Reputation: 129
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?
Upvotes: 0
Views: 69
Reputation:
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.
Upvotes: 1
Reputation: 549
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");
Upvotes: 1
Reputation: 7769
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");
});
Upvotes: 0