Assignment = Chat Window. . Urgent!

Reply

Join Date: Jan 2008
Posts: 15
Reputation: campuzcrazyness is an unknown quantity at this point 
Solved Threads: 0
campuzcrazyness's Avatar
campuzcrazyness campuzcrazyness is offline Offline
Newbie Poster

Assignment = Chat Window. . Urgent!

 
0
  #1
Mar 18th, 2009
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.

  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.awt.event.ItemEvent.*;
  4.  
  5. public class cwindow
  6. implements ActionListener, ItemListener
  7. {
  8. private Frame frame;
  9. private MenuBar menbar;
  10. private Menu men1;
  11. private Menu men2;
  12. private Menu men3;
  13. private MenuItem meni1;
  14. private MenuItem meni2;
  15. private MenuItem meni3;
  16. private MenuItem meni4;
  17. private CheckboxMenuItem meni5;
  18.  
  19. private TextArea txta;
  20. private Button send = new Button("Send");
  21. private Button clear = new Button("Clear");
  22. private Button cancel = new Button("Cancel");
  23. private TextField marky;
  24.  
  25. public void go()
  26.  
  27. {
  28. frame = new Frame("chat event");
  29. menbar = new MenuBar();
  30.  
  31. txta = new TextArea(" ", 4, 20);
  32. send.addActionListener(this);
  33. frame.add(txta, BorderLayout.CENTER);
  34. marky = new TextField(" ", 25);
  35. frame.add(send,BorderLayout.EAST);
  36.  
  37. marky.addKeyListener( new NameHandler() );
  38. frame.add(marky, BorderLayout.SOUTH);
  39. men1 = new Menu("File");
  40. men2 = new Menu("Edit");
  41. men3 = new Menu("Help");
  42. menbar.add(men1);
  43. menbar.add(men2);
  44. menbar.setHelpMenu(men3);
  45. frame.setMenuBar(menbar);
  46.  
  47. meni1 = new MenuItem("New");
  48. meni2 = new MenuItem("Save");
  49. meni3 = new MenuItem("Load");
  50. meni4 = new MenuItem("Quit");
  51.  
  52. meni1.addActionListener(this);
  53. meni2.addActionListener(this);
  54. meni3.addActionListener(this);
  55. meni4.addActionListener(this);
  56. men1.add(meni1);
  57. men1.add(meni2);
  58. men1.add(meni3);
  59. men1.addSeparator();
  60. men1.add(meni4);
  61.  
  62. meni5 = new CheckboxMenuItem("Persistent");
  63. meni5.addItemListener(this);
  64. men1.add(meni5);
  65.  
  66. frame.setSize(200,200);
  67. frame.pack();
  68. frame.setVisible(true);
  69.  
  70. }
  71.  
  72. public void actionPerformed( ActionEvent ae) {
  73. System.out.println("Button \"" +
  74. ae.getActionCommand() + "\" Pressed.");
  75.  
  76. if (ae.getActionCommand().equals("Quit")) {
  77. System.exit(0);
  78. }
  79. }
  80.  
  81. public void itemStateChanged(ItemEvent ie) {
  82. String state = "Deselected";
  83.  
  84. if (ie.getStateChange() == ItemEvent.SELECTED) {
  85. state = "Selected";
  86. }
  87. System.out.println(ie.getItem() + " " + state);
  88. }
  89.  
  90. class NameHandler extends KeyAdapter {
  91. public void keyPressed(KeyEvent e) {
  92. char c = e.getKeyChar();
  93. if ( Character.isDigit(c)) {
  94. e.consume();
  95. }
  96. }
  97. }
  98.  
  99. public static void main (String args[]) {
  100. cwindow markyMenu = new cwindow();
  101. markyMenu.go();
  102. }
  103. }


I'm waiting for your positive response.

GodBlesS yAh All!
"Doing your BEST is better than being the BEST!"
Sometimes, the more you become educated the more you become Simple & Humble.
campuzcraze_4lyf@yahoo.com
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,358
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Assignment = Chat Window. . Urgent!

 
0
  #2
Mar 18th, 2009
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/
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 11
Reputation: blackcompe is an unknown quantity at this point 
Solved Threads: 4
blackcompe's Avatar
blackcompe blackcompe is offline Offline
Newbie Poster

Re: Assignment = Chat Window. . Urgent!

 
0
  #3
Mar 18th, 2009
Looks like your doing pretty good to me!
Preparing for SCJP...
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,568
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 196
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: Assignment = Chat Window. . Urgent!

 
0
  #4
Mar 18th, 2009
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. . ?
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: Assignment = Chat Window. . Urgent!

 
0
  #5
Mar 19th, 2009
Originally Posted by BestJewSinceJC View Post
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 )
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC