public class StatsGUI extends JFrame implements ActionListener {
JLabel label;
JLabel label2;
JTextField input;
JTextField output;
JButton getButton;
JButton exitButton;
public StatsGUI()
{
JPanel panel = new JPanel();
label = new JLabel("Enter number");
panel.add(label);
input = new JTextField(10);
input.addActionListener(this);
panel.add(input);
label2 = new JLabel("Statistics");
output = new JTextField(10);
output.setEditable(false);
panel.add(output);
getButton = new JButton("Go");
getButton.addActionListener(this);
panel.add(getButton);
exitButton = new JButton("Exit");
exitButton.addActionListener(this);
panel.add(exitButton);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == exitButton)
{
System.exit(0);
}
else
{
String text = input.getText();
output.setText(text + "COUNTER");
}
}
public static void main(String[] args)
{
}
这是我简单的GUI程序。我已将所有按钮和其他小工具放在构造函数中。但是,我不确定我应该把我的主要内容放到我的主内容中,以便让我的GUI实际显示出来。我相信我错过了一些令人难以置信的简单但我不确定的事情。帮助将不胜感激。我如何运行我的GUI?或者更准确地说,我的主要内容是什么?
阅读[Swing教程](http://docs.oracle.com/javase/tutorial/uiswing/TOC.html)。本教程中的每个示例都将向您展示一种创建程序的简单方法,以便您正确启动GUI。不仅如此,本教程还将向您展示Swing基础知识。 – camickr