So I'm trying to learn java and I'm trying to condense code down to be more simple by attempting to manipulate a group of JButtons together, is there any way to do this?
I've tried putting them all under a ButtonGroup group = new ButtonGroup();
but I can't do things like group.setFont(new Font("Times New Roman", Font.PLAIN, 50);
or group.addActionListener(new Response());
or panel.add(group);
.
Does Java allow this or am I just woefully ignorant?
By the way I'm only including 3 buttons as an example but I'm actually working with 20 so please don't say "since you only have 3 buttons it doesn't really matter".
Currently:
button1.setFont(new Font("Times New Roman", Font.PLAIN, 50));
button2.setFont(new Font("Times New Roman", Font.PLAIN, 50));
button3.setFont(new Font("Times New Roman", Font.PLAIN, 50));
button1.addActionListener(new Response());
button2.addActionListener(new Response());
button3.addActionListener(new Response());
panel.add(button1);
panel.add(button2);
panel.add(button3);
What I would like to happen:
ButtonGroup group = new ButtonGroup();
group.add(Button1);
group.add(Button2);
group.add(Button3);
group.setFont(new Font("Times New Roman", Font.PLAIN, 50));
group.addActionListener(new Response());
panel.add(group);