Results 1 to 3 of 3
- 02-25-2009, 09:57 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 1
- Rep Power
- 0
Java, output string, getting correct output? HELP!
Hi, I have this piece of code;
Java Code:resultText.setText("Sorry the number is " + WHAT GOES HERE HELP!); finishGame(); break; case 1: //won resultText.setText("Well done it is " + playerNumber); finishGame(); break; case 2: resultText.setText("higher"); break; case 3: resultText.setText("lower"); break;
Java Code:public TestGame(int maxValue, int maxNumberOfGuesses) { super(maxValue, maxNumberOfGuesses); //ask user for guess number String numberString = JOptionPane.showInputDialog(null, "Please input guess number:"); //save it guessNumber = Integer.parseInt(numberString);
Any help appreciated. Thanks.
- 02-25-2009, 10:35 PM #2
Since I don't see all of your code, not sure if this will work:
instantiate the class at the beginning at classB ... example:
Java Code:myClassA mca = new myClassA();
Java Code:mca.guessNumber
CJSL
EDIT: this code is not a very good example.... the one in the my below post is a little better.Last edited by CJSLMAN; 02-26-2009 at 12:45 AM. Reason: corrected the termonology
Chris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 02-26-2009, 12:44 AM #3
A couple comments...
- You didn't fare very well over at the Sun forums (lesson learned: don't cross post)
- what you want to do is not as easy as it seems...
I'll try to explain....
you have two classes: Class A and Class B.
I think what you want to do is pass a variable value from class A so it can be used in class B... correct? Please make sure that this is what you want to do: can this be done in Class A with a mehtod?
You can't first run classA and then run class B for this to work. What has to happen is that you have to call the method that's in class B (from Class A) that needs that variable from Class A (sounds like "Who's on first?").
in Class A:
Java Code:String varToSend ="Hello !!!"; ClassB cb = new ClassB(); //instantiate class B in class A cb.heresTheVariable(varToSend);//call the class B method
Java Code:public void heresTheVariable(String varFromClassA) { System.out.println("The variable form class A: " + varFromClassA); }
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
Similar Threads
-
Calling a Jython script from a Java Servlet returns incomplete output
By bthakur in forum Java ServletReplies: 9Last Post: 01-23-2014, 08:17 PM -
the explanation of output of simple java program
By amol84 in forum New To JavaReplies: 1Last Post: 11-06-2008, 06:06 PM -
What will be output and why
By huma in forum Threads and SynchronizationReplies: 4Last Post: 06-26-2008, 11:14 PM -
JSP to output Java String Array
By irenavassilia in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 03-31-2008, 05:11 PM -
Java Swing class capturing output to the console
By Java Tip in forum Java TipReplies: 0Last Post: 03-12-2008, 12:24 PM
Bookmarks