943,525 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 807
  • Java RSS
Mar 18th, 2009
0

Assignment = Chat Window. . Urgent!

Expand Post »
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.

Java Syntax (Toggle Plain Text)
  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!
Reputation Points: 6
Solved Threads: 0
Newbie Poster
campuzcrazyness is offline Offline
17 posts
since Jan 2008
Mar 18th, 2009
0

Re: Assignment = Chat Window. . Urgent!

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/
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Mar 18th, 2009
0

Re: Assignment = Chat Window. . Urgent!

Looks like your doing pretty good to me!
Reputation Points: 8
Solved Threads: 4
Newbie Poster
blackcompe is offline Offline
11 posts
since Mar 2009
Mar 18th, 2009
0

Re: Assignment = Chat Window. . Urgent!

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. . ?
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
Mar 19th, 2009
0

Re: Assignment = Chat Window. . Urgent!

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 )
Reputation Points: 919
Solved Threads: 352
Nearly a Posting Maven
stultuske is offline Offline
2,471 posts
since Jan 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Help with java code, its urgent!!
Next Thread in Java Forum Timeline: Anyway to shorten this code?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC