473,397 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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!
Jul 3 '17 #1
2 1294
chaarmann
785 Expert 512MB
Can you please show us what you have programmed so far?
Jul 3 '17 #2
thank you for showing concern. I figured it out myself.
Expand|Select|Wrap|Line Numbers
  1. @Override
  2. public void actionPerformed(ActionEvent e) {
  3.     if(e.getSource()==log)
  4.     {
  5.         if (multi.isSelected())
  6.             {
  7.             if((p1.getText().length() !=0) && (p2.getText().length()!=0))    
  8.             {
  9.             fr.setVisible(false);
  10.             new DoubleYahtzee(p1.getText(),p2.getText());
  11.             }
  12.             else
  13.             JOptionPane.showMessageDialog(null,"Please enter your names to start the game");
  14.             }
  15.             else if(single.isSelected())
  16.             {
  17.                 if((p1.getText().length() !=0))
  18.                         {
  19.                 fr.setVisible(false);
  20.                 new Yahtzee(p1.getText());    
  21.             }
  22.                 else
  23.                     JOptionPane.showMessageDialog(null,"Please enter your names to start the game");
  24.             }
  25.                 else
  26.                 JOptionPane.showMessageDialog(fr,"Please choose a game type");
  27.         }
  28.  
  29.     if(e.getSource()==cancel)
  30.     {
  31.         fr.setVisible(false);
  32.     }
  33.  
  34. }
Jul 4 '17 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Konrad Den Ende | last post by:
Is it possible to do at all? The software will be used on computers with western operative systems (so i guess, JVM will be english) but i'm asured that japanese will be enabled through IME so that...
4
by: porky008 | last post by:
I put in a next and previous button but it crashes when I run it. I also need it to loop around to the first or last if at the ends. Can some one help me with this? import java.awt.*; import...
6
by: vijaykumarsharma | last post by:
Hi all I am having a problem with JButton. JButton b=new JButton("save"); how can i get the name of the JButton b. Please give the anser for me
2
by: Bubbs | last post by:
Hi, I have two radio buttons, b1 and b2. Now these two are added to a button group g1. I also have a JButton called submit. Now when I press "submit" I want to print on the console using...
2
by: sokeefe | last post by:
I am trying to edit the GUI of a project in Netbeans. In particular, I am trying to add new JButtons. I get a NullPointerException when I try to add an Event to any given JButton (even ones that...
1
by: sokeefe | last post by:
I am trying to edit the GUI of a project in Netbeans. In particular, I am trying to add new JButtons. I get a NullPointerException when I try to add an Event to any given JButton (even ones that...
12
by: yeshello54 | last post by:
So I want to set the background color of a Jbutton. I know that the normal way to do such a thing is down the following way: JButton button = new JButton("xxxx"); button.setBackground(Color.RED);...
1
by: mlibot | last post by:
My JButton will be disabled when running my program... my JButton will be enabled if the value or parameter are equal to 3... for example: 1 value is path of the file i selected. 2 vaue is path of...
1
by: INeedHelpASAP | last post by:
I am trying to make a program that opens a panel that contains a JButton. When the user clicks the JButton it is supposed to redraw the Jbutton to a new random position on the panel. There is also a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.