Need help with JFrame and JPanel
alright so I'm trying to write a simple program. the program contains a window and it two buttons . if you click on the green button the background for the whole window changes to green and the same for the other button but it changes to orange. how do I move the two buttons from the top to the bottom of the window? and what do we use to change the background of the window?
heres my code
Code:
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class LabAssign9 extends JFrame{
private JButton green;
private JButton orange;
public LabAssign9()
{
super("Colored Buttons");
setLayout(new FlowLayout());
green = new JButton("Green");
add(green);
green.setBackground(Color.green);
setLayout(new FlowLayout());
orange = new JButton("orange");
add(orange);
orange.setBackground(Color.orange);
HandlerClass handler = new HandlerClass();
green.addActionListener(handler);
orange.addActionListener(handler);
}
private class HandlerClass implements ActionListener{
public void actionPerformed(ActionEvent event){
}
}
public static void main(String[] args) {
LabAssign9 go = new LabAssign9();
go.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
go.setSize(425,375);
go.setVisible(true);
}
}