【发布时间】:2020-10-26 02:12:21
【问题描述】:
我已经组装了一个基本的 GUI,但调试器说没有 main 方法,即使有一个 static void main(String[] args) 这是我的代码
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class GUI implements ActionListener {
static void main(String[] args) {
new GUI();
}
public GUI() {
JFrame frame = new JFrame();
JPanel panel = new JPanel();
JButton button = new JButton(String.valueOf(Game.Compounds));
button.addActionListener(this);
panel.setBorder(BorderFactory.createEmptyBorder(30, 30, 10, 30));
panel.setLayout(new GridLayout(0, 1));
panel.add(button);
frame.add(panel, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("GUI");
frame.pack();
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
Game.Compounds = Game.Compounds + Game.CPC;
}
}
有什么问题
【问题讨论】:
-
main()必须是公开的。
标签: java user-interface main-method