GUI chat room

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mralam
    New Member
    • Aug 2007
    • 5

    #1

    GUI chat room

    i have to do the following:
    write a Java program to implement the GUI for a chat program.The program should include components attached to a form: a text field, a pop-up choice-group and up to 8 string items which will be messages entered by the user. Users should be presented with two
    commands, ‘Send’ and ‘Exit’.
    Beneath the text field and user selection choice-group, there should always be no more than 8 string items, also identifying which user wrote which message. When a message is added to the group of messages, the text field should be erased ready for the next message. After 8 messages have been added to the group of messages, any additional messages are added to the end of the group and the first (oldest) message is removed. Another way to describe this is to
    display only the last 8 messages entered.


    Any ideas how to do this
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by mralam
    i have to do the following:
    write a Java program to implement the GUI for a chat program.The program should include components attached to a form: a text field, a pop-up choice-group and up to 8 string items which will be messages entered by the user. Users should be presented with two
    commands, ‘Send’ and ‘Exit’.
    Beneath the text field and user selection choice-group, there should always be no more than 8 string items, also identifying which user wrote which message. When a message is added to the group of messages, the text field should be erased ready for the next message. After 8 messages have been added to the group of messages, any additional messages are added to the end of the group and the first (oldest) message is removed. Another way to describe this is to
    display only the last 8 messages entered.


    Any ideas how to do this
    Depends on how you've implemented your message displaying but a general approach is to check for the number of messages currently being displayed before adding a new message.

    Comment

    • mralam
      New Member
      • Aug 2007
      • 5

      #3
      Originally posted by r035198x
      Depends on how you've implemented your message displaying but a general approach is to check for the number of messages currently being displayed before adding a new message.
      Is there any code that is ready to use?

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by mralam
        Is there any code that is ready to use?
        There's probably lots of code out there ready to use. We don't give out ready to use code here. We prefer to help those that make an effort to write the code themselves. Do you have any codes that you've written so far for this?

        Comment

        • mralam
          New Member
          • Aug 2007
          • 5

          #5
          Originally posted by r035198x
          There's probably lots of code out there ready to use. We don't give out ready to use code here. We prefer to help those that make an effort to write the code themselves. Do you have any codes that you've written so far for this?
          I ll try to do something and ill get back here.

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by mralam
            I ll try to do something and ill get back here.
            Great. Don't keep us waiting too long.

            Comment

            • mralam
              New Member
              • Aug 2007
              • 5

              #7
              this the code that i did so far, any suggestions?

              Code:
              import javax.microedition.lcdui.Command;
              import javax.microedition.lcdui.CommandListener;
              import javax.microedition.lcdui.Display;
              import javax.microedition.lcdui.Displayable;
              import javax.microedition.lcdui.Form;
              import javax.microedition.lcdui.TextField;
              import javax.microedition.midlet.MIDlet;
              
              public class TextFieldCapture extends MIDlet implements CommandListener {
               private Display display;
              
               private Form form = new Form("GUI chat");
              
               private Command send = new Command("Send", Command.SCREEN, 1);
              
               private Command exit = new Command("Exit", Command.EXIT, 1);
              
               private TextField textfield = new TextField("Type Your message:", "", 90, TextField.ANY);
              
               public TextFieldCapture() {
                 display = Display.getDisplay(this);
                 form.addCommand(exit);
                 form.addCommand(send);
                 form.append(textfield);
                 form.setCommandListener(this);
               }
              
               public void startApp() {
                 display.setCurrent(form);
               }
              
               public void pauseApp() {
               }
              
               public void destroyApp(boolean unconditional) {
               }
              
               public void commandAction(Command command, Displayable displayable) {
                 if (command == send) {
                   textfield.setString("Hello, " + textfield.getString());
                   form.removeCommand(send);
                 } else if (command == exit) {
                   destroyApp(false);
                   notifyDestroyed();
                 }
               }
              }
              
              
              // TODO Auto-generated method stub
              Form form = new Form("Chat GUI");
              
              //command options
              TextField textfield =new TextField("TEXT FIELD","",25,TextField.ANY);
              form.append(textfield);
              display.setCurrent(form);
              
              }
              
              }

              Comment

              • Nepomuk
                Recognized Expert Specialist
                • Aug 2007
                • 3111

                #8
                Originally posted by mralam
                this the code that i did so far, any suggestions?

                [code=java]
                import javax.microedit ion.lcdui.Comma nd;
                import javax.microedit ion.lcdui.Comma ndListener;
                import javax.microedit ion.lcdui.Displ ay;
                import javax.microedit ion.lcdui.Displ ayable;
                import javax.microedit ion.lcdui.Form;
                import javax.microedit ion.lcdui.TextF ield;
                import javax.microedit ion.midlet.MIDl et;
                ...
                [/code]
                So, you're writing this for a mobile device, are you? At least from the API it seems to me, that this is what the Java Microedition is for - correct me if I'm wrong.

                Otherwise it looks fine to me so far. Do you have any problems with your code or is it working as it should? If problematic, tell us what the error is and I'm sure someone here will be able to help you find a solution.

                Greetings,
                Nepomuk

                Comment

                • ashitpro
                  Recognized Expert Contributor
                  • Aug 2007
                  • 542

                  #9
                  Just have a look at RMI in JAVA
                  I already made one chat room using this. Its very simple to use

                  Comment

                  Working...