Results 1 to 4 of 4
Thread: [SOLVED] N2J - inputDialog
- 07-14-2008, 11:19 PM #1
Member
- Join Date
- Jul 2008
- Location
- CA
- Posts
- 15
- Rep Power
- 0
[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!
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:CASHONHAND = JOptionPane.showInputDialog("Enter The Amount You Wish To Play"); cashonhand = Integer.parseInt(CASHONHAND); CashOnHandNum.setText("" + cashonhand);
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("*"); } } } }
- 07-15-2008, 01:12 AM #2
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.
- 07-15-2008, 04:38 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Best thing is use separate action listeners. In that way you are not mess with your implementation and you can easily clarify the events.
- 07-15-2008, 08:07 AM #4
Member
- Join Date
- Jul 2008
- Location
- CA
- Posts
- 15
- Rep Power
- 0
Similar Threads
-
JFace's InputDialog Demonstration
By Java Tip in forum SWTReplies: 0Last Post: 07-07-2008, 04:40 PM -
Demonstration of the custom InputDialog class
By Java Tip in forum SWTReplies: 0Last Post: 07-02-2008, 07:56 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks