Results 1 to 4 of 4
  1. #1
    obdi is offline Member
    Join Date
    Jul 2008
    Location
    CA
    Posts
    15
    Rep Power
    0

    Default [SOLVED] N2J - inputDialog

    I use the inputDialog to get a number to the textfield and start the game, but everytime i click the play button, the dialog pops up, everything else is fine i don't know what i should do with the inputDialog, i don't know any other ways to write it, so i only tried to put it in different places, but that didn't work, need help!
    Java Code:
    CASHONHAND = JOptionPane.showInputDialog("Enter The Amount You Wish To Play");
                cashonhand = Integer.parseInt(CASHONHAND);
                CashOnHandNum.setText("" + cashonhand);
    is what i have for the first input msg, after this the dialog should not pop again if i click play, how can i do it?

    Java Code:
    private class ClickPlay implements ActionListener
    	{
    		public void actionPerformed(ActionEvent e)
    		{       
                CASHONHAND = JOptionPane.showInputDialog("Enter The Amount You Wish To Play");
                cashonhand = Integer.parseInt(CASHONHAND);
                CashOnHandNum.setText("" + cashonhand);
                
    			ActionListener Begin = new TimeStamp();
    			MyTimer              = new Timer(35, Begin);
    			MyTimer.start();                     
    		}
    		private class TimeStamp implements ActionListener
    		{
    			public void actionPerformed(ActionEvent e)
                {
    				Action++;
                                   
    				if (Action < 20)
    				{
    					HideOne = RandomNumbers();
    					HideTwo = RandomNumbers();
    					HideTre = RandomNumbers();
    					NumberOne.setText("" + HideOne);
    					NumberTwo.setText("" + HideTwo);
    					NumberTre.setText("" + HideTre);	
    				}
    				else
    				{
    					Action = 0;
    					MyTimer.stop();
    					if(HideOne == HideTwo && HideTwo == HideTre && HideOne == HideTre)
    					{
    						JOptionPane.showMessageDialog(null, "You won $100!");
                            cashonhand = cashonhand + 100;
                            CashOnHandNum.setText("" + cashonhand);
                            totalwinning = totalwinning + 100;
                            TotalWinningNum.setText("" + totalwinning);
    					}
    					else if(HideOne == HideTwo || HideTwo == HideTre || HideOne == HideTre)
    					{...
                                                                      ...
    					}
    					NumberOne.setText("*");
    					NumberTwo.setText("*");
    					NumberTre.setText("*");
    				}
    			}
    		}
    	}

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    YOu need to show where and how you have added the actionListeners to your buttons. If you use the same ActionListener and want to do different things in actionPerformed() depending on which button was pressed, you need to checkwhich button was pressed. That is given in the ActionEvent object that is passed.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Best thing is use separate action listeners. In that way you are not mess with your implementation and you can easily clarify the events.

  4. #4
    obdi is offline Member
    Join Date
    Jul 2008
    Location
    CA
    Posts
    15
    Rep Power
    0

    Default

    Thanks Eranga, Norm, i did it with a new button, i still don't know how to do it in that START button, but at least got the job done :P

Similar Threads

  1. JFace's InputDialog Demonstration
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-07-2008, 05:40 PM
  2. Demonstration of the custom InputDialog class
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-02-2008, 08:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •