我正在使用Eclipse Neon中的第一个Java库GUI。我创建了一个内容窗格,并为其提供了一些代码,可以在按下按钮时打印出来。问题是我无法运行该程序。 Eclipse不会显示运行按钮。显示的唯一按钮是“外部工具”按钮。代码中是否存在我缺少的问题,还是其他问题?
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JList;
import javax.swing.JTextField;
import javax.swing.JScrollBar;
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.border.MatteBorder;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
@SuppressWarnings("serial")
public class Test extends JFrame {
private JPanel contentPane;
private JLabel label;
private JTextField textField;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Test frame = new Test();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Test() {
super("Test GUI");
setBackground(Color.GREEN);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 593, 458);
contentPane = new JPanel();
contentPane.setBackground(new Color(240, 248, 255));
contentPane.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0)));
setContentPane(contentPane);
contentPane.setLayout(null);
JTextArea textArea = new JTextArea();
textArea.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0)));
textArea.setBounds(10, 11, 355, 366);
contentPane.add(textArea);
JScrollBar scrollBar = new JScrollBar();
scrollBar.setBounds(371, 11, 17, 366);
contentPane.add(scrollBar);
@SuppressWarnings("rawtypes")
JList list = new JList();
list.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0)));
list.setBounds(398, 44, 139, 333);
contentPane.add(list);
JScrollBar scrollBar_1 = new JScrollBar();
scrollBar_1.setBounds(543, 48, 17, 329);
contentPane.add(scrollBar_1);
JButton button = new JButton("Log Out");
button.setBounds(438, 11, 71, 23);
contentPane.add(button);
textField = new JTextField();
textField.setColumns(10);
textField.setBounds(10, 384, 460, 20);
contentPane.add(textField);
JButton button_1 = new JButton("Send");
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
label.setText("Yeah, It Works!!!");
textArea.add(label);
}
});
button_1.setBounds(488, 383, 57, 23);
contentPane.add(button_1);
}
}
这是eclipse截图的链接。请注意,菜单选项中没有运行按钮: Screenshot of Eclipse Neon
提前致谢