⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 instantmessaginggui.java

📁 基于JAINSIP的一个proxy源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    }    /*******************************************************************************/    /*******************************************************************************/            /** Creates new IMGUI */    public InstantMessagingGUI(String confFile) throws Exception{        super("NIST-SIP Instant Messaging");               listenerInstantMessaging=new ListenerInstantMessaging(this);        instantMessagingUserAgent=new IMUserAgent(this);               // listenerInstantMessaging.startRMIregistry();                propertiesFile=confFile;        DebugIM.println("\n***************** STARTING ******************************\n");        uploadProperties(propertiesFile);        initComponents();        initFields();        uploadBuddies();        uploadAuthentication();        start();        DebugIM.println("\n*************************************************\n");        show();    }            /** This method is called from within the constructor to     * initialize the form.     */    public void initComponents() {        /***************** The main frame ***************************************/        // width, height        this.setSize(360,400);        Container container=this.getContentPane();        container.setLayout(new BorderLayout());        container.setBackground(containerBackGroundColor);        this.setLocation(0,0);        this.addWindowListener(new WindowAdapter() {            public void windowClosing(WindowEvent e) {              clean();            }        });                /********************** Menu bar **************************************/        menuBar=new JMenuBar();        setJMenuBar(menuBar);        // create a menu and add it to the menubar        menuMenu=new JMenu("  Menu  ");        menuMenu.setBorder(new BevelBorder(BevelBorder.RAISED));        menuMenu.setToolTipText("Available features!!!");        configurationMenuItem=new JMenuItem("Configuration");        configurationMenuItem.setToolTipText("Edit the properties");        configurationMenuItem.addActionListener(new ActionListener() {          public void actionPerformed(ActionEvent evt) {                 listenerInstantMessaging.configurationActionPerformed(evt);              }          }        );        menuMenu.add(configurationMenuItem);                sendIMMenuItem=new JMenuItem("Send an IM ");        sendIMMenuItem.setToolTipText("Send an instant message");        sendIMMenuItem.addActionListener(new ActionListener() {              public void actionPerformed(ActionEvent evt) {                 listenerInstantMessaging.sendIMActionPerformed(evt);              }          }        );               addContactMenuItem=new JMenuItem("Add contact");        addContactMenuItem.setToolTipText("Add a contact to the buddy list");        addContactMenuItem.addActionListener(new ActionListener() {              public void actionPerformed(ActionEvent evt) {                 listenerInstantMessaging.addContactActionPerformed(evt);              }          }        );                removeContactMenuItem=new JMenuItem("Remove a contact");        removeContactMenuItem.setToolTipText("Remove a contact from the buddy list");        removeContactMenuItem.addActionListener(new ActionListener() {              public void actionPerformed(ActionEvent evt) {                 listenerInstantMessaging.removeContactActionPerformed(evt);              }          }        );                tracesViewerMenuItem=new JMenuItem("Traces viewer");        tracesViewerMenuItem.setToolTipText("Visualize the traces");        tracesViewerMenuItem.addActionListener(new ActionListener() {              public void actionPerformed(ActionEvent evt) {                 listenerInstantMessaging.tracesViewerActionPerformed(evt);              }          }        );                menuMenu.add(sendIMMenuItem);        menuMenu.add(addContactMenuItem);        menuMenu.add(removeContactMenuItem);        menuMenu.add(tracesViewerMenuItem);                statusMenu=new JMenu("  Status ");       // statusMenu.setBorder(new BevelBorder(BevelBorder.RAISED));        statusMenu.setToolTipText("your status!!!");                onlineJRadioButtonMenuItem=new JRadioButtonMenuItem(" Online ");        onlineJRadioButtonMenuItem.setToolTipText("Set your status to online");        onlineJRadioButtonMenuItem.addActionListener(new ActionListener() {              public void actionPerformed(ActionEvent evt) {                 listenerInstantMessaging.onlineActionPerformed(evt);              }          }        );                awayJRadioButtonMenuItem=new JRadioButtonMenuItem(" Away ");        awayJRadioButtonMenuItem.setToolTipText("Set your status to away");        awayJRadioButtonMenuItem.addActionListener(new ActionListener() {              public void actionPerformed(ActionEvent evt) {                 listenerInstantMessaging.awayActionPerformed(evt);              }          }        );                offlineJRadioButtonMenuItem=new JRadioButtonMenuItem(" Offline ");        offlineJRadioButtonMenuItem.setToolTipText("Set your status to offline");        offlineJRadioButtonMenuItem.addActionListener(new ActionListener() {              public void actionPerformed(ActionEvent evt) {                 listenerInstantMessaging.offlineActionPerformed(evt);              }          }        );                busyJRadioButtonMenuItem=new JRadioButtonMenuItem(" busy ");        busyJRadioButtonMenuItem.setToolTipText("Set your status to busy");        busyJRadioButtonMenuItem.addActionListener(new ActionListener() {              public void actionPerformed(ActionEvent evt) {                 listenerInstantMessaging.busyActionPerformed(evt);              }          }        );                ButtonGroup group = new ButtonGroup();        offlineJRadioButtonMenuItem.setSelected(true);        group.add(onlineJRadioButtonMenuItem);        group.add(offlineJRadioButtonMenuItem);        group.add(busyJRadioButtonMenuItem);        group.add(awayJRadioButtonMenuItem);                statusMenu.add(awayJRadioButtonMenuItem);        statusMenu.add(onlineJRadioButtonMenuItem);        statusMenu.add(offlineJRadioButtonMenuItem);        statusMenu.add(busyJRadioButtonMenuItem);        menuMenu.add(statusMenu);                // add the menu to the menu bar        menuBar.add(menuMenu);                signMenu=new JMenu("  Sign in  ");        signMenu.setBorder(new BevelBorder(BevelBorder.RAISED));        signMenu.setToolTipText("Sign in to the server");        signMenu.addMouseListener( new MouseAdapter() {            public void mouseClicked(MouseEvent evt){                  listenerInstantMessaging.signMenuMouseClicked(evt);              }          }        );        menuBar.add(signMenu);               //...create and add some menus...        menuBar.add(Box.createHorizontalGlue());                helpMenu=new JMenu("  Help  ");        helpMenu.setBorder(new BevelBorder(BevelBorder.RAISED));        helpMenu.setToolTipText("Some useful notes about this tool");        helpMenu.addMouseListener( new MouseAdapter() {            public void mouseClicked(MouseEvent evt){                   listenerInstantMessaging.helpMenuMouseEvent(evt);              }          }        );        menuBar.add(helpMenu);                  quit=new JMenu("  Quit  ");        quit.setBorder(new BevelBorder(BevelBorder.RAISED));        quit.setToolTipText("Quit the application");        quit.addMouseListener( new MouseAdapter() {            public void mouseClicked(MouseEvent evt){              clean();            }        }        );        menuBar.add(quit);                                            /****************** The components    **********************************/        firstPanel=new JPanel();        //Top,,bottom,        //firstPanel.setBorder(BorderFactory.createEmptyBorder(0,10,10,10));        // If put to False: we see the container's background        firstPanel.setOpaque(false);        //rows, columns, horizontalGap, verticalGap        firstPanel.setLayout( new GridLayout(3,1,0,0) );        JPanel subPanel1=new JPanel();        //Top,,bottom,        subPanel1.setBorder(BorderFactory.createEmptyBorder(20,10,7,10));        // If put to False: we see the container's background        subPanel1.setOpaque(false);        //rows, columns, horizontalGap, verticalGap        subPanel1.setLayout( new GridLayout(1,1,5,10) );                JPanel subPanel2=new JPanel();        //Top,,bottom,        subPanel2.setBorder(BorderFactory.createEmptyBorder(4,10,15,10));        // If put to False: we see the container's background        subPanel2.setOpaque(false);        //rows, columns, horizontalGap, verticalGap        subPanel2.setLayout( new GridLayout(1,2,5,10) );                statusLabel=new JLabel(" You are: OFFLINE");        statusLabel.setToolTipText("your status");        // Alignment of the text        statusLabel.setHorizontalAlignment(AbstractButton.CENTER);        // Color of the text        statusLabel.setForeground(Color.black);        // Size of the text        statusLabel.setFont(new Font ("Dialog", 1, 14));        // If put to true: we see the label's background        statusLabel.setOpaque(true);        statusLabel.setBackground(labelBackGroundColor);        statusLabel.setBorder(labelBorder);        subPanel1.add(statusLabel);               firstPanel.add(subPanel1);        firstPanel.add(subPanel2);        localSipURLLabel=new JLabel("Contact SIP URL:");        localSipURLLabel.setToolTipText("Your identifier");        // Alignment of the text        localSipURLLabel.setHorizontalAlignment(AbstractButton.CENTER);        // Color of the text        localSipURLLabel.setForeground(Color.black);        // Size of the text        localSipURLLabel.setFont(new Font ("Dialog", 1, 14));        // If put to true: we see the label's background        localSipURLLabel.setOpaque(true);        localSipURLLabel.setBackground(labelBackGroundColor);        localSipURLLabel.setBorder(labelBorder);        localSipURLTextField = new JTextField(20);        localSipURLTextField.setHorizontalAlignment(JTextField.LEFT);        localSipURLTextField.setFont(new Font ("Dialog", 1, 14));        localSipURLTextField.setBackground(textBackGroundColor);        localSipURLTextField.setForeground(Color.black);        localSipURLTextField.setText("sip:");        localSipURLTextField.setSelectionStart(4);        localSipURLTextField.setBorder(BorderFactory.createLoweredBevelBorder() );        subPanel2.add(localSipURLLabel);        subPanel2.add(localSipURLTextField);               // The buddy list:        JPanel subPanel3=new JPanel();        //Top,,bottom,        subPanel3.setBorder(BorderFactory.createEmptyBorder(30,10,0,10));        // If put to False: we see the container's background        subPanel3.setOpaque(false);        //rows, columns, horizontalGap, verticalGap        subPanel3.setLayout( new GridLayout(1,1,5,10) );        firstPanel.add(subPanel3);                buddyLabel=new JLabel("Buddy list:");        buddyLabel.setToolTipText("Double click on the contact to send an IM");        // Alignment of the text        buddyLabel.setHorizontalAlignment(AbstractButton.CENTER);        // Color of the text        buddyLabel.setForeground(Color.black);        // Size of the text        buddyLabel.setFont(new Font ("Dialog", 1, 14));        // If put to true: we see the label's background        buddyLabel.setOpaque(true);        buddyLabel.setBackground(labelBackGroundColor);        buddyLabel.setBorder(labelBorder);        subPanel3.add(buddyLabel);                JPanel subPanel4=new JPanel();        //Top,,bottom,        subPanel4.setBorder(BorderFactory.createEmptyBorder(0,10,10,10));        // If put to False: we see the container's background        subPanel4.setOpaque(false);        //rows, columns, horizontalGap, verticalGap        subPanel4.setLayout( new GridLayout(1,1,5,10) );        buddyList=new BuddyList(this);        buddyList.setToolTipText("Double click on the contact to send an IM");        MouseListener mouseListener = new MouseAdapter() {        public void mouseClicked(MouseEvent e) {            listenerInstantMessaging.buddyListMouseClicked(e);        }        };        buddyList.addMouseListener(mouseListener);                JScrollPane scrollPane = new JScrollPane(buddyList,        JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,        JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);        subPanel4.add(scrollPane);                // The logo        JPanel imagesPanel=new JPanel();        imagesPanel.setOpaque(false);        // top, left, bottom, right        imagesPanel.setBorder(BorderFactory.createEmptyBorder(5,5,0,0));        container.add(imagesPanel);        imagesPanel.setLayout( new FlowLayout(FlowLayout.CENTER,0,0) );                ImageIcon icon;        icon = new ImageIcon("./images/"+logo);        JLabel label=new JLabel(icon);        label.setVisible(true);        label.setToolTipText("The NIST logo!!!");        label.setHorizontalAlignment(AbstractButton.CENTER);        label.setForeground(Color.black);        label.setFont(new Font ("Dialog", 1, 14));        label.setOpaque(true);        label.setBackground(Color.lightGray);        imagesPanel.add(label);                        container.add("North",firstPanel);        container.add("Center",subPanel4);        container.add("South",imagesPanel);                    }            public void clean() {        try {            instantMessagingUserAgent.stop();            buddyList.writeToXMLFile();                        if (listenerInstantMessaging.rmiregistryProcess!=null) {                 listenerInstantMessaging.rmiregistryProcess.destroy();                 DebugIM.println("DebugIM, rmiregistry process destroyed.");            }               }        catch(Exception e) {            e.printStackTrace();        }                System.exit(0);    }        public static void main(String args[]) {       try{                      String confFile= (String) args[1];           InstantMessagingGUI imGUI=new InstantMessagingGUI(confFile);                }       catch(Exception e){            System.out.println            ("ERROR: Set the configuration file flag: " +            "USE: -cf configuration_file_location"  );            System.out.println("ERROR, the IM client can not be started, " +            " exception raised:\n");            e.printStackTrace();       }   }        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -