jradiobutton

What is the best way to determine what JRadioButton is selected?

依然范特西╮ 提交于 2019-12-24 02:35:31
问题 Currently I'm getting the selected button in this way, but I don't if this is the right/best method. MAybe there something more easy or object oriented than this. private int getFilterType(JRadioButton... buttons) { for (int i = 0, n = buttons.length; i < n; i++) { if (buttons[i].isSelected()) { return i + 1; } } return buttons.length + 1; } 回答1: I like using the ButtonGroup itself for this. i.e., import java.awt.GridLayout; import java.awt.event.ActionEvent; import javax.swing.*; public

Java - pass value of one radio button that selected to another frame

岁酱吖の 提交于 2019-12-23 05:37:11
问题 Is there any code that I can use to pass value of selected radio button to another frame? This is my code: import javax.swing.*; import java.awt.*; import java.awt.event.*; public class bookBatman extends JFrame implements ActionListener { private JLabel jlbName, jlbTime, jlbPic, jlbDate, jlbDescription, jlbAuthor, jlbDateProduce, jlbDirector, jlbActor, jlbRate, jlbNoOfTicket, jlbPrice, jlbTotal; private JTextField jtfNoOfTicket; private JRadioButton jr1, jr2, jr3, jr4, jr5, jr6, jr7, jr8,

If-else condition within a JButton ActionEvent

拜拜、爱过 提交于 2019-12-23 05:29:04
问题 I've just uploaded my progress into the program. Please have a look and see what is lacking in it. Also, please ignore the lame joke from the strings in it while you're at it. It can be downloaded from this link: http://www.mediafire.com/?n0sp8v22egfsx7t Note that I used NetBeans to easily make the program. Edited: How do I stop the ActionEvent method of a JButton from re-iterating the reading of the first layer of the nested if-else condition once the innermost line or last line of codes is

Action listener for multiple radio buttons

江枫思渺然 提交于 2019-12-23 04:37:27
问题 I intend to write a program where I will give the user a choice to choose from a 8*8 matrix. Because my reputation is below 10 I can not include an image but rest assured its just a normal 8*8 matrix. I plan to visualize it in my Java program with 8*8=64 radio buttons. the user can choose only one radio button at a time so it means all 64 buttons will be of the same button group. Now, how can I manage the action listeners? it is impossible (really tiresome and boring) to set up 64 individual

How to add JRadioButton to two columuns of a JTable and ButtonGroup them.

半城伤御伤魂 提交于 2019-12-20 05:31:13
问题 I want a JTable which consists of 2 columns(having RadioButton ) Active and Inactive such that if Active Column is Selected then Inactive RadioButton gets Unselected and Vice versa means that in a single row only 1 radiobutton can be selected out of 2 radiobuttons. the code for radiobutton is below . I am not able 2 add buttongroup for this 2 columns. public class NewJFrame extends javax.swing.JFrame { DefaultTableModel dt; public JRadioButton radioButton=new JRadioButton(); public class

setSelected a specific jradiobutton in a buttongroup based on action command

孤街浪徒 提交于 2019-12-20 01:42:02
问题 i want to setSelected a speicfic jradiobutton in a buttongroup based on the actionCommand(/name of the specific jradiobutton). it could be done usind .setSelected(true) for example, JRadioButton rabbitButton = new JRadioButton("rabbit"); rabbitButton .setActionCommand("rabbit"); JRadioButton pigButton = new JRadioButton("pig"); pigButton .setActionCommand("pig"); ButtonGroup group = new ButtonGroup(); group.add(rabbitButton); group.add(pigButton); now.. without , { rabbitButton.setSelected

JRadioButton: how to replace text by IconImage?

徘徊边缘 提交于 2019-12-19 08:07:32
问题 I want to replace the text in my radio button list by an icon. I've tried this: rotateButton = new JRadioButton(rotateIcon.getImage()); But this replaces the radio button and text by the icon. I would like to keep the radio button and display the image. What should I do? What I'm currently getting is: But I want it to end up with this: 回答1: public JRadioButton(String text, Icon icon) and simple example here 回答2: Create a JRadioButton with no text and put a JLabel with the image next to it.

JRadioButton: how to replace text by IconImage?

旧时模样 提交于 2019-12-19 08:07:18
问题 I want to replace the text in my radio button list by an icon. I've tried this: rotateButton = new JRadioButton(rotateIcon.getImage()); But this replaces the radio button and text by the icon. I would like to keep the radio button and display the image. What should I do? What I'm currently getting is: But I want it to end up with this: 回答1: public JRadioButton(String text, Icon icon) and simple example here 回答2: Create a JRadioButton with no text and put a JLabel with the image next to it.

JButton doesnt recognize does JRadioButton is select

我与影子孤独终老i 提交于 2019-12-13 05:25:09
问题 This JButton examines does is some of JRadioButtons is selected. So if JRadionButtons from list below is selected message dialog box will print message that's correct answer else it should print that isn't correct answer. I have 40 JRadioButtons, 10 Button Groups, 4 JRadioButtons is showing on screen at the time. I noted that this JButton (btn2) remember first examines so if I click on wrong JRadioButton and then I click on this btn2 it's will show me message dialog box with "this isn't

Java Button Handler

南楼画角 提交于 2019-12-13 04:29:01
问题 I am having an issue handling button events. I am creating a program that lets the user select the type of pizza they want and the program calculates the price of the pizza. I have my layout setup, however when a medium pizza is selected the button is not processing the proper response. Can anyone give me some advice? I have looked over my code for the past hour and I just can't seem to see the error I am making. Here is my code... public class Prog9Frame extends JFrame implements