JInternalFrame listeners stops working if more than one opened ?

Hi all, I'm trying to write some kind of chat program for my term project
I'm really stucked at this point.
I connect to a server, get chat room lists, join to a chat room, there's no problem at this first chat room ( internalFrame ), everything is fine ( I can refresh user list with pressing F5, send messages through send message button ), when I join another chat room ( second internalFrame ), problems start to occur, I can refresh with pressing F5, but I cannot send messages to server, server recieves my messages as null messages, still I can send messages with the first internal frame I opened but cannot refresh with pressing F5 in the first frame !
here are my codes for certain parts
main class
public class ChatClientMain extends JFrame
                               implements ActionListener {
// items etc here
    public ChatClientMain() {
        super("project");
        connectedToServer=false;
        int inset = 50;
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setBounds(inset, inset,
                  screenSize.width  - inset*2,
                  screenSize.height - inset*2);
        desktopPane = new JDesktopPane(); //a specialized layered pane
        setContentPane(desktopPane);
        desktopPane.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    public void actionPerformed(ActionEvent event)
       if ( event.getSource() == connectMenuItem )
                   try
                        connectionSocket = new Socket(serverName,serverPort);
                                inFromServer = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
                        outToServer = new PrintStream(connectionSocket.getOutputStream());
                   catch (IOException e)
                        JOptionPane.showMessageDialog(null, "Cannot connect to server\nProgram will exit", "Cannot connect", JOptionPane.ERROR_MESSAGE);
                        e.printStackTrace();
                        System.exit(1);
                   createServerFrame(outToServer);
                   new ConnectionToServer(nickName,connectionSocket,inFromServer,outToServer).start();
                // other actions etc.
    protected static void createChatFrame(String roomName)
        ChatFrame frame = new ChatFrame(roomName);
        frame.setVisible(true);
        desktopPane.add(frame);
        try
            frame.setSelected(true);
        catch (java.beans.PropertyVetoException e) {}
        outToServer.println("GET USER LIST"+roomName);
here's thread for connection to server
public class ConnectionToServer extends Thread
     public ConnectionToServer(String nick,Socket socket,BufferedReader bf,PrintStream ps)
          nickName=nick;
          inFromServer = bf;
          outToServer = ps;
          connectionSocket=socket;
          ChatClientMain.connectedToServer=true;
          outToServer.println("CONNECTION INITIALIZATION"+nickName);
     public void run()
          try
               while(true)
                    recievedMessage = inFromServer.readLine();
                    System.out.println(recievedMessage);
                    if (recievedMessage.startsWith("CHATROOM")) // problem here ( in split function ), cannot parse since recieves null message
                         String[] chatRoomMessageParts = recievedMessage.split("#");
                         String chatRoomName = chatRoomMessageParts[1];
                         String chatRoomMessage = chatRoomMessageParts[2];
                         System.out.println("room name : " + chatRoomName + " message : " + chatRoomMessage);
                                //some other protocols I implemented here
                    if (!roomListRecieving || ! userListRecieving)
                         ServerFrame.serverConversation.append(recievedMessage + "\n");
          catch (IOException e)
               e.printStackTrace();
code for chat frame, which works for one, but not for two :S
public class ChatFrame extends JInternalFrame
     private static final long serialVersionUID = 1L;
     static int openFrameCount = 0;
     static int xOffset = 60;
     static int yOffset = 60;
     JPanel chatRoomContent;
     JLabel chatRoom;
     JLabel users;
     JTextArea roomConversation;
     static JList roomUserList;
     JScrollPane conversationScroll;
     JScrollPane userListScroll;
     JTextField roomMessage;
     JButton roomMessageButton;
     static DefaultListModel userListModel;
     ListSelectionListener userListListener;
     public ChatFrame(final String roomName)
          super("Chat Room : " + roomName,
                    true, //resizable
                    true, //closable
                    true, //maximizable
                    true);//iconifiable
          openFrameCount++;
          chatRoomContent = new JPanel();
          chatRoomContent.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
          chatRoomContent.setLayout(new GridBagLayout());
          GridBagConstraints c = new GridBagConstraints();
          c.fill = GridBagConstraints.BOTH;
// I set proper values for c everytime I add new item to pane
          chatRoom = new JLabel("Now chatting in : " + roomName);
          chatRoomContent.add(chatRoom,c);
          users = new JLabel("User List");
          chatRoomContent.add(users,c);
          roomConversation = new JTextArea();
          roomConversation.setEditable(false);
          conversationScroll = new JScrollPane();
          conversationScroll.setViewportView(roomConversation);
          chatRoomContent.add(conversationScroll,c);
          userListModel = new DefaultListModel();
          userListListener = new ListSelectionListener(){
               public void valueChanged(ListSelectionEvent event) {
                    JList lsm = (JList) event.getSource();
                    if(event.getValueIsAdjusting())
                         roomConversation.append("Starting chat with " + lsm.getSelectedValue() + "\n");
                         String chatName = (String) lsm.getSelectedValue();
                         ChatClientMain.createPrivateChatFrame(chatName);
          roomUserList = new JList();
//list props set here
          chatRoomContent.add(userListScroll,c);
          roomMessage = new JTextField();
          chatRoomContent.add(roomMessage,c);
          roomMessageButton = new JButton("Send Message");
          roomMessageButton.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent event) {
                    if (!roomMessage.getText().equals(""))
                         String message = ChatClientMain.nickName + " : " + roomMessage.getText() + "\n"; // message person wrote
                         roomConversation.append(message);
                         roomMessage.setText("");
                         ChatClientMain.outToServer.println("CHATROOM#"+roomName+"#"+message);  // message I'm sending to server
          chatRoomContent.add(roomMessageButton,c);
          this.setFocusable(true);
          this.addKeyListener(new KeyListener() {
               @Override
               public void keyPressed(KeyEvent arg0) {
                    int keyNo = arg0.getKeyCode();
                    if ( keyNo == KeyEvent.VK_F5)
                         ChatClientMain.outToServer.println("GET USER LIST"+roomName);       //refresh part with works just for the last internal frame I opened
               //other methods
          this.addInternalFrameListener(new InternalFrameListener() {
               public void internalFrameClosed(InternalFrameEvent arg0) {
                    ChatClientMain.leaveRoom(roomName);
                        //other methods here
          add(chatRoomContent);
          setSize(525,525);
          setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
}I would really be thankful if you help..

Hi all, I'm trying to write some kind of chat program for my term project
I'm really stucked at this point.
I connect to a server, get chat room lists, join to a chat room, there's no problem at this first chat room ( internalFrame ), everything is fine ( I can refresh user list with pressing F5, send messages through send message button ), when I join another chat room ( second internalFrame ), problems start to occur, I can refresh with pressing F5, but I cannot send messages to server, server recieves my messages as null messages, still I can send messages with the first internal frame I opened but cannot refresh with pressing F5 in the first frame !
here are my codes for certain parts
main class
public class ChatClientMain extends JFrame
                               implements ActionListener {
// items etc here
    public ChatClientMain() {
        super("project");
        connectedToServer=false;
        int inset = 50;
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setBounds(inset, inset,
                  screenSize.width  - inset*2,
                  screenSize.height - inset*2);
        desktopPane = new JDesktopPane(); //a specialized layered pane
        setContentPane(desktopPane);
        desktopPane.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    public void actionPerformed(ActionEvent event)
       if ( event.getSource() == connectMenuItem )
                   try
                        connectionSocket = new Socket(serverName,serverPort);
                                inFromServer = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
                        outToServer = new PrintStream(connectionSocket.getOutputStream());
                   catch (IOException e)
                        JOptionPane.showMessageDialog(null, "Cannot connect to server\nProgram will exit", "Cannot connect", JOptionPane.ERROR_MESSAGE);
                        e.printStackTrace();
                        System.exit(1);
                   createServerFrame(outToServer);
                   new ConnectionToServer(nickName,connectionSocket,inFromServer,outToServer).start();
                // other actions etc.
    protected static void createChatFrame(String roomName)
        ChatFrame frame = new ChatFrame(roomName);
        frame.setVisible(true);
        desktopPane.add(frame);
        try
            frame.setSelected(true);
        catch (java.beans.PropertyVetoException e) {}
        outToServer.println("GET USER LIST"+roomName);
here's thread for connection to server
public class ConnectionToServer extends Thread
     public ConnectionToServer(String nick,Socket socket,BufferedReader bf,PrintStream ps)
          nickName=nick;
          inFromServer = bf;
          outToServer = ps;
          connectionSocket=socket;
          ChatClientMain.connectedToServer=true;
          outToServer.println("CONNECTION INITIALIZATION"+nickName);
     public void run()
          try
               while(true)
                    recievedMessage = inFromServer.readLine();
                    System.out.println(recievedMessage);
                    if (recievedMessage.startsWith("CHATROOM")) // problem here ( in split function ), cannot parse since recieves null message
                         String[] chatRoomMessageParts = recievedMessage.split("#");
                         String chatRoomName = chatRoomMessageParts[1];
                         String chatRoomMessage = chatRoomMessageParts[2];
                         System.out.println("room name : " + chatRoomName + " message : " + chatRoomMessage);
                                //some other protocols I implemented here
                    if (!roomListRecieving || ! userListRecieving)
                         ServerFrame.serverConversation.append(recievedMessage + "\n");
          catch (IOException e)
               e.printStackTrace();
code for chat frame, which works for one, but not for two :S
public class ChatFrame extends JInternalFrame
     private static final long serialVersionUID = 1L;
     static int openFrameCount = 0;
     static int xOffset = 60;
     static int yOffset = 60;
     JPanel chatRoomContent;
     JLabel chatRoom;
     JLabel users;
     JTextArea roomConversation;
     static JList roomUserList;
     JScrollPane conversationScroll;
     JScrollPane userListScroll;
     JTextField roomMessage;
     JButton roomMessageButton;
     static DefaultListModel userListModel;
     ListSelectionListener userListListener;
     public ChatFrame(final String roomName)
          super("Chat Room : " + roomName,
                    true, //resizable
                    true, //closable
                    true, //maximizable
                    true);//iconifiable
          openFrameCount++;
          chatRoomContent = new JPanel();
          chatRoomContent.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
          chatRoomContent.setLayout(new GridBagLayout());
          GridBagConstraints c = new GridBagConstraints();
          c.fill = GridBagConstraints.BOTH;
// I set proper values for c everytime I add new item to pane
          chatRoom = new JLabel("Now chatting in : " + roomName);
          chatRoomContent.add(chatRoom,c);
          users = new JLabel("User List");
          chatRoomContent.add(users,c);
          roomConversation = new JTextArea();
          roomConversation.setEditable(false);
          conversationScroll = new JScrollPane();
          conversationScroll.setViewportView(roomConversation);
          chatRoomContent.add(conversationScroll,c);
          userListModel = new DefaultListModel();
          userListListener = new ListSelectionListener(){
               public void valueChanged(ListSelectionEvent event) {
                    JList lsm = (JList) event.getSource();
                    if(event.getValueIsAdjusting())
                         roomConversation.append("Starting chat with " + lsm.getSelectedValue() + "\n");
                         String chatName = (String) lsm.getSelectedValue();
                         ChatClientMain.createPrivateChatFrame(chatName);
          roomUserList = new JList();
//list props set here
          chatRoomContent.add(userListScroll,c);
          roomMessage = new JTextField();
          chatRoomContent.add(roomMessage,c);
          roomMessageButton = new JButton("Send Message");
          roomMessageButton.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent event) {
                    if (!roomMessage.getText().equals(""))
                         String message = ChatClientMain.nickName + " : " + roomMessage.getText() + "\n"; // message person wrote
                         roomConversation.append(message);
                         roomMessage.setText("");
                         ChatClientMain.outToServer.println("CHATROOM#"+roomName+"#"+message);  // message I'm sending to server
          chatRoomContent.add(roomMessageButton,c);
          this.setFocusable(true);
          this.addKeyListener(new KeyListener() {
               @Override
               public void keyPressed(KeyEvent arg0) {
                    int keyNo = arg0.getKeyCode();
                    if ( keyNo == KeyEvent.VK_F5)
                         ChatClientMain.outToServer.println("GET USER LIST"+roomName);       //refresh part with works just for the last internal frame I opened
               //other methods
          this.addInternalFrameListener(new InternalFrameListener() {
               public void internalFrameClosed(InternalFrameEvent arg0) {
                    ChatClientMain.leaveRoom(roomName);
                        //other methods here
          add(chatRoomContent);
          setSize(525,525);
          setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
}I would really be thankful if you help..

Similar Messages

  • More than one OPENING in FLOW_TYPE in the S Dimension

    Dear BPC Experts:
            I am using BPC 7.5 NW SP09 now, and need to create more than one Opening flow members.
    Can I give FLOW_TYPE OPENING to each opening flow member? Does such config affect the default caculation
    behind system? Like currency conversion or carry-forward business rules? Does anyone have similiar experience?
    Or I just don't have set OPENING FLOW_TYPE to those many opening flows?
    BRs,
    Fred Cheng

    Hi,
    Let me try to explain this.
    Lets say you have 2 accounts - ACC1 and ACC2.
    If you want to have opening flow for each of the accounts in the account dimension, itself, then you will have soemthing like
    ACC1
       ACC1OPE
    ACC2
       ACC2OPE
    So, you see, the number of members can increase tremendously.
    To overcome this problem, we use the subtable type of dimension. In this dimension, you will have only one member for opening flow - OPE
    No, the if you look at the data region ACC1 and OPE, it will show you the opening value of ACC1,
    Similarly, if you look at the region ACC2 and OPE, it will show you the opening value of ACC2.
    Hope you got the idea, now.

  • Cannot work on more than one page and menu shifting problems

    I downloaded Muse CC 2014 when it first came out, and now I find myself no longer able to edit more than one page without having to completely shut down the application and start it again. Here's what happens:
    I open a page to edit, and then anything else I try to double click on (or right click and choose open page) does absolutely nothing. Any ideas why this is occurring?
    Also, I've noticed a strange phenomenon where my menu has completely shifted its menu contents - pushing everything down. Nothing I did - wondering why this is happening. This has pretty much rendered Muse unusable to me and I am becoming more and more frustrated since I'm paying good money for this....please help.
    Here's a screenshot of the messed up menu (all text should be located in between the green dots and not so spread out):
    Also, if I try to create a border around a text box with just the bottom border showing (i.e. the other 3 sides are set to 0), that bottom border also shifts down as if the text container has suddenly expanded.
    This happens with both my Macbook Air and my MacPro.
    Thanks in advance for any help. I'm kind of at my wit's end....I really need to be able to update my website as this is the face of my business.
    -Kristine

    You could look at using a template.  Create your master template, create editable and non-editable regions, then use this template create all the child pages.  When you need to make a change to the menu, make it in the template and the changes will flow down to all the pages created from the template.
    Using DW Templates:
    http://www.adobe.com/devnet/dreamweaver/templates.html
    http://www.adobe.com/devnet/dreamweaver/articles/dw_templates.html
    The other option would be to create the Navigation item as a server side include...
    More about this:
    http://kb2.adobe.com/cps/143/tn_14380.html
    http://www.entheosweb.com/website_design/server_side_includes.asp
    Difference between using a template and server side includes.
    When you make a change to a template, you need to re-upload all the pages created from the template.
    Using a SSI, you make the change in the ssi file,  upload it and all pages are automatically updated.
    Nadia
    Adobe® Community Expert : Dreamweaver
    http://www.perrelink.com.au
    Unique CSS Templates |Tutorials |SEO Articles
    http://www.DreamweaverResources.com
    http://csstemplates.com.au/
    http://twitter.com/nadiap

  • Working with more than one ALV on Screen

    Hi,
    I have got two alv's in same application/report. One ALV is for displaying the data and another ALV is for interaction or with EVENT Handling, but when iam defining the class with methods for event handling for CL_GUI_ALV_GRID, it is showing me an error message as there are more than one ALV with reference to CL_GUI_ALV_GRID. It seems it wants only UNICODE Object for CL_GUI_ALV_GRID.
    Please assit, how to manage with event handling when there are more than one ALVs on screen. How to go for class definition and implementation

    If you are dealing with two ALV, you should have created two different objects referring to CL_GUI_ALV_GRID.
    If you have done and still getting a error, please post the code that is erroring here.
    Regards,
    Ravi
    Note - Please mark all the helpful answers

  • I want to view web sites in more than one open window instead of tabs. How do I change the settings to do that?

    I want to have more than one window open with firefox at the same time instead of having multiple web sites up using tabs. but every time I try to do this a tab opens instead. I am using windows 7.

    You can copy a bookmark from one folder and paste it in another folder to have a copy in more than one folder.

  • E3200 - USB port does NOT work for more than one device

    We needed a new router that had the dual band connectivity as our previous router stopped working properly when we started using a baby monitor operating on the same 2.4 GHz. The choice was between E3200 and E2500. We chose the E3200 mainly because it also offered a USB port. We were hoping to use that to connect our printer and two external drives (thus bypassing our old desktop that's been working as a server). However, it turns out that the USB port on E3200 does NOT support USB hubs! So, you can ONLY use ONE device - either a printer or one external storage drive. That wasn't really clear at all from the description. I feel like we wasted the extra $50 hoping to get functionality that just isn't there. Can't believe that in this day and age, Cisco thinks we all have only ONE USB device we might want to connect to the network! The router itself is fast enough, but the extra $50 for a USB port that doesn't do much and some speedboost phantom ability is just not worth it. 

    Just to save time to you all, after numerous attempts to install a USB hub to my E3200,
    I wrote to Cisco Customer Service (live chat) and I specifically requested how to set up the usb hub or the virtual USB port and they said that they do not have a software to install a USB hub.
    Hope this help
    Massimo
    (Mod note: Edited for guideline compliance.)

  • Tcode MASS does not work if more than one item in contract

    Hi,
    I need to update the contract zone of a PO. Via tcode ME22N, this zone is disabled, so i cannot fill my contract in the PO using this tcode.
    I tried tcode MASS which works only if the contract has only one item.
    Can anyone help please?
    Thanks in advance

    HI Anu,
    Good to KNow that you are able to do it by Mass
    In Mass for Multiple Line Item to update to Multiple line item PO
    Just go to MASS
    Select the option BUS2012 (Purchase orders)
    and in the select the poline item EKPO
    And enter the PO Number along with the Item Number in the entry screen and execute it .
    But for the Contract also enter the option
    Outline Agreement -- for the contract number
    Principal Agmt Item-- for the contract item number
    Enter the above against the PO and its item number combination it works.
    As suggested earlier please check the Screen layout option also.which would be more easy way,
    Check the PO Screen layout-Field settings. at the Document type level  mainatained in the config.
    against the
    Hope so this would help.
    Regards
    Anjanna

  • Networked L7680 does not work from more than one computer at a time.

    Have installed latest driver software on both computers. Printer will only work with one computer on at a time. When I run windows device trouble shooter from the last computer turned on it says printer is off. It works ok from the first computer turned on.
    Any help is appreciated.

    Networked how??  Please explain how everything is connected and model number of equipment.
    Say thanks by clicking the Kudos Thumbs Up to the right in the post.
    If my post resolved your problem, please mark it as an Accepted Solution ...
    I worked for HP but now I'm retired!

  • How does nat selectoin work when more than one nat command?

    My router's configuration contains two ip nat inside source commands with route maps. One command is a static translation and one is a dynamic. Is this the way processing works:
    The inside packet source address is processed against one of the command's route map (which command?). If that route map permits the address, then the source address is natted.
    However, if the first route map denies the address, then the router continues on to the second ip nat inside source command and processes the address against its route list.
    Right?

    Hi
    Basically yes, the router will compare the packet against all route-maps until it finds a match (if any) and then apply the NAT.
    If you think about it logically it shouldn't matter which order it applies them because if you are statically mapping one address to another you would ensure that this address is never matched in your dynamic NAT setup otherwise you could get very unpredictable results.
    HTH
    Jon

  • Language Settings - Working with more than one language

    Dreamweaver Developer Toolbox, in the Control Panel, have a tab to set the site Language, for bugs, errors, form verification, etc.
    I´m working in a website with two languages, Spanish and English: How can I show messages in the corresponding language?

    I get this error:
    Cannot redeclare kt_getresource() (previously declared in ....includes\common\lib\resources\KT_ResourcesFunctions_Eng.inc.php:24) in ...includes\common\lib\resources\KT_ResourcesFunctions.inc.php on line 24
    Previously, i do this changes:
    I edit this file tNG.inc_Eng.php, that now calls '../common/lib/resources/KT_Resources_Eng.php' ( duplicate KT_Resources.php)
    In KT_Resources_Eng.php , edit this line:  array('KT_ResourcesFunctions_Eng.inc.php', '../../KT_common.php');
    In 'KT_ResourcesFunctions_Eng.inc.php edit this line: $dictionaryFileName = KT_realpath(dirname(realpath(__FILE__)). '/../../../resourcesEn/'). '%s.res.php';
    But, i realized the other files are inter-connected, one example: in TNG.inc_Eng.php, calls '../common/lib/folder/KT_Folder.php', and this KT_Folder.php calls '../resources/KT_Resources.php');, an get conflict with my previous loaded KT_Resources_Eng.php , a great mess.
    I guess y should follow each link and check every page loaded, duplicate, etc.
    I think Í´ll use de session variable. jajaja. I´ve a page included in all english sections, loginEng.php, i´ll create there the session variable for the english version, and exacly the same in the loginEsp.php page, that is included on every page in the spanish version.
    What do you think?
    Thank you very much Gunter!

  • Working with more than one spreadsheet

    I use Numbers a lot but it's occurred to me that I've not yet tried working with numerous spreadsheets.
    Can Numbers grab information from a separate spreadsheet or does everything have to be worksheets within a single spreadsheet?

    Darryn,
    One Numbers Docment (Filename) can not communicate with another Numbers Document. Multiple Sheets within one Document may reference each other. So, if you wish, you can embed your spreadsheets on separate Sheets within the same Document and have them link to each other.
    Jerry

  • Will hp2543 work with more than one wifi connection it works at office but not at home

    New printer  set up to work with wifi at office but it doesn't work at home. Will it work at 2 or more locations and if so how do you set it up

    Hi,
    Yes BUT each location you have to set it up like a new printer and you have to switch forward backward on every move.
    Regards.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • Simply FRUSTRATED. How to work on more than one site at a time

    I have three sites in edit mode in iWeb. But I can't seem to publish one at a time. It publishes the three different sites as one! H E L P ! !
    I also don't know how to save them without publishing, since it seems clear that once I remove them from the editing field on the left, they are no longer openable in iWeb.
    Thanks. I hope I just don't know which button to hit...

    bradhaan:
    I use iWebSites to manage multiple sites.. It lets me create multiple sites and multiple domain files.
    If you have multiple sites in one domain file here's the workflow I used to split them into individual site files with iWebSites. Be sure to make a backup copy of your original Domain.sites files before starting the splitting process.
    This lets me edit several sites and only republish the one I want.
    OT

  • Error when working with more than one recordstore

    Hi all,
    I use Sun Java ME Toolkit SDK 3.
    When I insert a new record into a second recordstore then I get an error. How to correct it ?
    Thank you very much

    If you are dealing with two ALV, you should have created two different objects referring to CL_GUI_ALV_GRID.
    If you have done and still getting a error, please post the code that is erroring here.
    Regards,
    Ravi
    Note - Please mark all the helpful answers

  • How do I reopen or reset the option that allows me to view more than one open email account at a time?

    In the past, I could open one email address, then jump to another email address, while not having to log in and out? I must have changes something? Once logged in to one email address, the other email addresses would rise up in the lower right corner to notify me I received a new email?
    How do I turn that back on?

    In Firefox all browser windows and tabs use the same cookies that will identify you to the server.
    You can look this extension if you want to sign on with different identities at the same time:
    * Multifox: http://br.mozdev.org/multifox/

Maybe you are looking for