/** 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(); } }
private void setComponentsEnabled(boolean enabled) { list.setEnabled(enabled); process.setEnabled(enabled); remove.setEnabled(enabled); xres.setEnabled(enabled); yres.setEnabled(enabled); aspect.setEnabled(enabled); boolean b = aspect.isSelected() && enabled; colorLabel.setEnabled(b); colorBox.setEnabled(b); redLabel.setEnabled(b); red.setEnabled(b); redValue.setEnabled(b); greenLabel.setEnabled(b); green.setEnabled(b); greenValue.setEnabled(b); blueLabel.setEnabled(b); blue.setEnabled(b); blueValue.setEnabled(b); format.setEnabled(enabled); algorithm.setEnabled(enabled); prepend.setEnabled(enabled); append.setEnabled(enabled); output.setEnabled(enabled); }
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(); }
/** Update button enable/disable state according enableCheckBox. */ private void updateButtonsState() { sipProtocolCheckBox.setEnabled(enableCheckBox.isSelected()); jabberProtocolCheckBox.setEnabled(enableCheckBox.isSelected()); rtpProtocolCheckBox.setEnabled(enableCheckBox.isSelected()); ice4jProtocolCheckBox.setEnabled(enableCheckBox.isSelected()); fileCountField.setEnabled(enableCheckBox.isSelected()); fileSizeField.setEnabled(enableCheckBox.isSelected()); fileSizeLabel.setEnabled(enableCheckBox.isSelected()); fileCountLabel.setEnabled(enableCheckBox.isSelected()); }
// 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 enableOrder(boolean state) { textPlay.setEnabled(state); butPlay.setEnabled(state); if (state) { orderSent = false; } }
// 部屋に入室している状態のコンポーネント設定 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()); }
/** 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); }
public Viewer() { leveldbStore.setMultiSelectionEnabled(false); leveldbStore.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); putButton.setEnabled(false); key.setEnabled(false); value.setEnabled(false); findField.setEnabled(false); deleteButton.setEnabled(false); saveButton.setEnabled(false); putType.setEnabled(false); putType.setEditable(false); signedBox.setEnabled(false); openButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (openButton.isEnabled()) { openButton.setEnabled(false); new Thread() { public void run() { if (leveldbStore.showOpenDialog(pane) == JFileChooser.APPROVE_OPTION) { File select = leveldbStore.getSelectedFile(); if (select.isDirectory()) { new OpenLevelDBDialog(Viewer.this, select); openDatabase(select); dbPathField.setText(select.getAbsolutePath()); } else { JOptionPane.showMessageDialog( pane, "The selecting item must be a directory", "Unable to load database", JOptionPane.WARNING_MESSAGE); } } else { openButton.setEnabled(true); } } }.start(); } } }); deleteButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (dataList.getSelectedValue() != null) { delete(dataList.getSelectedValue().key); } openDatabase(leveldbStore.getSelectedFile()); } }); putButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { put( ((PutType) putType.getSelectedItem()).getBytes(key.getText()), ((PutType) putType.getSelectedItem()).getBytes(value.getText())); openDatabase(leveldbStore.getSelectedFile()); } }); findField.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { openDatabase(leveldbStore.getSelectedFile()); } }); findField .getDocument() .addDocumentListener( new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { openDatabase(leveldbStore.getSelectedFile()); } @Override public void removeUpdate(DocumentEvent e) { openDatabase(leveldbStore.getSelectedFile()); } @Override public void changedUpdate(DocumentEvent e) { openDatabase(leveldbStore.getSelectedFile()); } }); findField .getDocument() .addUndoableEditListener( new UndoableEditListener() { @Override public void undoableEditHappened(UndoableEditEvent e) { openDatabase(leveldbStore.getSelectedFile()); } }); hexKey .getDocument() .addDocumentListener( new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { update(hexKey); } @Override public void removeUpdate(DocumentEvent e) { update(hexKey); } @Override public void changedUpdate(DocumentEvent e) { update(hexKey); } }); hexKey .getDocument() .addUndoableEditListener( new UndoableEditListener() { @Override public void undoableEditHappened(UndoableEditEvent e) { update(hexKey); } }); stringKey .getDocument() .addDocumentListener( new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { update(stringKey); } @Override public void removeUpdate(DocumentEvent e) { update(stringKey); } @Override public void changedUpdate(DocumentEvent e) { update(stringKey); } }); stringKey .getDocument() .addUndoableEditListener( new UndoableEditListener() { @Override public void undoableEditHappened(UndoableEditEvent e) { update(stringKey); } }); hexValue .getDocument() .addDocumentListener( new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { update(hexValue); } @Override public void removeUpdate(DocumentEvent e) { update(hexValue); } @Override public void changedUpdate(DocumentEvent e) { update(hexValue); } }); hexValue .getDocument() .addUndoableEditListener( new UndoableEditListener() { @Override public void undoableEditHappened(UndoableEditEvent e) { update(hexValue); } }); stringValue .getDocument() .addDocumentListener( new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { update(stringValue); } @Override public void removeUpdate(DocumentEvent e) { update(stringValue); } @Override public void changedUpdate(DocumentEvent e) { update(stringValue); } }); stringValue .getDocument() .addUndoableEditListener( new UndoableEditListener() { @Override public void undoableEditHappened(UndoableEditEvent e) { update(stringValue); } }); saveButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { save(); openDatabase(leveldbStore.getSelectedFile()); } }); dataList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); dataList.addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { DBItem item = dataList.getSelectedValue(); if (item != null) { hexValue.setText(cutToLine(LevelDBViewer.toHexString(item.value), 64)); stringValue.setText(cutToLine(new String(item.value), 64)); hexKey.setText(cutToLine(LevelDBViewer.toHexString(item.key), 64)); stringKey.setText(cutToLine(new String(item.key), 64)); lengthLabel.setText(String.valueOf(item.value.length + item.key.length)); keyLength.setText(String.valueOf(item.key.length)); valueLength.setText(String.valueOf(item.value.length)); } } }); signedBox.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { LevelDBViewer.DEFAULT_SINGED = signedBox.isSelected(); int i = dataList.getSelectedIndex(); dataList.clearSelection(); dataList.updateUI(); dataList.setSelectedIndex(i); update(hexKey); update(hexValue); } }); for (PutType t : PutType.values()) { putType.addItem(t); } putType.setSelectedItem(PutType.STRING); putType.addItemListener( new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { openDatabase(leveldbStore.getSelectedFile()); } }); putType.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { openDatabase(leveldbStore.getSelectedFile()); } }); dialog.setLocationByPlatform(true); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setContentPane(pane); dialog.setTitle("LevelDB Viewer By Marcus (https://github.com/SuperMarcus)"); dialog.getRootPane().setDefaultButton(openButton); dialog.pack(); dialog.setVisible(true); }
public void openDatabase(File select) { if (getOptions() != null) { DB database = null; try { database = factory.open(select, getOptions()); DBIterator iterator = database.iterator(); ArrayList<DBItem> data = new ArrayList<>(); String reg = findField.getText().trim(); for (iterator.seekToFirst(); iterator.hasNext(); iterator.next()) { if (reg.isEmpty() || new BigInteger(iterator.peekNext().getKey()).toString(16).contains(reg) || LevelDBViewer.toHexString(iterator.peekNext().getKey()).contains(reg) || new BigInteger(iterator.peekNext().getValue()).toString(16).contains(reg) || LevelDBViewer.toHexString(iterator.peekNext().getValue()).contains(reg) || new String(iterator.peekNext().getKey()).contains(reg) || new String(iterator.peekNext().getValue()).contains(reg)) { data.add(new DBItem(iterator.peekNext().getKey(), iterator.peekNext().getValue())); } } iterator.close(); dialog.getRootPane().setDefaultButton(putButton); dataList.getSelectionModel().clearSelection(); dataList.setListData(data.toArray(new DBItem[data.size()])); putButton.setEnabled(true); key.setEnabled(true); value.setEnabled(true); findField.setEnabled(true); deleteButton.setEnabled(true); putType.setEnabled(true); signedBox.setEnabled(true); // saveButton.setEnabled(true); hexValue.setText(""); stringValue.setText(""); hexKey.setText(""); stringKey.setText(""); lengthLabel.setText(""); keyLength.setText(""); valueLength.setText(""); } catch (Exception e) { JOptionPane.showMessageDialog(pane, "Unable to open database:\n" + e); e.printStackTrace(); } finally { if (database != null) { try { database.close(); } catch (IOException e) { JOptionPane.showMessageDialog(pane, "Unable to close database:\n" + e); e.printStackTrace(); } } } } }
private static JPanel initOptionsPane() { JPanel pane = null; ActionAdapter buttonListener = null; // Create an options pane JPanel optionsPane = new JPanel(new GridLayout(4, 1)); // IP address input pane = new JPanel(new FlowLayout(FlowLayout.RIGHT)); pane.add(new JLabel("Host IP:")); ipField = new JTextField(10); ipField.setText(hostIP); ipField.setEnabled(false); ipField.addFocusListener( new FocusAdapter() { public void focusLost(FocusEvent e) { ipField.selectAll(); // Should be editable only when disconnected if (connectionStatus != DISCONNECTED) { changeStatusNTS(NULL, true); } else { hostIP = ipField.getText(); } } }); pane.add(ipField); optionsPane.add(pane); // Port input pane = new JPanel(new FlowLayout(FlowLayout.RIGHT)); pane.add(new JLabel("Port:")); portField = new JTextField(10); portField.setEditable(true); portField.setText((new Integer(port)).toString()); portField.addFocusListener( new FocusAdapter() { public void focusLost(FocusEvent e) { // should be editable only when disconnected if (connectionStatus != DISCONNECTED) { changeStatusNTS(NULL, true); } else { int temp; try { temp = Integer.parseInt(portField.getText()); port = temp; } catch (NumberFormatException nfe) { portField.setText((new Integer(port)).toString()); mainFrame.repaint(); } } } }); pane.add(portField); optionsPane.add(pane); // Host/guest option buttonListener = new ActionAdapter() { public void actionPerformed(ActionEvent e) { if (connectionStatus != DISCONNECTED) { changeStatusNTS(NULL, true); } else { isHost = e.getActionCommand().equals("host"); // Cannot supply host IP if host option is chosen if (isHost) { ipField.setEnabled(false); ipField.setText("localhost"); hostIP = "localhost"; } else { ipField.setEnabled(true); } } } }; ButtonGroup bg = new ButtonGroup(); hostOption = new JRadioButton("Host", true); hostOption.setMnemonic(KeyEvent.VK_H); hostOption.setActionCommand("host"); hostOption.addActionListener(buttonListener); guestOption = new JRadioButton("Guest", false); guestOption.setMnemonic(KeyEvent.VK_G); guestOption.setActionCommand("guest"); guestOption.addActionListener(buttonListener); bg.add(hostOption); bg.add(guestOption); pane = new JPanel(new GridLayout(1, 2)); pane.add(hostOption); pane.add(guestOption); optionsPane.add(pane); // Connect/disconnect buttons JPanel buttonPane = new JPanel(new GridLayout(1, 2)); buttonListener = new ActionAdapter() { public void actionPerformed(ActionEvent e) { // Request a connection initiation if (e.getActionCommand().equals("connect")) { changeStatusNTS(BEGIN_CONNECT, true); } // Disconnect else { changeStatusNTS(DISCONNECTING, true); } } }; connectButton = new JButton("Connect"); connectButton.setMnemonic(KeyEvent.VK_C); connectButton.setActionCommand("connect"); connectButton.addActionListener(buttonListener); connectButton.setEnabled(true); disconnectButton = new JButton("Disconnect"); disconnectButton.setMnemonic(KeyEvent.VK_D); disconnectButton.setActionCommand("disconnect"); disconnectButton.addActionListener(buttonListener); disconnectButton.setEnabled(false); buttonPane.add(connectButton); buttonPane.add(disconnectButton); optionsPane.add(buttonPane); return optionsPane; }
// Checks the current state and sets the enables/disables // accordingly public void run() { switch (connectionStatus) { case DISCONNECTED: connectButton.setEnabled(true); disconnectButton.setEnabled(false); ipField.setEnabled(true); portField.setEnabled(true); hostOption.setEnabled(true); guestOption.setEnabled(true); chatLine.setText(""); chatLine.setEnabled(false); statusColor.setBackground(Color.red); break; case DISCONNECTING: connectButton.setEnabled(false); disconnectButton.setEnabled(false); ipField.setEnabled(false); portField.setEnabled(false); hostOption.setEnabled(false); guestOption.setEnabled(false); chatLine.setEnabled(false); statusColor.setBackground(Color.orange); break; case CONNECTED: connectButton.setEnabled(false); disconnectButton.setEnabled(true); ipField.setEnabled(false); portField.setEnabled(false); hostOption.setEnabled(false); guestOption.setEnabled(false); chatLine.setEnabled(true); statusColor.setBackground(Color.green); break; case BEGIN_CONNECT: connectButton.setEnabled(false); disconnectButton.setEnabled(false); ipField.setEnabled(false); portField.setEnabled(false); hostOption.setEnabled(false); guestOption.setEnabled(false); chatLine.setEnabled(false); chatLine.grabFocus(); statusColor.setBackground(Color.orange); break; } // Make sure that the button/text field states are consistent // with the internal states ipField.setText(hostIP); portField.setText((new Integer(port)).toString()); hostOption.setSelected(isHost); guestOption.setSelected(!isHost); statusField.setText(statusString); chatText.append(toAppend.toString()); toAppend.setLength(0); mainFrame.repaint(); }
private void init(EditorPatternButton imgBtn, JLabel msgApplied) { _imgBtn = imgBtn; JLabel lblPath = new JLabel(_I("lblPath")); JLabel lblFilename = new JLabel(_I("lblFilename")); String filename = _imgBtn.getFilename(); File f = new File(filename); String fullpath = f.getParent(); filename = getFilenameWithoutExt(f); _oldFilename = filename; BufferedImage thumb = _imgBtn.createThumbnailImage(THUMB_MAX_HEIGHT); Border border = LineBorder.createGrayLineBorder(); JLabel lblThumb = new JLabel(new ImageIcon(thumb)); lblThumb.setBorder(border); _txtPath = new JTextField(fullpath, TXT_FILENAME_LENGTH); _txtPath.setEditable(false); _txtPath.setEnabled(false); String[] candidates = new String[] {filename}; // <editor-fold defaultstate="collapsed" desc="OCR --- not used"> /* String ocrText = getFilenameFromImage(thumb); if(ocrText.length()>0 && !ocrText.equals(filename)) candidates = new String[] {filename, ocrText}; */ // </editor-fold> _txtFilename = new AutoCompleteCombo(candidates); _txtFileExt = new JTextField(getFileExt(f), TXT_FILE_EXT_LENGTH); _txtFileExt.setEditable(false); _txtFileExt.setEnabled(false); GridBagConstraints c = new GridBagConstraints(); c.gridy = 0; c.insets = new Insets(100, 0, 0, 0); this.add(new JLabel(""), c); c = new GridBagConstraints(); c.fill = 0; c.gridwidth = 3; c.gridy = 1; c.insets = new Insets(0, 10, 20, 10); this.add(lblThumb, c); c = new GridBagConstraints(); c.fill = 1; c.gridy = 2; this.add(lblPath, c); c.gridx = 1; c.gridwidth = 2; this.add(_txtPath, c); c = new GridBagConstraints(); c.gridy = 3; c.fill = 0; this.add(lblFilename, c); this.add(_txtFilename, c); this.add(_txtFileExt, c); c = new GridBagConstraints(); c.gridy = 4; c.gridx = 1; c.insets = new Insets(200, 0, 0, 0); this.add(msgApplied, c); }
private void refresh(int index) { GridBagConstraints c = new GridBagConstraints(); // No connector ................ if (acs.size() == 0) { add(new JLabel(bundle.getString("CTL_No_Connector")), c); return; } // Connector switch ................ if (acs.size() > 1) { c.insets = new Insets(0, 0, 3, 3); add(new JLabel(bundle.getString("CTL_Connector")), c); cbConnectors = new JComboBox(); int i, k = acs.size(); for (i = 0; i < k; i++) { AttachingConnector ac = (AttachingConnector) acs.get(i); int jj = ac.name().lastIndexOf('.'); String s = (jj < 0) ? ac.name() : ac.name().substring(jj + 1); cbConnectors.addItem(s + " (" + ac.description() + ")"); } c = new GridBagConstraints(); c.insets = new Insets(0, 3, 3, 0); c.weightx = 1.0; c.fill = java.awt.GridBagConstraints.HORIZONTAL; c.gridwidth = 0; cbConnectors.setSelectedIndex(index); cbConnectors.setActionCommand("SwitchMe!"); cbConnectors.addActionListener(this); add(cbConnectors, c); } ac = (AttachingConnector) acs.get(index); // Transport ................ c = new GridBagConstraints(); c.insets = new Insets(3, 0, 0, 3); add(new JLabel(bundle.getString("CTL_Transport")), c); JTextField tfTransport = new JTextField(ac.transport().name()); tfTransport.setEnabled(false); c = new GridBagConstraints(); c.gridwidth = 0; c.insets = new Insets(3, 3, 0, 0); c.fill = java.awt.GridBagConstraints.HORIZONTAL; c.weightx = 1.0; add(tfTransport, c); // Other params ................ args = ac.defaultArguments(); tfParams = new JTextField[args.size()]; Iterator it = args.keySet().iterator(); int i = 0; while (it.hasNext()) { String name = (String) it.next(); Argument a = (Argument) args.get(name); c = new GridBagConstraints(); c.insets = new Insets(6, 0, 0, 3); c.anchor = GridBagConstraints.WEST; add(new JLabel(a.label() + ": "), c); JTextField tfParam = new JTextField(a.value()); tfParams[i++] = tfParam; tfParam.setName(name); c = new GridBagConstraints(); c.gridwidth = 0; c.insets = new Insets(6, 3, 0, 0); c.fill = java.awt.GridBagConstraints.HORIZONTAL; c.weightx = 1.0; add(tfParam, c); } c = new GridBagConstraints(); c.weighty = 1.0; JPanel p = new JPanel(); p.setPreferredSize(new Dimension(1, 1)); add(p, c); }
/** Updates the components. */ private void updateComponents() { text_inner_aperture.setEnabled(getMode() == DefaultStarDetector.MODE_APERTURE); text_outer_aperture.setEnabled(getMode() == DefaultStarDetector.MODE_APERTURE); }
DeleteCustomer() { // super(Title, Resizable, Closable, Maximizable, Iconifiable) super("Delete Account Holder", false, true, false, true); setSize(350, 235); jpDel.setLayout(null); lbNo = new JLabel("Account No:"); lbNo.setForeground(Color.black); lbNo.setBounds(15, 20, 80, 25); lbName = new JLabel("Person Name:"); lbName.setForeground(Color.black); lbName.setBounds(15, 55, 90, 25); lbDate = new JLabel("Last Transaction:"); lbDate.setForeground(Color.black); lbDate.setBounds(15, 90, 100, 25); lbBal = new JLabel("Balance:"); lbBal.setForeground(Color.black); lbBal.setBounds(15, 125, 80, 25); txtNo = new JTextField(); txtNo.setHorizontalAlignment(JTextField.RIGHT); txtNo.setBounds(125, 20, 200, 25); txtName = new JTextField(); txtName.setEnabled(false); txtName.setBounds(125, 55, 200, 25); txtDate = new JTextField(); txtDate.setEnabled(false); txtDate.setBounds(125, 90, 200, 25); txtBal = new JTextField(); txtBal.setEnabled(false); txtBal.setHorizontalAlignment(JTextField.RIGHT); txtBal.setBounds(125, 125, 200, 25); // Aligning The Buttons. btnDel = new JButton("Delete"); btnDel.setBounds(20, 165, 120, 25); btnDel.addActionListener(this); btnCancel = new JButton("Cancel"); btnCancel.setBounds(200, 165, 120, 25); btnCancel.addActionListener(this); // Adding the All the Controls to Panel. jpDel.add(lbNo); jpDel.add(txtNo); jpDel.add(lbName); jpDel.add(txtName); jpDel.add(lbDate); jpDel.add(txtDate); jpDel.add(lbBal); jpDel.add(txtBal); jpDel.add(btnDel); jpDel.add(btnCancel); // Restricting The User Input to only Numerics in Numeric TextBoxes. txtNo.addKeyListener( new KeyAdapter() { public void keyTyped(KeyEvent ke) { char c = ke.getKeyChar(); if (!((Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE)))) { getToolkit().beep(); ke.consume(); } } }); // Checking the Accunt No. Provided By User on Lost Focus of the TextBox. txtNo.addFocusListener( new FocusListener() { public void focusGained(FocusEvent e) {} public void focusLost(FocusEvent fe) { if (txtNo.getText().equals("")) { } else { rows = 0; populateArray(); // Load All Existing Records in Memory. findRec(); // Finding if Account No. Already Exist or Not. } } }); // Adding Panel to Window. getContentPane().add(jpDel); populateArray(); // Load All Existing Records in Memory. // In the End Showing the New Account Window. setVisible(true); }
// Function use to Lock Controls of Window. void btnEnable() { txtNo.setEnabled(false); btnDel.setEnabled(false); }
public void actionPerformed(ActionEvent e) { if (e.getSource() == butConnect) { try { boolean ok = serverConnection(); if (ok) { setInitPanel(); } else { System.out.println("Le pseudo existe déjà, choisissez en un autre."); } } catch (IOException err) { System.err.println( "Problème de connection avec le serveur: " + err.getMessage() + "\n.Arrêt..."); System.exit(1); } } else if (e.getSource() == butListParty) { try { // envoyer requête LIST PARTY oos.writeInt(JungleServer.REQ_LISTPARTY); oos.flush(); // recevoir résultat et l'afficher dans textInfoInit System.out.println("flush"); boolean pret = ois.readBoolean(); System.out.println(pret); if (pret) { String nomParty = (String) ois.readObject(); System.out.println("apres read"); textInfoInit.append(nomParty + " "); } } catch (ClassNotFoundException err) { } catch (IOException err) { System.err.println( "Problème de connection avec le serveur: " + err.getMessage() + "\n.Arrêt..."); System.exit(1); } } else if (e.getSource() == butCreateParty) { try { boolean ok; // envoyer requête CREATE PARTY (paramètres : nom partie et nb joueurs nécessaires) oos.writeInt(JungleServer.REQ_CREATEPARTY); oos.writeObject(textCreate.getText()); int nbJoueurs = (Integer) spinNbPlayer.getValue(); oos.writeInt(nbJoueurs); oos.flush(); // recevoir résultat -> ok ok = ois.readBoolean(); System.out.println(ok); // si ok == true : if (ok) { // mettre le panneau party au centre setPartyPanel(); // afficher un message dans textInfoParty comme quoi il faut attendre le début de partie textInfoParty.append("Attendre le début de la partie"); // créer un ThreadClient et lancer son exécution ThreadClient threadClient = new ThreadClient(this); threadClient.start(); } } catch (IOException err) { System.err.println( "probleme de connection serveur : " + err.getMessage() + "\n.Aborting..."); System.exit(1); } } else if (e.getSource() == butJoinParty) { try { int idPlayer; // envoyer requête JOIN PARTY (paramètres : numero partie) oos.writeInt(JungleServer.REQ_JOINPARTY); oos.flush(); System.out.println("requete envoyée"); int numPartie = Integer.parseInt(textJoin.getText()); oos.writeInt(numPartie); oos.flush(); System.out.println("numPartie flushé"); // recevoir résultat -> idPlayer idPlayer = ois.readInt(); System.out.println("idplayer reçu : " + idPlayer); // si idPlayer >= 1 : if (idPlayer >= 1) { // mettre le panneau party au centre setPartyPanel(); // afficher un message dans textInfoParty comme quoi il faut attendre le début de partie textInfoParty.append("Attendre la début de la partie"); // créer un ThreadClient et lancer son exécution System.out.println("avant démarrage du thread"); ThreadClient threadClient = new ThreadClient(this); threadClient.start(); System.out.println("Apres le thread"); } } catch (IOException err) { System.err.println("Problème de connection serveur: " + err.getMessage() + "\n.Arrêt..."); System.exit(1); } } else if (e.getSource() == butPlay) { try { // envoyer requête PLAY (paramètre : contenu de textPlay) oos.writeInt(JungleServer.REQ_PLAY); oos.writeObject(textPlay.getText()); oos.flush(); orderSent = true; butPlay.setEnabled(false); textPlay.setEnabled(false); // mettre orderSent à true // bloquer le bouton play et le textfiled associé } catch (IOException err) { System.err.println("Problème connection serveur: " + err.getMessage() + "\n.Arrêt..."); System.exit(1); } } else if (e.getSource() == butQuit) { try { oos.close(); ois.close(); setConnectionPanel(); comm = null; } catch (IOException err) { System.err.println("Problème connection serveur: " + err.getMessage() + "\n.Arrêt..."); System.exit(1); } } }
public JChat() { this.setSize(500, 600); this.setResizable(false); this.setLayout(new BorderLayout()); JPanel topPanel = new JPanel(); topPanel.setLayout(new GridLayout(2, 1)); // set up buttons openChat = new JButton("Open to chat"); openChat.addActionListener(new OpenChat()); chatWith = new JButton("Chat with"); chatWith.addActionListener(new ChatWith()); send = new JButton("send"); send.addActionListener(new Send()); send.setEnabled(false); InputMap inputMap = send.getInputMap(JButton.WHEN_IN_FOCUSED_WINDOW); KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); inputMap.put(enter, "ENTER"); send.getActionMap().put("ENTER", new ClickAction(send)); // set up labels pickPort = new JLabel(); pickPort.setText("Pick your port number:"); desPort = new JLabel(); desPort.setText("Or enter a destinaltion port number:"); // set up text fields pickText = new JTextField(); pickText.setPreferredSize(new Dimension(150, 30)); desText = new JTextField(); desText.setPreferredSize(new Dimension(150, 30)); chatText = new JTextField(); chatText.setPreferredSize(new Dimension(400, 30)); chatText.setEnabled(false); JPanel top1 = new JPanel(); top1.add(pickPort); top1.add(pickText); top1.add(openChat); JPanel top2 = new JPanel(); top2.add(desPort); top2.add(desText); top2.add(chatWith); topPanel.add(top1); topPanel.add(top2); chatField = new JTextArea(); chatField.setAutoscrolls(true); chatField.setDragEnabled(true); chatField.setEditable(false); chatField.setAlignmentY(TOP_ALIGNMENT); JPanel bottomPanel = new JPanel(); bottomPanel.add(chatText); bottomPanel.add(send); this.add(topPanel, BorderLayout.NORTH); this.add(chatField, BorderLayout.CENTER); this.add(bottomPanel, BorderLayout.SOUTH); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }