Results 1 to 6 of 6
Thread: My Chat program
- 06-24-2011, 10:04 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 3
- Rep Power
- 0
My Chat program
Hi, Im new to Java and programing in general. Currently, I am working on a chat program for me and my friends to use, and was wondering how I would add text submitted to the overall chunk of text (I don't know what its called). Obviously, completion is a long way off, but thats fine. So don't give me crap about not having the skills to make an online chat program, I know that, it just gives me a reason to learn the skills. anyway, heres my rather clunky bit of code.
your help would be greatly, appreciatedJava Code:import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.applet.*; public class chatStuff extends JFrame implements ActionListener { public String name = ("Name"); public void framer(){ //setup this.setTitle(name + "'s Chat Client"); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setAlwaysOnTop(true); ///setup //components JTextArea txt = new JTextArea("Say hello!", 20, 30); String mytype = "" ; JTextField typehere = new JTextField(mytype, 20); JButton submit = new JButton("Say"); JLabel logo = new JLabel(new ImageIcon ("/home/***/logo.png")); ///components //containers JPanel pantxt = new JPanel(); ///containers //Component adding pantxt.add(logo); pantxt.add(txt); pantxt.add(typehere); pantxt.add(submit); this.add(pantxt); this.add(pantxt); this.setVisible(true); this.pack(); ///component adding //layout; this.setSize(400, 450); this.setMaximizedBounds(getBounds()); } public void actionPerformed(ActionEvent arg0) { } }
- 06-24-2011, 10:46 PM #2
Can you explain what you mean here?how I would add text submitted to the overall chunk of text
By text I understand the something like contents of a String that is to be displayed to a human for information.
- 06-24-2011, 10:50 PM #3
Member
- Join Date
- Jun 2011
- Posts
- 3
- Rep Power
- 0
sorry, thats kinda vague. I meant how would you take a string that the user types into the textfield "typehere" and add it to the textarea. or is there a better way to do this?
- 06-24-2011, 10:53 PM #4
Have you read the API doc for the textfield class and the textarea class? There are methods to get the contents and methods to add contents. You want to get the contents of the textfield and add it to the contents of the textarea.
The API doc: Java Platform SE 6
- 06-24-2011, 11:14 PM #5
Some remarks:
- I see a simple GUI, lacking a main(). Probably you had one but did'n't post it: best to post code as a SSCCE (small self contained compiling example).
- You called your class chatStuff. Convention is to start classsnames with a capital.
- The main problem is that the gui-components are declared within the method framer(): their scope is that method, so your actionPerformed() doesn't see them or know they exist, and so can't read or write them: declare them as globals, outside the methods, as f.i. private JTextArea txt =...;'
- Your button will only work if you add a listener to it: submit.addActionListener(this)
That's it for now, otherwise you're chatting tomorrow without learning anything
No bug ever had to calculate its fitnessfunction.
- 06-25-2011, 01:31 AM #6
Member
- Join Date
- Jun 2011
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
How to code a program to send messages to a chat program?
By josh2992 in forum New To JavaReplies: 2Last Post: 04-02-2011, 12:57 PM -
MultiThreading Chat Program
By Noelf21 in forum Threads and SynchronizationReplies: 2Last Post: 12-23-2009, 10:49 AM -
Help with chat client program
By srivigneshwar in forum New To JavaReplies: 1Last Post: 04-03-2009, 06:32 PM -
simple chat program
By munishmhr in forum NetworkingReplies: 2Last Post: 03-25-2009, 04:00 PM -
Java Program chat
By susan in forum Advanced JavaReplies: 1Last Post: 07-25-2007, 09:05 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks