如何从Main via按钮的动作监听器调用我的类gui_Game?

时间:2016-11-13 02:05:54

标签: java swing

当我点击名为“start”的按钮时,我想在gui_Game中启动一个班级。在gui_Game设置标题中,有三个按钮。

此代码位于Main类:

private class Start implements ActionListener{
        public void actionPerformed(ActionEvent e) {
            JButton b = (JButton) e.getSource();
            if (b.getText().equals("start"))
                // I want to add here
        }
    }

这是gui_Game来源:

    public class gui_Game extends JFrame{

       private JButton button;
       private JButton button1;
       private JButton button2;
       private JButton button3;
       private JButton button4;
       private JButton button5;
       private JButton button6;
       private JButton button7;
       private JButton button8;
       private JLabel Stage;

       public gui_Game() throws IOException 
       {
          // .. code ..
       }

       public static void main(String[] args) throws IOException
       {
          gui_Game main = new gui_Game();
          main.setVisible(true);
       }
    }

gui_Game中,它会创建一个新窗口和三个按钮。

0 个答案:

没有答案