Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / January 2006

Tip: Looking for answers? Try searching our database.

Reading from JButton

Thread view: 
Nandu - 03 Jan 2006 20:51 GMT
hi
i have a client server program.. i am sending data variable
'msgFromClient' through PrintWriter object as follwoing
pwOut.println(msgFromClient);
in the program.. i am reading 'msgFromClient' from the following two
functions. Now i want to trigger the above statement only when user has
given his input through one of the following fucntions. i can trigger
directly by keeping the statement in both the function. but my
statement is outside the both functions and now i want to trigger the
statment only when input is given by user ( ie. when user clicks one of
the 2 buttons)
Please help me out to solve this situation

private payoff_oneActionPerformed(ActionEvent ae) {
msgFromClient = payoff_one.getText();
payoff_one.setEnabled(false);
payoff_two.setEnabled(false);
game_status.setText("Please wait for your Opponent to Choose");
}
private payoff_twoActionPerformed(ActionEvent ae) {
msgFromClient = payoff_two.getText();
payoff_one.setEnabled(false);
payoff_two.setEnabled(false);
game_status.setText("Please wait for your Opponent to Choose");
}
Kent Paul Dolan - 03 Jan 2006 22:03 GMT
-> hi

-> i have a client server program.. i am sending data variable
-> 'msgFromClient' through PrintWriter object as follwoing
-> pwOut.println(msgFromClient);
-> in the program.. i am reading 'msgFromClient' from the following two
-> functions. Now i want to trigger the above statement only when user
has
-> given his input through one of the following fucntions. i can
trigger
-> directly by keeping the statement in both the function. but my
-> statement is outside the both functions and now i want to trigger
the
-> statment only when input is given by user ( ie. when user clicks one
of-
-> the 2 buttons)
-> Please help me out to solve this situation

-> private payoff_oneActionPerformed(ActionEvent ae) {
-> msgFromClient = payoff_one.getText();
-> payoff_one.setEnabled(false);
-> payoff_two.setEnabled(false);
-> game_status.setText("Please wait for your Opponent to Choose");
-> }
-> private payoff_twoActionPerformed(ActionEvent ae) {
-> msgFromClient = payoff_two.getText();
-> payoff_one.setEnabled(false);
-> payoff_two.setEnabled(false);
-> game_status.setText("Please wait for your Opponent to Choose");
-> }

I don't think you can rename actionPerformed(ActionEvent ae) like
that, I'm pretty sure that name is a _required_ one for implementing
the ActionListener interface, and I think it must be public, as well.

It isn't clear from your description which "statement" is outside your
two functions, but this kind of stuff _always_ works; the guts of
"actionPerformed" don't have to be in the routine itself.

public void actionPerformed(ActionEvent ae)
{
 do_something(ae);
}

private void do_something(ActionEvent ae)
{
// the real stuff you want to do goes here.
}

They don't even have to be in the same class:

private void actionPerformed(ActionEvent ae)
{
 MyUtilities.do_Something(ActionEvent ae, Payoff_one p1, Payoff_two
p2);
}

in MyUtilities:

public static void do_Something(ActionEvent ae, Payoff_one p1,
Payoff_two p2)
{
 // put the real stuff you want to do here. Notice that since this is
a static
 // routine, we had to pass in the instance objects visible from the
instance
 // object where the ActionListener was implemented, which probably
 // wouldn't be visible from a static method otherwise.
}

I may have messed up the details, I often do, but the generality of
that
Works For Me.

HTH

xanthian.
Andrew Thompson - 04 Jan 2006 04:19 GMT
> hi
> i have a client server program..

Please refrain from multi-posting

Signature

Andrew Thompson
physci, javasaver, 1point1c, lensescapes - athompson.info/andrew



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.