I'm working on my first GUI in Java in Eclipse Neon. I created a content pane and gave it some code to print something out when a button is pressed. The problem is that I can't run the program. Eclipse won't display the run button. The only button that shows is the "External Tools" button. Is there something I'm missing in the code that's the problem or is it something else?
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);
}
}
Here is a link to the screenshot of eclipse. Notice there is no run button in the menu options: Screenshot of Eclipse Neon
Thanks in advance