aspose file tools*
The moose likes Beginning Java and the fly likes problem with code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem with code" Watch "problem with code" New topic
Author

problem with code

Karen Wilson
Ranch Hand

Joined: Nov 19, 2012
Posts: 68
I found a chat application online that uses client/server but they just wrote out all the code to add the buttons, textfields etc to the frame.
I prefer to add a JFrame and drag and drop the stuff over and then create event handlers for the buttons.
But when i try putting the code into my frame nothing works.
I really hope someone can help

The website code works perfectly I just want to put everything in a JFrame.
I would really appreciate if someone could take a look and see what I am doing wrong

here is the website code:




Karen Wilson
Ranch Hand

Joined: Nov 19, 2012
Posts: 68
and here is my attempt at adding the code to JFrame

here is the login page:


and here is the client page:
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2861
    
  11

Of the two, Login is the easier to convert to a JFrame. Why? Because it's not extending a class now. You can just declare it to extend JFrame, remove the JFrame frame1 field, change the first line of the constructor from "frame1 = new JFrame("Login Page") to super("Login Page"), and finally change all other references of frame1 to this. It's all bookkeeping really.

MyClient is just a bit harder since it extends WindowAdapter. You'd either have to make it implement WindowListener (and provide dummy implementations for the methods you don't care about) or create a new WindowAdapter, possibly as an anonymous inner class, with the windowClosing() method that's currently in MyClient. Still bookkeeping, but somewhat harder bookkeeping.
 
Consider Paul's rocket mass heater.
 
subject: problem with code