/** Listener to handle button actions */ public void actionPerformed(ActionEvent e) { // Check if the user changed the service filter option if (e.getSource() == service_box) { service_list.setEnabled(service_box.isSelected()); service_list.clearSelection(); remove_service_button.setEnabled(false); add_service_field.setEnabled(service_box.isSelected()); add_service_field.setText(""); add_service_button.setEnabled(false); } // Check if the user pressed the add service button if ((e.getSource() == add_service_button) || (e.getSource() == add_service_field)) { String text = add_service_field.getText(); if ((text != null) && (text.length() > 0)) { service_data.addElement(text); service_list.setListData(service_data); } add_service_field.setText(""); add_service_field.requestFocus(); } // Check if the user pressed the remove service button if (e.getSource() == remove_service_button) { Object[] sels = service_list.getSelectedValues(); for (int i = 0; i < sels.length; i++) { service_data.removeElement(sels[i]); } service_list.setListData(service_data); service_list.clearSelection(); } }
public void actionPerformed(ActionEvent event) { if (event.getSource() == joinButton) { if (joinButton.isSelected()) { mThread = new MulticastThread( Integer.valueOf(portField.getText()), chatIPField.getText(), chatroomArea, true); (new Thread(mThread)).start(); } } if (event.getSource() == sendButton) { mThread.send(usernameField.getText(), chatMsgField.getText()); chatMsgField.setText(""); } if (event.getSource() == leaveButton) { try { joinButton.setSelected(false); mThread.leave(); System.out.println("Disconnected from chat "); } catch (Exception e) { } } if (event.getSource() == exitButton) { System.exit(0); } }
private JPanel initServerChoice() { JPanel p = new JPanel(); p.setLayout(new GridLayout(6, 1, 5, 2)); p.add(new JLabel("Search At: ")); chosenServer.setText(server.getHost().getHostName()); p.add(chosenServer); chosenServer.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { try { InetAddress newHost = InetAddress.getByName(chosenServer.getText()); Whois newServer = new Whois(newHost); server = newServer; } catch (Exception e) { // should use an error dialog here, but that // doesn't teach much about networking chosenServer.setText(server.getHost().getHostName()); } } }); return p; }
public void save() { for (String key : fields.keySet()) { JComponent comp = fields.get(key); if (comp instanceof JTextField) { JTextField c = (JTextField) comp; if (c.getText().trim().equals("")) { sketch.configFile.unset(key); } else { sketch.configFile.set(key, c.getText()); } } else if (comp instanceof JTextArea) { JTextArea c = (JTextArea) comp; if (c.getText().trim().equals("")) { sketch.configFile.unset(key); } else { sketch.configFile.set(key, c.getText()); } } } sketch.saveConfig(); }
// ボタンが押されたときのイベント処理 public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); if (cmd.equals("submit")) { // 送信 sendMessage("msg " + msgTextField.getText()); msgTextField.setText(""); } else if (cmd.equals("rename")) { // 名前の変更 sendMessage("setName " + nameTextField.getText()); } else if (cmd.equals("addRoom")) { // 部屋を作成 String roomName = nameTextField.getText(); sendMessage("addRoom " + roomName); enteredRoom(roomName); sendMessage("getUsers " + roomName); } else if (cmd.equals("enterRoom")) { // 入室 Object room = roomList.getSelectedValue(); if (room != null) { String roomName = room.toString(); sendMessage("enterRoom " + roomName); enteredRoom(roomName); } } else if (cmd.equals("exitRoom")) { // 退室 sendMessage("exitRoom " + roomName); exitedRoom(); } }
// Initialize all the GUI components and display the frame private static void initGUI() { // Set up the status bar statusField = new JLabel(); statusField.setText(statusMessages[DISCONNECTED]); statusColor = new JTextField(1); statusColor.setBackground(Color.red); statusColor.setEditable(false); statusBar = new JPanel(new BorderLayout()); statusBar.add(statusColor, BorderLayout.WEST); statusBar.add(statusField, BorderLayout.CENTER); // Set up the options pane JPanel optionsPane = initOptionsPane(); // Set up the chat pane JPanel chatPane = new JPanel(new BorderLayout()); chatText = new JTextArea(10, 20); chatText.setLineWrap(true); chatText.setEditable(false); chatText.setForeground(Color.blue); JScrollPane chatTextPane = new JScrollPane( chatText, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); chatLine = new JTextField(); chatLine.setEnabled(false); chatLine.addActionListener( new ActionAdapter() { public void actionPerformed(ActionEvent e) { String s = chatLine.getText(); if (!s.equals("")) { appendToChatBox("OUTGOING: " + s + "\n"); chatLine.selectAll(); // Send the string sendString(s); } } }); chatPane.add(chatLine, BorderLayout.SOUTH); chatPane.add(chatTextPane, BorderLayout.CENTER); chatPane.setPreferredSize(new Dimension(200, 200)); // Set up the main pane JPanel mainPane = new JPanel(new BorderLayout()); mainPane.add(statusBar, BorderLayout.SOUTH); mainPane.add(optionsPane, BorderLayout.WEST); mainPane.add(chatPane, BorderLayout.CENTER); // Set up the main frame mainFrame = new JFrame("Simple TCP Chat"); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainFrame.setContentPane(mainPane); mainFrame.setSize(mainFrame.getPreferredSize()); mainFrame.setLocation(200, 200); mainFrame.pack(); mainFrame.setVisible(true); }
public void enableChat() { openChat.setEnabled(false); chatWith.setEnabled(false); pickText.setEnabled(false); desText.setEnabled(false); send.setEnabled(true); chatText.setEnabled(true); new Thread(this).start(); }
/** Clears all the data previously entered in the form. */ public void clear() { usernameField.setText(""); displayNameField.setText(""); passField.setText(""); retypePassField.setText(""); emailField.setText(""); errorPane.setText(""); remove(errorPane); }
private void actionAdd() { URL verifiedUrl = verifyUrl(addTextField.getText()); if (verifiedUrl != null) { tableModel.addDownload(new DownloadFile(verifiedUrl)); addTextField.setText(""); } else { JOptionPane.showMessageDialog( this, "Invalid Download URL", "Error", JOptionPane.ERROR_MESSAGE); } }
void addTextField(JPanel panel, String key, String label) { JLabel lab = new JLabel(label); lab.setAlignmentX(LEFT_ALIGNMENT); panel.add(lab); JTextField field = new JTextField(); field.setText(sketch.configFile.get(key)); field.setMaximumSize(new Dimension(Integer.MAX_VALUE, field.getPreferredSize().height)); fields.put(key, field); panel.add(field); }
/** * Méthode de création du panelInit * * @return */ private JPanel createPanelInit() { JPanel panRight = new JPanel(); panRight.setLayout(new BoxLayout(panRight, BoxLayout.Y_AXIS)); butListParty = new JButton("Liste des parties"); butListParty.addActionListener(this); JPanel panCreate = new JPanel(); panCreate.setLayout(new BoxLayout(panCreate, BoxLayout.X_AXIS)); textCreate = new JTextField("", 40); textCreate.setMaximumSize(textCreate.getPreferredSize()); butCreateParty = new JButton("Creation de parties "); butCreateParty.addActionListener(this); SpinnerModel model = new SpinnerNumberModel(3, 2, 8, 1); spinNbPlayer = new JSpinner(model); spinNbPlayer.setMaximumSize(spinNbPlayer.getPreferredSize()); panCreate.add(new JLabel("Nouveau nom de partie : ")); panCreate.add(textCreate); panCreate.add(Box.createHorizontalStrut(20)); panCreate.add(new JLabel("Nombres de joueurs : ")); panCreate.add(spinNbPlayer); panCreate.add(butCreateParty); JPanel panJoin = new JPanel(); panJoin.setLayout(new BoxLayout(panJoin, BoxLayout.X_AXIS)); textJoin = new JTextField("", 2); textJoin.setMaximumSize(textJoin.getPreferredSize()); butJoinParty = new JButton("Rejoindre la partie "); butJoinParty.addActionListener(this); panJoin.add(new JLabel("Num Partie : ")); panJoin.add(textJoin); panJoin.add(butJoinParty); panRight.add(butListParty); panRight.add(panCreate); panRight.add(panJoin); panRight.add(Box.createVerticalGlue()); textInfoInit = new JTextArea(20, 100); textInfoInit.setLineWrap(true); JScrollPane scroll = new JScrollPane( textInfoInit, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); JPanel panAll = new JPanel(); panAll.setLayout(new BoxLayout(panAll, BoxLayout.X_AXIS)); panAll.add(scroll); panAll.add(panRight); return panAll; }
private void jbInit() throws Exception { this.getContentPane().setLayout(null); Bienvenue.setFont(new java.awt.Font("Garamond", 1, 24)); Bienvenue.setForeground(SystemColor.textHighlight); Bienvenue.setRequestFocusEnabled(true); Bienvenue.setVerifyInputWhenFocusTarget(true); Bienvenue.setText("Bienvenue dans JChat"); Bienvenue.setBounds(new Rectangle(125, 28, 305, 44)); Pseudo_L.setFont(new java.awt.Font("Dialog", 1, 14)); Pseudo_L.setText("Pseudonyme :"); Pseudo_L.setBounds(new Rectangle(75, 94, 128, 28)); nom.setText(""); nom.setBounds(new Rectangle(229, 95, 108, 24)); pwd.setText(""); pwd.setBounds(new Rectangle(230, 135, 108, 25)); pwd_L.setFont(new java.awt.Font("Dialog", 1, 14)); pwd_L.setText("Mot de passe :"); pwd_L.setBounds(new Rectangle(76, 133, 122, 31)); gestionnaire_B gestionnaire = new gestionnaire_B(); Connect.addActionListener(gestionnaire); Connect.setBackground(new Color(239, 240, 234)); Connect.setBounds(new Rectangle(281, 251, 142, 30)); Connect.setText("Connexion"); Connect.setIcon(new ImageIcon(image_c)); Annuler.addActionListener(gestionnaire); Annuler.setBackground(new Color(239, 240, 234)); Annuler.setBounds(new Rectangle(104, 252, 140, 29)); Annuler.setText("Annuler"); Annuler.setIcon(new ImageIcon(image_d)); this.getContentPane().setBackground(new Color(239, 240, 234)); this.setForeground(new Color(239, 240, 234)); this.setTitle("Interface de connexion des clients au serveur de chat"); jLabel1.setFont(new java.awt.Font("Dialog", 1, 14)); jLabel1.setText("Adresse du serveur :"); jLabel1.setBounds(new Rectangle(75, 176, 156, 26)); jTextField1.setBounds(new Rectangle(230, 176, 108, 25)); Icon siegle = new ImageIcon(image); siegle_L = new JLabel("", siegle, SwingConstants.LEFT); siegle_L.setBounds(new Rectangle(0, 1, 76, 105)); this.getContentPane().add(jLabel1, null); this.getContentPane().add(pwd_L, null); this.getContentPane().add(Pseudo_L, null); this.getContentPane().add(jTextField1, null); this.getContentPane().add(nom, null); this.getContentPane().add(pwd, null); this.getContentPane().add(Bienvenue, null); this.getContentPane().add(Connect, null); this.getContentPane().add(Annuler, null); this.getContentPane().add(siegle_L, null); this.setSize(new Dimension(439, 321)); this.setResizable(false); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); }
/** Constructor */ public ServiceFilterPanel(String text, Vector list) { empty_border = new EmptyBorder(5, 5, 0, 5); indent_border = new EmptyBorder(5, 25, 5, 5); service_box = new JCheckBox(text); service_box.addActionListener(this); service_data = new Vector(); if (list != null) { service_box.setSelected(true); service_data = (Vector) list.clone(); } service_list = new JList(service_data); service_list.setBorder(new EtchedBorder()); service_list.setVisibleRowCount(5); service_list.addListSelectionListener(this); service_list.setEnabled(service_box.isSelected()); service_scroll = new JScrollPane(service_list); service_scroll.setBorder(new EtchedBorder()); remove_service_button = new JButton("Remove"); remove_service_button.addActionListener(this); remove_service_button.setEnabled(false); remove_service_panel = new JPanel(); remove_service_panel.setLayout(new FlowLayout()); remove_service_panel.add(remove_service_button); service_area = new JPanel(); service_area.setLayout(new BorderLayout()); service_area.add(service_scroll, BorderLayout.CENTER); service_area.add(remove_service_panel, BorderLayout.EAST); service_area.setBorder(indent_border); add_service_field = new JTextField(); add_service_field.addActionListener(this); add_service_field.getDocument().addDocumentListener(this); add_service_field.setEnabled(service_box.isSelected()); add_service_button = new JButton("Add"); add_service_button.addActionListener(this); add_service_button.setEnabled(false); add_service_panel = new JPanel(); add_service_panel.setLayout(new BorderLayout()); JPanel dummy = new JPanel(); dummy.setBorder(empty_border); add_service_panel.add(dummy, BorderLayout.WEST); add_service_panel.add(add_service_button, BorderLayout.EAST); add_service_area = new JPanel(); add_service_area.setLayout(new BorderLayout()); add_service_area.add(add_service_field, BorderLayout.CENTER); add_service_area.add(add_service_panel, BorderLayout.EAST); add_service_area.setBorder(indent_border); setLayout(new BorderLayout()); add(service_box, BorderLayout.NORTH); add(service_area, BorderLayout.CENTER); add(add_service_area, BorderLayout.SOUTH); setBorder(empty_border); }
private void selectFolder() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File(textFolder.getText())); fileChooser.setDialogTitle(CAPTION_SELECT_FOLDER); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setApproveButtonText("Select"); fileChooser.setApproveButtonToolTipText(TOOL_TIP_SELECT_FOLDER); if (fileChooser.showOpenDialog(FileTransferServer.this) == JFileChooser.APPROVE_OPTION) { // Get the selected file String path = fileChooser.getSelectedFile().getPath() + "\\"; textFolder.setText(path); } }
Server() { setSize(500, 100); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); thread = new Thread(this); clientList = new ArrayList<ClientData>(); sList = new ArrayList<ServerThread>(); JPanel panel = new JPanel(); panel.add(new JLabel("Port :")); portText = new JTextField(5); portText.setText("7777"); panel.add(portText); startButton = new JButton("Start server"); startButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { try { port = Integer.parseInt(portText.getText()); thread.start(); startButton.setEnabled(false); } catch (NumberFormatException ex) { JOptionPane.showMessageDialog(null, "B³êdny format numeru portu"); portText.setText(""); } } }); panel.add(startButton); l = new JLabel("Serwer jest nieaktywny"); panel.add(l); add(panel, BorderLayout.NORTH); }
public Cliente(Socket s) { super("OPERACIONES CON BD"); socket = s; try { salida = new DataOutputStream(socket.getOutputStream()); inObjeto = new ObjectInputStream(socket.getInputStream()); } catch (IOException e) { e.printStackTrace(); System.exit(0); } setLayout(null); etiqueta.setBounds(10, 10, 200, 30); add(etiqueta); empconsultar.setBounds(210, 10, 50, 30); add(empconsultar); textarea1 = new JTextArea(); scrollpane1 = new JScrollPane(textarea1); scrollpane1.setBounds(10, 50, 400, 300); add(scrollpane1); boton.setBounds(420, 10, 100, 30); add(boton); desconectar.setBounds(420, 50, 100, 30); add(desconectar); textarea1.setEditable(false); boton.addActionListener(this); desconectar.addActionListener(this); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); }
// constructor public Server1() { super("Kelvin's Server"); userText = new JTextField(); userText.setEditable(false); userText.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { sendMessage(event.getActionCommand()); userText.setText(""); } }); add(userText, BorderLayout.NORTH); chatWindow = new JTextArea(); add(new JScrollPane(chatWindow)); setSize(300, 150); setVisible(true); }
public void enableOrder(boolean state) { textPlay.setEnabled(state); butPlay.setEnabled(state); if (state) { orderSent = false; } }
/** Handle changes to the text field */ public void changedUpdate(DocumentEvent e) { String text = add_service_field.getText(); if ((text != null) && (text.length() > 0)) { add_service_button.setEnabled(true); } else { add_service_button.setEnabled(false); } }
@Override public void actionPerformed(ActionEvent e) { // TODO action Object obj = e.getSource(); if (obj.equals(jtf) || obj.equals(textin)) { // name.setText(" 메시지 입력 "); pw.println(jtf.getText()); jtf.setText(""); } else if (obj.equals(serveropen)) { ServerOpen(); } else if (obj.equals(clientin) || obj.equals(pi)) { ClientIn(); } else if (obj.equals(conf)) { login(); } }
private void buildInterface() { // Panel p to hold the label and text field JPanel panelInput = new JPanel(); panelInput.setLayout(new BorderLayout()); panelInput.add(buttonSelect, BorderLayout.EAST); panelInput.add(textFolder, BorderLayout.CENTER); textFolder.setEditable(false); textFolder.setText(System.getProperty("user.home") + "\\"); // Set default save location setLayout(new BorderLayout()); add(panelInput, BorderLayout.NORTH); add(new JScrollPane(textArea), BorderLayout.CENTER); textArea.setEditable(false); buttonSelect.setToolTipText(TOOL_TIP_SELECT_FOLDER); buttonSelect.addActionListener(new ButtonListener()); // Register listener }
public void keyReleased(KeyEvent e) { char ch = e.getKeyChar(); if (ch == KeyEvent.CHAR_UNDEFINED || Character.isISOControl(ch)) return; int pos = m_editor.getCaretPosition(); String str = m_editor.getText(); if (str.length() == 0) return; for (int k = 0; k < m_comboBox.getItemCount(); k++) { String item = m_comboBox.getItemAt(k).toString(); if (item.startsWith(str)) { m_editor.setText(item); m_editor.setCaretPosition(item.length()); m_editor.moveCaretPosition(pos); m_comboBox.setSelectedItem(item); break; } } }
// 部屋に入室している状態のコンポーネント設定 private void enteredRoom(String roomName) { this.roomName = roomName; setTitle(APPNAME + " " + roomName); msgTextField.setEnabled(true); submitButton.setEnabled(true); addRoomButton.setEnabled(false); enterRoomButton.setText("退室"); enterRoomButton.setActionCommand("exitRoom"); }
// 部屋に入室していない状態のコンポーネント設定 private void exitedRoom() { roomName = null; setTitle(APPNAME); msgTextField.setEnabled(false); submitButton.setEnabled(false); addRoomButton.setEnabled(true); enterRoomButton.setText("入室"); enterRoomButton.setActionCommand("enterRoom"); userList.setModel(new DefaultListModel()); }
public void login() { String driver = "oracle.jdbc.driver.OracleDriver"; String url = "jdbc:oracle:thin:@localhost:1521:orcl"; Connection con = null; Statement stmt = null; ResultSet rs = null; String id, pw, sql; try { Class.forName(driver); con = DriverManager.getConnection(url, "hr", "hr"); stmt = con.createStatement(); sql = "select * from chatuser where id = '" + lid.getText() + "'"; rs = stmt.executeQuery(sql); if (rs.next()) { pw = rs.getString(2); nick = rs.getString(3); if (lpw.getText().equals(pw)) { jd.setVisible(false); setVisible(true); } else { lpw.setText("일치하지 않습니다."); } } else { lid.setText("일치하지 않습니다."); } } catch (Exception e1) { e1.printStackTrace(); System.out.println("데이터 베이스 연결 실패!!"); } finally { try { if (rs != null) rs.close(); if (stmt != null) stmt.close(); if (con != null) con.close(); } catch (Exception e1) { System.out.println(e1.getMessage()); } } }
/** called when our JTree's nodes are selected. */ void nodeSelected(TreeNode treeNode) { lastSelected = treeNode; Node node = jtree.getNode(treeNode); if (node == null) return; String xpath = DOMInfoExtractor.getXPath(node); selectedXPathTextField.setText(xpath); String message = DOMTreeFull.toString(node); message += "\r\n"; message += xpath; setMessage(message); }
/** * Méthode de création du panel de Connection * * @return */ private JPanel createPanelConnect() { JPanel panAll = new JPanel(new BorderLayout()); JPanel panPseudo = new JPanel(); textPseudo = new JTextField("", 20); textPseudo.setMaximumSize(textPseudo.getPreferredSize()); panPseudo.add(new JLabel("Pseudo: ")); panPseudo.add(textPseudo); JPanel panConn = new JPanel(); textServerIP = new JTextField("127.0.0.1", 15); panConn.add(new JLabel("Server IP: ")); panConn.add(textServerIP); butConnect = new JButton("Connect"); butConnect.addActionListener(this); panAll.add(panPseudo, BorderLayout.NORTH); panAll.add(panConn, BorderLayout.CENTER); panAll.add(butConnect, BorderLayout.SOUTH); return panAll; }
/** * Methode de connection avec le serveur * * @return * @throws IOException */ public boolean serverConnection() throws IOException { boolean ok = false; // créer la connexion au serveur, ainsi que les flux uniquement si elle n'est pas active if (comm == null) { try { // Récupération de l'adresse du serveur comm = new Socket(textServerIP.getText(), 12345); oos = new ObjectOutputStream(comm.getOutputStream()); ois = new ObjectInputStream(comm.getInputStream()); // envoyer le pseudo du joueur oos.writeObject(textPseudo.getText()); oos.flush(); // lire un booléen -> ok ok = true; } catch (IOException e) { System.out.println("problème de connexion au serveur : (JungleIG)" + e.getMessage()); System.exit(1); } } return ok; }
/** * Méthode de création du panel de Jeu * * @return */ private JPanel createPanelPlay() { JPanel panAll = new JPanel(new BorderLayout()); textInfoParty = new JTextArea(20, 100); textInfoParty.setLineWrap(true); JScrollPane scroll = new JScrollPane( textInfoParty, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); JPanel panPlay = new JPanel(); textPlay = new JTextField("", 5); textPlay.setMaximumSize(textPlay.getPreferredSize()); butPlay = new JButton("Jouer"); butPlay.addActionListener(this); panPlay.add(new JLabel("Ordre : ")); panPlay.add(textPlay); enableOrder(false); JPanel panRight = new JPanel(new BorderLayout()); panRight.add(panPlay, BorderLayout.CENTER); panRight.add(butPlay, BorderLayout.SOUTH); JPanel panMain = new JPanel(); panMain.add(scroll); panMain.add(panRight); butQuit = new JButton("Quitter"); butQuit.addActionListener(this); panAll.add(panMain, BorderLayout.CENTER); panAll.add(butQuit, BorderLayout.SOUTH); return panAll; }
public void actionPerformed(ActionEvent e) { if (e.getSource() == boton) { try { salida.writeUTF(empconsultar.getText()); } catch (IOException e1) { e1.printStackTrace(); } } if (e.getSource() == desconectar) { try { socket.close(); } catch (IOException e1) { e1.printStackTrace(); } System.exit(0); } }