• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Coding a Client side program

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Norm Radder, and other programmers,

Thank you for your recommendations. I have put the code below into code tags.I hope they are appropriate.

I will try describing the difficulty I am encountering with the code more clearly than I did before.

Because I (or anyone, presumably) can't write ClientGUI extends JFrame, Thread - (though my Ivor Horton book says you can)
- I made two classes for ClientGUI - one holding the main method which instantiates and calls methods held within the other ClientGui program.

However there is the consequent problem in that ClientGUI holds an ActionListener/ Performed method - so it can't object.method() call from

the MainMethod class - ie: it can't invoke the sendmessage() method within it from the MainMethod, as the ActionPerformed is to press the

button 'SEND' which is in the GUI created by ClientGUI program.

The other methods like getConnection() can be object method called from within the MainMethod, as they are not contingent on an

ActionListener/Performed type method. If I copy the object.method() call process that invokes these methods in the MainMethod into the

ActionListener/Performed method in the clientGUI so that it might read :-

{
ClientGUI clientgui = new ClientGUI();
clientgui.sendMessage();
}

-then upon pressing the GUI's 'SEND' button I just get another GUI - from the instantiation, without the sendMessage() method ever being

reached, or executed.

Okay, maybe making two programs out of one wasn't such a cool idea after all, but then how do I extend one program from JPane (which I need

for the GUI) and Thread (which I need also to thread the sendMessage(), recieveMessage() methods?

I was thinking it'd be easier to get an idea of the problem if you just ran these programs, as writ, as they compile and run okay, they just

don't work (ie: take messages to the GUI'S textfield to and fro from Server and Client consoles, nor from GUI's textfield to textArea) like I

(or anyone) would wish them to. *****************************
**************************************************************************
***************************************************************************
***************************************************************************

As you may know, you have to run the Server program first, then the MainMethod to launch the ClientGUI program. I think the methods in ClientGUI are coded alright - to put input to text field to input and output streams and to transfer message thus initialised to the textArea.
Anyway thank you much for your help, particularly as most people out there are preoccupied with loot before they're prepared to offer any help.
Yours
Simon

[ July 26, 2008: Message edited by: Simon Evans ]

[ July 26, 2008: Message edited by: Simon Evans ]

[ July 26, 2008: Message edited by: Simon Evans ]
[ July 26, 2008: Message edited by: Simon Evans ]
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure why the MainMethod class extends Thread as there is not a run() method in it. Why do you need a Thread object?
 
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't read through everything in your comments (partly because the opening comments have a couple of scary run on sentences). But this comment did jump out at me:

Originally posted by Simon Evans:

...I can't subclsss (extend) it from the Jframe and Thread class using extends JFrame, Thread as the compiler doesn't like it...


In Java, you can only extend a single class. Extending multiple classes can result in the Diamond of Death, so Java doesn't allow it. But a class can implement multiple interfaces. And a class can extend one class and implement one or more interfaces.

So extend JFrame and implement the Runnable interface. You will then need to implement Ruannable's run() method in your class. The Thread class actually implements Runnable. But generally when you want to make something so it can run in a separate thread, you implement the Runnable method. You can then construct a Thread passing in the class that implements the Runnable interface.

For more information on multi-threading, see the Java Tutorial lesson on Concurrency. You may then want to check out the fine book Java Threads, Third Edition, co-authored by Scott Oaks and Henry Wong. Henry is one of the moderators here at JavaRanch.

Again, this is just some basic information based on a quick look at your stuff. But if I follow the gist of what yo want to do, that should help.

Some housekeeping notes...

I recommend you edit your post above and wrap your code in UBB [code] tags. Also see the UseCodeTags FAQ. You can just click the edit button , highlight the code, click the "code" button below the editing text field, then click the "Edit Post" button to save the changes. People will generally not want to spend the time reading unformatted code. So you will get more responses if you make the change.

I would also recommend editing your comments and questions so they are a clearer. As explained in this FAQ, while people here want to help others, if they have to spend too much time trying to figure out what you are asking, they will simply move on to other threads. We're all computer nuts... so for us it's fun answering computer questions... it's not fun trying to figure out what the question is.

Beat Regards,
Mark
[ July 25, 2008: Message edited by: Mark Vedder ]
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your listener class, you need a reference to the existing client class. You do NOT want to create a new one. Pass a reference to the client class when you create the listener and have the listener's constructor save it to be used by the actionPerformed method.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have put the code below into code tags.I hope they are appropriate.



The purpose of code tags is to preserve formatting -- which is, of course, to help with readibility. However, it doesn't look like you have any formatting in your code.

Henry
reply
    Bookmark Topic Watch Topic
  • New Topic