I am wondering if there is any easier and more efficient way of making JButtons. My design looks like this and it's not practical at all doing it like this. And before anyone suggests using something else than JButtons, I am not allowed to. Thanks
Since only a couple of the attributes are different (mainly the location and the size), you could create a factory method and pass in the different attributes.
private JButton createJButton(String label, int xcoordinate, int ycoordinate, int width, int height, ActionListener actionListener) {
JButton button = new JButton(label);
button.setBounds(xcoordinate, ycoordinate, width, height);
button..setBackground(new Color(0x32BD12));
button.setForeground(Color.BLACK);
button.setFont(new Font("arial", Font.BOLD, 40))
button.addActionListener(actionListener);
button.setBorder(new EmptyBorder(1, 1,1,1));
return button;
}
That would help get rid of some of the boiler plate code.