Hello Fellas,

I would like to ask some help from you.
I'm Mark from the Philippines.
I'm a newbie programmer and I'm new with java,that's why it's very difficult for me to make a program using java.

Our Teacher had given us an assignment using java,to make a simple chat window within one week. And that day is on friday,but still I'm not finished doing it.

one text field,one text area,three buttons(Send=to send the text in the text area,Clear=to clear out the text in the text area,Cancel=to cancel the text in the text field). .

Here is my code.

import java.awt.*;
import java.awt.event.*;
import java.awt.event.ItemEvent.*;

public class cwindow
    implements ActionListener, ItemListener 
    	{
  private Frame frame;
  private MenuBar menbar;
  private Menu men1;
  private Menu men2;
  private Menu men3;
  private MenuItem meni1;
  private MenuItem meni2;
  private MenuItem meni3;
  private MenuItem meni4;
  private CheckboxMenuItem meni5;
  
  private TextArea txta;
  private Button send = new Button("Send");
  private Button clear = new Button("Clear");
  private Button cancel = new Button("Cancel");
  private TextField marky;

  public void go() 
  	
  	{
    frame = new Frame("chat event");
    menbar = new MenuBar();
    
    txta = new TextArea(" ", 4, 20);
	send.addActionListener(this);
	frame.add(txta, BorderLayout.CENTER);
	marky = new TextField("   ", 25);
	frame.add(send,BorderLayout.EAST);

	marky.addKeyListener( new NameHandler() );
    frame.add(marky, BorderLayout.SOUTH);
    men1 = new Menu("File");
    men2 = new Menu("Edit");
    men3 = new Menu("Help");
    menbar.add(men1);
    menbar.add(men2);
    menbar.setHelpMenu(men3);
    frame.setMenuBar(menbar);

    meni1 = new MenuItem("New");
    meni2 = new MenuItem("Save");
    meni3 = new MenuItem("Load");
    meni4 = new MenuItem("Quit");
    
    meni1.addActionListener(this);
    meni2.addActionListener(this);
    meni3.addActionListener(this);
    meni4.addActionListener(this);
    men1.add(meni1);
    men1.add(meni2);
    men1.add(meni3);
    men1.addSeparator();
    men1.add(meni4);

    meni5 = new CheckboxMenuItem("Persistent");
    meni5.addItemListener(this);
    men1.add(meni5);

    frame.setSize(200,200);
     frame.pack();
    frame.setVisible(true);
   
  }

  public void actionPerformed( ActionEvent ae) {
    System.out.println("Button \"" + 
        ae.getActionCommand() + "\" Pressed.");

    if (ae.getActionCommand().equals("Quit")) {
      System.exit(0);
    }
  }

  public void itemStateChanged(ItemEvent ie) {
    String state = "Deselected";

    if (ie.getStateChange() == ItemEvent.SELECTED) {
      state = "Selected";
    }
    System.out.println(ie.getItem() + " " + state);
  }

 class NameHandler extends KeyAdapter {
    public void keyPressed(KeyEvent e) {
      char c = e.getKeyChar();
      if ( Character.isDigit(c)) {
        e.consume();
      }
    }
  }

  public static void main (String args[]) {
    cwindow markyMenu = new cwindow();
    markyMenu.go();
  }
}

I'm waiting for your positive response.

GodBlesS yAh All!

I will be very positive when I tell you that we are not just going to do it for you.

Tell us exactly what problem you are having and we will help you correct it, otherwise, http://www.rentacoder.com/

Looks like your doing pretty good to me!

Maybe I don't understand what a chat window is, but don't you have to connect to another machine in order to chat with someone? I don't see code involving Sockets anywhere. . ?

Maybe I don't understand what a chat window is, but don't you have to connect to another machine in order to chat with someone? I don't see code involving Sockets anywhere. . ?

since he states he's a newbie on the entire programming part, I doubt he's already been given classes in programming over a network. maybe he just means some kind of a chat-simulation where only the text entered locally has bto be send to the textarea.

if so, all he needs to do is

String b = textArea.getText();
b += newText;
textArea.setText(b);

(or something like that :) )

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.