public class TestIHM extends JFrame implements ActionListener { private PanelImage panelFond = new PanelImage(); private PanelImage panelPrincipal = new PanelImage(); private PanelImage panelLateral = new PanelImage(); private PanelImage panelSup = new PanelImage(); private JCoolButton boutonMenuPrincipal = new JCoolButton("Menu principal"); private JCoolButton boutonMenuSecondaire = new JCoolButton("Menu Secondaire"); private JCoolButton boutonParametres = new JCoolButton("Paramètres"); private JCoolButton boutonAnalyse = new JCoolButton("Statistiques"); private JCoolButton boutonQuitter = new JCoolButton("Quitter"); private GridBagConstraints constraintsSup = new GridBagConstraints(); private GridBagConstraints constraintsLateral = new GridBagConstraints(); public testIHM() { this.setTitle(ParametresFenetre.version); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(ParametresFenetre.largeurFenetre, ParametresFenetre.hauteurFenetre); if(ParametresFenetre.ouverture == true) this.setLocationRelativeTo(null); else this.setLocation(ParametresFenetre.emplacementLargeurFenetre, ParametresFenetre.emplacementHauteurFenetre); try { panelFond.setImage("Ressources/Images/agriculture01.jpg"); } catch (IOException e) { e.printStackTrace(); } panelFond.setLayout(new BorderLayout()); JScrollPane scrollPaneGeneral = new JScrollPane(panelFond); this.getContentPane().add(scrollPaneGeneral); panelPrincipal.setBorder(BorderFactory.createTitledBorder("Menu principal")); Dimension SizePanelLateral = new Dimension(150, 500); panelLateral.setPreferredSize(SizePanelLateral); Dimension SizePanelSup = new Dimension(900, 50); panelSup.setPreferredSize(SizePanelSup); panelFond.add(panelSup, BorderLayout.NORTH); panelFond.add(panelLateral, BorderLayout.WEST); panelFond.add(panelPrincipal, BorderLayout.CENTER); //////////////////////////////////////////////////////////////////////////////////// panelSup.setLayout(new GridBagLayout()); constraintsSup.gridx = 0; constraintsSup.gridy = 0; constraintsSup.gridwidth = 1; constraintsSup.gridheight = 1; constraintsSup.ipadx = 300; constraintsSup.ipady = 25; constraintsSup.anchor = GridBagConstraints.LINE_END; panelSup.add(boutonMenuPrincipal,constraintsSup); constraintsSup.gridx = 1; constraintsSup.gridy = 0; constraintsSup.gridwidth = 1; constraintsSup.gridheight = 1; constraintsSup.anchor = GridBagConstraints.LINE_START; panelSup.add(boutonMenuSecondaire,constraintsSup); //////////////////////////////////////////////////////////////////////////////////// panelLateral.setLayout(new GridBagLayout()); Dimension SizeBoutonLateral = new Dimension(135, 60); constraintsLateral.gridx = 0; constraintsLateral.gridy = 1; constraintsLateral.gridwidth = 1; constraintsLateral.gridheight = 1; constraintsLateral.insets = new Insets(0,0,5,0); boutonParametres.setPreferredSize(SizeBoutonLateral); panelLateral.add(boutonParametres,constraintsLateral); constraintsLateral.gridx = 0; constraintsLateral.gridy = 5; constraintsLateral.gridwidth = 1; constraintsLateral.gridheight = 1; constraintsLateral.insets = new Insets(0,0,40,0); boutonAnalyse.setPreferredSize(SizeBoutonLateral); panelLateral.add(boutonAnalyse,constraintsLateral); constraintsLateral.gridx = 0; constraintsLateral.gridy = 7; constraintsLateral.gridwidth = 1; constraintsLateral.gridheight = 1; constraintsLateral.weighty = 1; constraintsLateral.insets = new Insets(0,0,20,0); constraintsLateral.anchor = GridBagConstraints.PAGE_END; boutonQuitter.setPreferredSize(SizeBoutonLateral); panelLateral.add(boutonQuitter,constraintsLateral); //////////////////////////////////////////////////////////////////////////////////// boutonMenuPrincipal.addActionListener(this); boutonMenuSecondaire.addActionListener(this); boutonParametres.addActionListener(this); boutonAnalyse.addActionListener(this); boutonQuitter.addActionListener(this); } public void actionPerformed(ActionEvent arg0) { if(arg0.getSource() == boutonMenuPrincipal) { this.dispose(); new MenuPrincipal().setVisible(true); } if(arg0.getSource() == boutonMenuSecondaire) { new MenuSecondaire().setVisible(true); this.dispose(); } /////////////////////////////////////////////////////////////////////////// if(arg0.getSource() == boutonParametres) { new Parametres().setVisible(true); this.dispose(); } if(arg0.getSource() == boutonAnalyse) { new Statistiques().setVisible(true); this.dispose(); } if(arg0.getSource() == boutonQuitter) { System.exit(0); } } }
public class TestIHMDeux extends TestIHM implements ActionListener { private JPanel panelTest = new JPanel(); private GridBagConstraints constraintsPrincipal = new GridBagConstraints(); private GridBagConstraints constraintsTest = new GridBagConstraints(); private JCoolButton boutonTest = new JCoolButton("Test"); public TestIHMDeux() { TestIHM.panelPrincipal.setLayout(new GridBagLayout()); // Color couleurTitres = new Color(70,130,180,255); constraintsPrincipal.gridx = 0; constraintsPrincipal.gridy = 0; constraintsPrincipal.gridwidth = 3; constraintsPrincipal.gridheight = 1; constraintsPrincipal.weighty = 1; constraintsPrincipal.insets = new Insets(10,10,0,10); constraintsPrincipal.ipadx = 300; constraintsPrincipal.ipady = 10; constraintsPrincipal.fill = GridBagConstraints.HORIZONTAL; panelTest.setBorder(BorderFactory.createTitledBorder("Exploitations")); panelTest.setOpaque(false); panelPrincipal.add(panelTest,constraintsPrincipal); panelTest.setLayout(new GridBagLayout()); Dimension SizeBoutonPanel1 = new Dimension(100, 40); boutonTest.setPreferredSize(SizeBoutonPanel1); constraintsTest.gridx = 0; constraintsTest.gridy = 0; constraintsTest.gridwidth = 1; constraintsTest.gridheight = 1; constraintsTest.weightx = 1; panelTest.add(boutonTest,constraintsTest); boutonTest.addActionListener(this); } public void actionPerformed(ActionEvent arg0) { if(arg0.getSource() == boutonTest) { System.out.println("Appui sur test !"); } } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionboutonQuitter.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.exit(0); } }); boutonAnalyse.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ new Statistiques().setVisible(true); this.dispose(); } });
The method dispose() is undefined for the type new ActionListener(){}