public void onWho(ActionEvent actionEvent) { StandardDialog dlg = new StandardDialog(); dlg.setTitle("Your name and address"); String strName = prefs.get(NAME, server.ip + ":" + server.port); JTextField name = new JTextField(strName), ip = new JTextField(server.ip), port = new JTextField(server.port + ""); ip.setEditable(false); port.setEditable(false); LabelledItemPanel myContentPane = new LabelledItemPanel(); myContentPane.setBorder(BorderFactory.createEtchedBorder()); myContentPane.addItem("Your name", name); myContentPane.addItem("", new JLabel("Tell your buddy the follows:")); myContentPane.addItem("Your IP", ip); myContentPane.addItem("Your port", port); dlg.setContentPane(myContentPane); dlg.setSize(300, 300); GUIUtils.centerWithinScreen(dlg); dlg.setVisible(true); if (!dlg.hasUserCancelled()) { prefs.put(NAME, name.getText()); server.myName = name.getText(); } }
private void jbInit() throws Exception { messageMap(); getContentPane().setLayout(borderLayout1); btnWho.setText("@"); btnWho.setToolTipText("Who am I? Set your id and get your address"); this.getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER); jScrollPane1.getViewport().add(buddyList); btnAdd.setText("+"); btnAdd.setToolTipText("Add Buddy"); btnAbout.setText("?"); btnAbout.setToolTipText("About"); this.getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH); buddyList.setBackground(new Color(184, 199, 153)); jPanel1.add(btnWho); jPanel1.add(btnAdd); jPanel1.add(btnAbout); server.addMessageListener(this); buddyList.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent evt) { JList list = (JList) evt.getSource(); if (evt.getClickCount() == 2) // Double-click { // Get item index int index = list.locationToIndex(evt.getPoint()); Buddy buddy = (Buddy) list.getModel().getElementAt(index); startTalk(buddy); } } }); int delay = 60 * 1000; // milliseconds ActionListener taskPerformer = new ActionListener() { public void actionPerformed(ActionEvent evt) { onTimer(evt); } }; new Timer(delay, taskPerformer).start(); if (prefs.get(NAME, null) == null) { String inputValue = null; // ask for nickname while (inputValue == null || inputValue.trim().length() == 0) { inputValue = JOptionPane.showInputDialog("Please choose your nickname"); } server.myName = inputValue; prefs.put(NAME, inputValue); } // hide the frame if iconized final JFrame thisFrame = this; WindowStateListener listener = new WindowAdapter() { public void windowStateChanged(WindowEvent evt) { int oldState = evt.getOldState(); int newState = evt.getNewState(); if ((oldState & Frame.ICONIFIED) == 0 && (newState & Frame.ICONIFIED) != 0) { // Frame was iconized thisFrame.setVisible(false); } } }; // Register the listener with the frame addWindowStateListener(listener); }