public class PanelMatrice extends JPanel { //Ta matrice de 0 et de 1 private Matrice matrice; public PanelMatrice (Matrice matrice){ this.matrice=matrice; } @Override public void paintComponent(Graphics g){ int largeur=getWidth()/matrice.getNombreCarreauxLargeur(); int hauteur=getHeight()/matrice.getNombreCarreauxHauteur(); for(int i=0; i<matrice.getTailleLargeur(); i++){ for(int j=0; j<matrice.getTailleHauteur; j++){ if(matrice.get(i, j)==0){ g.setColor(Color.WHITE); } else{ g.setColor(Color.BLACK); } g.fillRect(i*largeur, j*hauteur, largeur, hauteur); } } } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionpackage aiproject; import java.awt.Color; import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; import java.awt.Graphics; import java.util.Random; public class DrawWelcomeWindow extends JLabel{ protected JFrame frame; protected DrawLabyrinthFromMatrix DessinLab; protected JMenuBar jmBar; protected JMenu jmHelp; protected JMenuItem jmiAbout; protected JMenu jmFile; protected JMenuItem jmiExit; protected JPanel jpanel; StoreFileDataIntoIntegerMatrix sfm= new StoreFileDataIntoIntegerMatrix(); protected int lescolonnes; protected int leslignes; protected int[][] lamatrice; protected int[][] thematrix; protected int hauteur=20; protected int largeur=20; protected int x; protected int y; protected int[] moncul; //private static final Random random = new Random(); int[][]matricedetravail; public DrawWelcomeWindow(int[][] givenmatrix){ this.matricedetravail=givenmatrix; } /* *draw my user interface * */ @Override public void paintComponent(Graphics g){ frame=new JFrame("Projet IA"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //frame.setLayout(new GridLayout(leslignes, lescolonnes)); sfm.storeIntoArray(); sfm.storeAsIntegersIntoMatrix(); lescolonnes=sfm.getColumnsNb(); leslignes=sfm.getRowsNb(); lamatrice=sfm.getLabyrinthMatrix(); int a=20; int b=20; for(int i=0;i<a;i++){ for(int j=0;j<b;j++){ if(lamatrice[i][j]==1){ g.setColor(Color.BLUE); }else{ g.setColor(Color.DARK_GRAY); } g.fillRect(i*largeur, j*hauteur, largeur, hauteur); } } //DrawLabyrinthe label=new DrawLabyrinthe(lamatrice); DrawWelcomeWindow label=new DrawWelcomeWindow(lamatrice); frame.add(label); jmBar=new JMenuBar(); ImageIcon iconExit=new ImageIcon(getClass().getResource("exit.jpeg")); ImageIcon iconAbout=new ImageIcon(getClass().getResource("help.png")); jmFile=new JMenu("File"); jmFile.setMnemonic('F'); jmHelp=new JMenu("Help"); jmHelp.setMnemonic('H'); jmiExit=new JMenuItem("Exit",iconExit); jmiExit.setMnemonic('E'); jmiAbout=new JMenuItem("About",iconAbout); jmiAbout.setMnemonic('A'); jmFile.add(jmiExit); jmHelp.add(jmiAbout); jmBar.add(jmFile); jmBar.add(jmHelp); frame.setJMenuBar(jmBar); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); jmiExit.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.exit(0); } }); jmiAbout.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ JOptionPane.showMessageDialog(null,"Billal BEGUERADJ & Mohammed EL BARBORI Master CRYPTIS 1ère Année"," Projet IA 2011/2012",JOptionPane.PLAIN_MESSAGE); } }); }/*END OF initUI() */ }//END OF my class
package aiproject; import java.io.FileNotFoundException; public class Labyrinthe{ public static void main(String[]args) throws FileNotFoundException{ //ReadMyFile rmf=new ReadMyFile(); StoreFileDataIntoIntegerMatrix storeit=new StoreFileDataIntoIntegerMatrix(); storeit.storeIntoArray(); storeit.storeAsIntegersIntoMatrix(); int[][]exercice=storeit.getLabyrinthMatrix(); DrawWelcomeWindow dww=new DrawWelcomeWindow(exercice); //storeit.afficherMatrice(); } }
package aiproject; import java.awt.Color; import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; import java.awt.Graphics; import java.util.Random; public class DrawWelcomeWindow extends JPanel{ protected JFrame frame; protected DrawLabyrinthFromMatrix DessinLab; protected JMenuBar jmBar; protected JMenu jmHelp; protected JMenuItem jmiAbout; protected JMenu jmFile; protected JMenuItem jmiExit; protected JPanel jpanel; StoreFileDataIntoIntegerMatrix sfm= new StoreFileDataIntoIntegerMatrix(); protected int lescolonnes; protected int leslignes; protected int[][] lamatrice; protected int[][] thematrix; protected int hauteur=20; protected int largeur=20; protected int x; protected int y; protected int[] moncul; //private static final Random random = new Random(); int[][]matricedetravail; int a=20; int b=20; public DrawWelcomeWindow(int[][] givenmatrix){ //frame.setLayout(new GridLayout(leslignes, lescolonnes)); sfm.storeIntoArray(); sfm.storeAsIntegersIntoMatrix(); lescolonnes=sfm.getColumnsNb(); leslignes=sfm.getRowsNb(); lamatrice=sfm.getLabyrinthMatrix(); this.matricedetravail=givenmatrix; } /* *draw my user interface * */ @Override public void paintComponent(Graphics g){ for(int i=0;i<lescolonnes;i++){ for(int j=0;j<leslignes;j++){ if(lamatrice[i][j]==1){ g.setColor(Color.BLUE); }else{ g.setColor(Color.DARK_GRAY); } g.fillRect(i*largeur, j*hauteur, largeur, hauteur); } } }/*END OF paintComponent */ public void initUI(){ frame=new JFrame("Projet IA"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //DrawLabyrinthe label=new DrawLabyrinthe(lamatrice); DrawWelcomeWindow label=new DrawWelcomeWindow(lamatrice); frame.add(label); jmBar=new JMenuBar(); ImageIcon iconExit=new ImageIcon(getClass().getResource("exit.jpeg")); ImageIcon iconAbout=new ImageIcon(getClass().getResource("help.png")); jmFile=new JMenu("File"); jmFile.setMnemonic('F'); jmHelp=new JMenu("Help"); jmHelp.setMnemonic('H'); jmiExit=new JMenuItem("Exit",iconExit); jmiExit.setMnemonic('E'); jmiAbout=new JMenuItem("About",iconAbout); jmiAbout.setMnemonic('A'); jmFile.add(jmiExit); jmHelp.add(jmiAbout); jmBar.add(jmFile); jmBar.add(jmHelp); frame.setJMenuBar(jmBar); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); jmiExit.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.exit(0); } }); jmiAbout.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ JOptionPane.showMessageDialog(null,"Billal BEGUERADJ & Mohammed EL BARBORI Master CRYPTIS 1ère Année"," Projet IA 2011/2012",JOptionPane.PLAIN_MESSAGE); } }); } }//END OF my class
package aiproject; import java.io.FileNotFoundException; public class Labyrinthe{ public static void main(String[]args) throws FileNotFoundException{ //ReadMyFile rmf=new ReadMyFile(); StoreFileDataIntoIntegerMatrix storeit=new StoreFileDataIntoIntegerMatrix(); storeit.storeIntoArray(); storeit.storeAsIntegersIntoMatrix(); int[][]exercice=storeit.getLabyrinthMatrix(); DrawWelcomeWindow dww=new DrawWelcomeWindow(exercice); dww.initUI(); //storeit.afficherMatrice(); } }
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 8 at aiproject.DrawWelcomeWindow.paintComponent(DrawWelcomeWindow.java:69) at javax.swing.JComponent.paint(JComponent.java:1029) at javax.swing.JComponent.paintChildren(JComponent.java:866) at javax.swing.JComponent.paint(JComponent.java:1038) at javax.swing.JComponent.paintChildren(JComponent.java:866) at javax.swing.JComponent.paint(JComponent.java:1038) at javax.swing.JLayeredPane.paint(JLayeredPane.java:581) at javax.swing.JComponent.paintChildren(JComponent.java:866) at javax.swing.JComponent.paintToOffscreen(JComponent.java:5145) at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:302) at javax.swing.RepaintManager.paint(RepaintManager.java:1145) at javax.swing.JComponent.paint(JComponent.java:1015) at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:39) at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:78) at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:115) at java.awt.Container.paint(Container.java:1844) at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:751) at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:696) at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:676) at javax.swing.RepaintManager.access$700(RepaintManager.java:57) at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1550) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:226) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:647) at java.awt.EventQueue.access$000(EventQueue.java:96) at java.awt.EventQueue$1.run(EventQueue.java:608) at java.awt.EventQueue$1.run(EventQueue.java:606) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105) at java.awt.EventQueue.dispatchEvent(EventQueue.java:617) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177) at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)
public void paintComponent(Graphics g){ System.out.println(lescolonnes); System.out.println(leslignes); for(int i=0;i<leslignes;i++){ x1=x1+largeur; for(int j=0;j<lescolonnes;j++){ if(lamatrice[i][j]==1){ g.setColor(Color.BLUE); }else if(lamatrice[i][j]==0){ g.setColor(Color.DARK_GRAY); }else{ g.setColor(Color.RED); } g.fillRect(j*largeur, i*hauteur, largeur, hauteur); } } }/*END OF paintComponent */