I'm working on a java program in netbeans and I have it working except to run it I have to right click the main file and tell it to run instead of just clicking the run button.
Any help would be appreciated.
Sincerely yours;
jdm
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package FirstGUI;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
class FirstGui extends JPanel implements ActionListener {
private JButton yellowButton = new JButton("Yellow");
private JButton blueButton = new JButton("Blue");
private JButton redButton = new JButton("Red");
private JButton greenButton = new JButton("Green");
public FirstGui() {
add(redButton);
add(greenButton);
add(blueButton);
add(yellowButton);
yellowButton.addActionListener(this);
blueButton.addActionListener(this);
redButton.addActionListener(this);
greenButton.addActionListener(this);
}
public void actionPerformed(ActionEvent evt) {
Object source = evt.getSource();
Color color = getBackground();
if (source == yellowButton)
color = Color.yellow;
else if (source == blueButton)
color = Color.blue;
else if (source == redButton)
color = Color.red;
else if (source == greenButton)
color = Color.green;
setBackground(color);
repaint();
}
public static void main(String[] args) {
JFrame frame = new JFrame("Color Changing Demo");
frame.setSize(500, 200);
frame.setLocation(100,300);
frame.setResizable(false);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
);
Container contentPane = frame.getContentPane();
contentPane.setBackground(Color.white);
contentPane.add(new FirstGui());
frame.show();
}
}