JRadioButton and JButton filter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GuruCool12221
    New Member
    • Jun 2017
    • 15

    JRadioButton and JButton filter

    so I've this welcome frame where I've the following things:
    i) Two radio buttons- single, multi
    ii) Two labels- Player1 Name, Player2 Name
    iii) Two text boxes receiving the names
    iv) Button 'Start !'

    what I want the program to do is when the user clicks the radio label 'single', the field for player2 disappears and user will enter Player1 name only and when the user clicks the 'multi' radio label, the fields for player2 and player1 reappear and has to input both the names. I have been able to program till here.

    Now, what I want it to do is, if 'single' is selected and the field is filled when I press the 'Start !' button, I want it to call the class 'Yahtzee' and it 'multi' is selected, I want it to call the class 'DoubleYahtzee' when the 'Start !' button is clicked.
    Thanks in advance!
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    Can you please show us what you have programmed so far?

    Comment

    • GuruCool12221
      New Member
      • Jun 2017
      • 15

      #3
      thank you for showing concern. I figured it out myself.
      Code:
      @Override
      public void actionPerformed(ActionEvent e) {
      	if(e.getSource()==log)
      	{
      		if (multi.isSelected())
      			{
      			if((p1.getText().length() !=0) && (p2.getText().length()!=0))	
      			{
      			fr.setVisible(false);
      			new DoubleYahtzee(p1.getText(),p2.getText());
      			}
      			else
      			JOptionPane.showMessageDialog(null,"Please enter your names to start the game");
      			}
      			else if(single.isSelected())
      			{
      				if((p1.getText().length() !=0))
      						{
      				fr.setVisible(false);
      				new Yahtzee(p1.getText());	
      			}
      				else
      					JOptionPane.showMessageDialog(null,"Please enter your names to start the game");
      			}
      				else
      				JOptionPane.showMessageDialog(fr,"Please choose a game type");
      		}
      	
      	if(e.getSource()==cancel)
      	{
      		fr.setVisible(false);
      	}
      	
      }

      Comment

      Working...