Помогите пожалйста найти ошибки: Почему функция которая создает окно управления инвентарем не работает? Она как будто два раза вызывает конструктор. И кнопки тоже почему то не работают :( Подскажите пожалуйста что я делаю не так, может быть я что то забыла добавить, просто это моя первая программка с графическим интерфейсом
| Код | public class GestionInventaire extends JFrame { private static final int FRAME_WIDTH = 600; private static final int FRAME_HEIGTH = 300; private static JFrame menuprinc = new JFrame("Gestion inventaire"); private static JPanel panelcombox; private static JPanel panelprincipal; private static JPanel panelSecond; private static JPanel panelAjout; private static JPanel panelSupp; private static JPanel panelMod;
private static JRadioButton buttonAjout; private static JRadioButton buttonSupp; private static JRadioButton buttonMod; private static JButton buttonReturnMenu; private static ActionListener listener; //Создаем окно управления инвентарем public GestionInventaire(){ createMenuBox(); createPanelPrincipal(); createPanelSecondaire(); System.out.println("pipi caca"); menuprinc.getContentPane().add(panelprincipal, BorderLayout.CENTER); panelprincipal.setLayout(new GridLayout(2, 0)); setSize(FRAME_WIDTH, FRAME_HEIGTH); } /** * Создаем меню */ public void createMenuBox(){ buttonAjout = new JRadioButton(); buttonSupp = new JRadioButton(); buttonMod = new JRadioButton(); buttonReturnMenu = new JButton(); class ChoiceListener implements ActionListener{ public void actionPerformed (ActionEvent e) { setChoice(); } } listener = new ChoiceListener(); buttonAjout = new JRadioButton("1- Ajouter un article"); buttonAjout.addActionListener(listener); buttonSupp = new JRadioButton("2- Supprimer un article"); buttonSupp.addActionListener(listener); buttonMod = new JRadioButton("3 - Modifier un article"); buttonMod.addActionListener(listener); buttonReturnMenu = new JButton("Retour menu principal"); buttonReturnMenu.addActionListener(listener); ButtonGroup group = new ButtonGroup(); group.add(buttonAjout); group.add(buttonSupp); group.add(buttonMod); group.add(buttonReturnMenu); } /** *Создаем главное меню
*/ public JPanel createPanelPrincipal() { panelprincipal = new JPanel(new GridLayout(2,1)); panelcombox = new JPanel(new GridLayout(4,1)); panelcombox.add(buttonAjout); panelcombox.add(buttonSupp); panelcombox.add(buttonMod); panelcombox.add(buttonReturnMenu); panelcombox.setBorder(new TitledBorder(new EtchedBorder(), "Options")); panelprincipal.add(panelcombox); return panelcombox; } /** * Создаем дополнительную панель в зависимости от выбора пользователя */ public void createPanelSecondaire(){ panelSecond = new JPanel(); panelAjout = createPanelAjout(); panelSupp = createPanelSupp(); panelMod = createPanelMod(); panelSecond.setBorder(new TitledBorder(new EtchedBorder(), "Titre")); panelSecond.setLayout(new BorderLayout()); panelprincipal.add(panelSecond); //return panelSecond;
} //Создаем панель добавления предметов public JPanel createPanelAjout(){ JPanel panel = new JPanel(); return panel; } //Создаем панель удаления предметов public JPanel createPanelSupp(){ JPanel panel = new JPanel(); return panel; } //Создаем панель изменения предметов public JPanel createPanelMod(){ JPanel panel = new JPanel(); return panel; } /** * Метод который позволяет открыть выбранное окно. */ public void setChoice(){
String titre = ""; if(buttonAjout.isSelected()){ titre = "Ajouter un article"; panelSecond.add(panelAjout, BorderLayout.CENTER); panelSecond.setBorder(new TitledBorder(new EtchedBorder(), titre)); } } public static Window getInventaireFrame(){ System.out.println("...."); menuprinc.setBounds(325, 250, FRAME_WIDTH, FRAME_HEIGTH); menuprinc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); menuprinc.setVisible(true); return menuprinc; }
} |
|