Problem with JRadionButton are all selected if clicked one by one
-
Hello again I am creating again a new app in java which can animate images. I have problem with JRadionButton if I am going to select another one it marked with a dot and if I select another one it also marked with a dot without removing the pass which I had selected. Here's my code
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package star;/**
*
* @author flashery
*/
import java.awt.Color;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.*;public class StarAnimate extends JFrame implements ItemListener {
JPanel panel = new JPanel(); JRadioButton btnBoard1 = new JRadioButton("Board 1", true); JRadioButton btnBoard2 = new JRadioButton("Board 2"); JRadioButton btnBoard3 = new JRadioButton("Board 3"); Board board1 = new Board(); Board2 board2 = new Board2(); Board3 board3 = new Board3(); public StarAnimate() { init(); } private void init() { btnBoard1.setBounds(5, 10, 100, 30); btnBoard1.setBackground(Color.red); btnBoard1.addItemListener(this); btnBoard2.setBounds(5, 40, 100, 30); btnBoard2.setBackground(Color.red); btnBoard2.addItemListener(this); btnBoard3.setBounds(5, 70, 100, 30); btnBoard3.setBackground(Color.red); btnBoard3.addItemListener(this); panel.setLayout(null); panel.setBounds(0, 0, 160, 540); panel.setBackground(Color.red); panel.add(btnBoard1); panel.add(btnBoard2); panel.add(btnBoard3); this.add(panel); this.setDefaultCloseOperation(EXIT\_ON\_CLOSE); this.setSize(560, 540); this.setLayout(null); this.setLocationRelativeTo(null); this.setTitle("Star Animation"); this.setResizable(true); this.setVisible(true); } public static void main(String\[\] args) { StarAnimate star = new StarAnimate(); } @Override public void itemStateChanged(ItemEvent e) { if (e.getSource() == btnBoard1) { this.add(board1); this.remove(board2); this.remove(board3); } if (e.getSource() == btnBoard2) { this.add(board2); this.remove(board1); this.remove(board3); } if (e.getSource() == btnBoard3) { this.add(b
-
Hello again I am creating again a new app in java which can animate images. I have problem with JRadionButton if I am going to select another one it marked with a dot and if I select another one it also marked with a dot without removing the pass which I had selected. Here's my code
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package star;/**
*
* @author flashery
*/
import java.awt.Color;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.*;public class StarAnimate extends JFrame implements ItemListener {
JPanel panel = new JPanel(); JRadioButton btnBoard1 = new JRadioButton("Board 1", true); JRadioButton btnBoard2 = new JRadioButton("Board 2"); JRadioButton btnBoard3 = new JRadioButton("Board 3"); Board board1 = new Board(); Board2 board2 = new Board2(); Board3 board3 = new Board3(); public StarAnimate() { init(); } private void init() { btnBoard1.setBounds(5, 10, 100, 30); btnBoard1.setBackground(Color.red); btnBoard1.addItemListener(this); btnBoard2.setBounds(5, 40, 100, 30); btnBoard2.setBackground(Color.red); btnBoard2.addItemListener(this); btnBoard3.setBounds(5, 70, 100, 30); btnBoard3.setBackground(Color.red); btnBoard3.addItemListener(this); panel.setLayout(null); panel.setBounds(0, 0, 160, 540); panel.setBackground(Color.red); panel.add(btnBoard1); panel.add(btnBoard2); panel.add(btnBoard3); this.add(panel); this.setDefaultCloseOperation(EXIT\_ON\_CLOSE); this.setSize(560, 540); this.setLayout(null); this.setLocationRelativeTo(null); this.setTitle("Star Animation"); this.setResizable(true); this.setVisible(true); } public static void main(String\[\] args) { StarAnimate star = new StarAnimate(); } @Override public void itemStateChanged(ItemEvent e) { if (e.getSource() == btnBoard1) { this.add(board1); this.remove(board2); this.remove(board3); } if (e.getSource() == btnBoard2) { this.add(board2); this.remove(board1); this.remove(board3); } if (e.getSource() == btnBoard3) { this.add(b
Add your
JRadioButton
into aJRadioButtonGroup
Excuse me for my improper grammar and typos. It's because English is my primary language, not my first language. My first languages are C# and Java. VB, ASP, JS, PHP and SQL are my second language. Indonesian came as my third language. My fourth language? I'm still creating it, I'll let you know when it's done! :-D
-
Add your
JRadioButton
into aJRadioButtonGroup
Excuse me for my improper grammar and typos. It's because English is my primary language, not my first language. My first languages are C# and Java. VB, ASP, JS, PHP and SQL are my second language. Indonesian came as my third language. My fourth language? I'm still creating it, I'll let you know when it's done! :-D
-
flashery wrote:
Anyway its just ButtonGroup not JRadioButtonGroup.
Sorry about that, my brain's currently running in safe-mode (ie. debugging some VB apps)
Excuse me for my improper grammar and typos. It's because English is my primary language, not my first language. My first languages are C# and Java. VB, ASP, JS, PHP and SQL are my second language. Indonesian came as my third language. My fourth language? I'm still creating it, I'll let you know when it's done! :-D