File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem with code" Watch "problem with code" New topic

problem with code

Karen Wilson
Ranch Hand

Joined: Nov 19, 2012
Posts: 70
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: 70
and here is my attempt at adding the code to JFrame

here is the login page:

and here is the client page:
Greg Charles

Joined: Oct 01, 2001
Posts: 2969

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.
I agree. Here's the link:
subject: problem with code
It's not a secret anymore!