小编Aka*_*asu的帖子

按钮运行一个全新的类

我希望我的按钮能够运行一个全新的类,它将在内部执行不同的操作.我不知道这是否可能因为我在java上真的很糟糕.我的代码目前看起来像这样:

public class MainMenu {
    private class GardenActivities {
        public GardenActivities() {
            JFrame GardenAct = new JFrame();
            GardenAct.setSize(400, 400);
            GardenAct.setVisible(true);
        }
    }

    public static void main(String[] args) {
        JFrame choice = new JFrame();
        choice.setSize(700, 500);
        choice.setLocationRelativeTo(null);
        choice.setTitle("Seeds");
        choice.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel panel = new JPanel();                                                        
        panel.setLayout(new GridLayout(0, 1));
        JButton Labora = new JButton();
        Labora.setText("Laboratory");
        Labora.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent ev) {
                      GardenActivities();
                }
        });

        JButton Garden = new JButton();
        Garden.setText("Garden");
        Garden.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ev) {
            } …
Run Code Online (Sandbox Code Playgroud)

java swing class jframe jbutton

2
推荐指数
1
解决办法
5272
查看次数

标签 统计

class ×1

java ×1

jbutton ×1

jframe ×1

swing ×1