So, I am trying to create buttons 8 on left and right side each. And I am really new to GUI. So, I am not sure how to change the colour and shape, to make those buttons a circle and color them in red and blue...This what I have so far...
import javax.swing.*;
import java.awt.*;
public class Arrangement {
// main must be static
public static void main(String[] args) {
Arrangement arrangement = new Arrangement();
arrangement.handle();
}
public void handle() {
JFrame f= new JFrame();
f.setVisible(true);
f.setSize(600,400);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel p = new JPanel (new GridBagLayout());//in the constructor u specify the layout :)
JPanel a = new JPanel (new GridBagLayout());
JButton b1 = new JButton("Button 1");
JButton b2 = new JButton("Button 2");
JButton b3= new JButton ("Button 3");
JButton b4= new JButton ("Button 4");
JButton b5= new JButton ("Button 5");
JButton b6= new JButton ("Button 6");
JButton b7 = new JButton("Button 7");
JButton b8 = new JButton("Button 8");
JButton b9 = new JButton ("Button 9");
JButton b10 = new JButton ("Button 10");
JButton b11 = new JButton ("Button 11");
JButton b12 =new JButton ("Button 12");
JButton b13 = new JButton("Button 13");
JButton b14= new JButton("Button 14");
JButton b15= new JButton ("Button 15");
JButton b16 = new JButton ("Button 16");
GridBagConstraints c= new GridBagConstraints();
GridBagConstraints d= new GridBagConstraints();
c.insets = new Insets(5,5,5,5);//spacing
c.gridx=0;
c.gridy=1;
p.add(b1,c);
c.gridx=0;
c.gridy=2;
p.add(b2,c);
c.gridx=0;
c.gridy=4;
p.add(b3,c);
c.gridx=0;
c.gridy=6;
p.add(b4,c);
c.gridx=0;
c.gridy=8;
p.add(b5,c);
c.gridx=0;
c.gridy=10;
p.add(b6,c);
c.gridx=0;
c.gridy=11;
p.add(b7,c);
c.gridx=0;
c.gridy=12;
p.add(b8,c);
d.insets = new Insets(5,5,5,5);
d.gridx=0;
d.gridy=1;
a.add(b9,d);
d.gridx=0;
d.gridy=2;
a.add(b10,d);
d.gridx=0;
d.gridy=3;
a.add(b11,d);
d.gridx=0;
d.gridy=4;
a.add(b12,d);
d.gridx=0;
d.gridy=6;
a.add(b13,d);
d.gridx=0;
d.gridy=8;
a.add(b14,d);
d.gridx=0;
d.gridy=10;
a.add(b15,d);
d.gridx=0;
d.gridy=12;
a.add(b16,d);
f.add(p, BorderLayout.WEST);
f.add(a, BorderLayout.EAST);
}
} Now the problem here is I cant use "this. ", with static and if I remove static I get an error saying I need to include static for my code to work... Can someone help me debug this :'( and direct me as to how can I get my buttons to be desired shape and colour...! Any help would be greatly appreciated <3