0

I created a JDialog box where it has 2 radio button which will change the JLabel whenever I clicked the other button(for example: Monthly salary when I click the full time button and hourly pay when i click the part time button)

So my questions is how do i do that? Do I create ActionListener for the radioButton and create the those JPanel inside the the actionPerformed class?

example

Noah Skull Weijian
  • 129
  • 1
  • 2
  • 8

3 Answers3

1

I think the best way to go about this is create an action listener for the button. When one is selected change the text with monthLabel.setText("Monthly Salary");

Kevin Mee
  • 539
  • 3
  • 14
1

Yes, you will need listener, I recommend ItemListener over ActionListener but there is no need to create Panel in listener. Instead change the label text itself.

0

Here's how you can do it:

radio1.addActionListener(new ActionListener(){
   label.setText("Clicked from radio 1");
});

radio2.addActionListener(new ActionListener(){
   label.setText("Clicked from radio 2");
});
CMPS
  • 7,733
  • 4
  • 28
  • 53