You can put an action Listener on the Radio Buttons and set your type = "#" to whichever one is selected.JRadioButton b = new JRadioButton("1"); b.addActionListener() { public void actionPerformed(ActionEvent e) { type = "1"; }}); Something like that anyway.