How do I create an array of buttons instead of each individual button? Anything else you see that I could make more effiecent, please let me know
package really.trying;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Color;
public class swingStuff implements ActionListener{
JButton red1 = new JButton("Red");
JButton black1 = new JButton("Black");
JButton blue1 = new JButton("Blue");
JFrame frame = new JFrame("Tester");
Container content = frame.getContentPane();
Color color1, color2;
public swingStuff(){
content.add(red1);
content.add(blue1);
content.add(black1);
LayoutManager flow1 = new FlowLayout(FlowLayout.RIGHT);
content.setLayout(flow1);
frame.setSize(300,300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
red1.addActionListener(this);
blue1.addActionListener(this);
black1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae){
if(ae.getSource() == red1){
color1 = new Color(255, 0, 0);
color2 = content.getBackground();
}
else if(ae.getSource() == blue1) {
color1 = new Color(0, 0, 255);
color2 = content.getBackground();
}
else if(ae.getSource() == black1) {
color2 = content.getBackground();
color1 = new Color(0, 0, 0);
}
content.setBackground(color1);
red1.setBackground(color2);
blue1.setBackground(color2);
black1.setBackground(color2);
}
public static void main(
String args[]) {
swingStuff new1 = new swingStuff();
}
}