/** 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(); } }
void addButton_actionPerformed(ActionEvent e) { if (jTextFieldAccountname.getText().length() == 0) { JOptionPane.showMessageDialog( null, "Fill in the Account Name", "Error", JOptionPane.ERROR_MESSAGE); jTextFieldAccountname.requestFocus(); } else if (jTextFieldFullname.getText().length() == 0) { JOptionPane.showMessageDialog( null, "Fill in the Full Name", "Error", JOptionPane.ERROR_MESSAGE); jTextFieldFullname.requestFocus(); } else if ((String.valueOf(jPasswordField1.getPassword())) .equals(String.valueOf(jPasswordField2.getPassword())) == false) { JOptionPane.showMessageDialog( null, "Passwords don't match", "Error", JOptionPane.ERROR_MESSAGE); jPasswordField1.requestFocus(); } else { usermodel.addUser( new User( jTextFieldAccountname.getText(), jTextFieldFullname.getText(), jPasswordField1.getPassword())); usermodel.fireTableDataChanged(); } }
public void actionPerformed(ActionEvent event) { if (event.getSource() == okButton) { this.setVisible(false); } else if (event.getSource() == rightArrow) { try { araucaria .getArgument() .addOwnersToSelected(araucaria, ownerSourceTableModel.getSelectedOwners()); ownerNodesTableModel.updateTable(araucaria.getArgument().getSelectedVertexOwners()); araucaria.undoStack.push(new EditAction(araucaria, "adding owners")); } catch (Exception ex) { return; } } else if (event.getSource() == leftArrow) { // Delete owners only from selected vertices araucaria.getArgument().deleteOwners(ownerNodesTableModel.getSelectedOwners(), true); ownerNodesTableModel.updateTable(araucaria.getArgument().getSelectedVertexOwners()); araucaria.undoStack.push(new EditAction(araucaria, "removing owners")); } else if (event.getSource() == addOwnerButton) { String newOwnerName = ownerText.getText(); if (newOwnerName.length() == 0) { return; } ownerSourceTableModel.addOwner(newOwnerName); ownerText.setText(""); ownerText.requestFocus(); } else if (event.getSource() == deleteSourceButton) { Vector selected = null; try { selected = ownerSourceTableModel.getSelectedOwners(); } catch (Exception ex) { return; } if (selected == null || selected.size() == 0) return; int action = JOptionPane.showConfirmDialog( this, "<html><center><font color=red face=helvetica><b>Delete selected owners?</b></font></center></html>", "Delete owners?", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null); if (action == 1) return; araucaria.getArgument().deleteOwners(selected); // Delete owners from ALL vertices araucaria.getArgument().deleteOwners(selected, false); ownerSourceTableModel.updateTable(araucaria.getArgument().getOwnerList()); ownerNodesTableModel.updateTable(araucaria.getArgument().getSelectedVertexOwners()); } }
@Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (e.getSource() == b1) { int index = box.getSelectedIndex(); String column = ""; if (index == 0) column = "ename"; else if (index == 1) column = "hiredate"; else column = "deptno"; String data = tf.getText().trim(); if (data.length() < 1) { tf.requestFocus(); return; } getFindData(column, data); } if (e.getSource() == b2) { getData(); } }
// Constructor connection receiving a socket number public ClientGUI(String host, int port, int udpPort) { super("Clash of Clans"); defaultPort = port; defaultUDPPort = udpPort; defaultHost = host; // the server name and the port number JPanel serverAndPort = new JPanel(new GridLayout(1, 5, 1, 3)); tfServer = new JTextField(host); tfPort = new JTextField("" + port); tfPort.setHorizontalAlignment(SwingConstants.RIGHT); // CHAT COMPONENTS chatStatus = new JLabel("Please login first", SwingConstants.LEFT); chatField = new JTextField(18); chatField.setBackground(Color.WHITE); JPanel chatControls = new JPanel(); chatControls.add(chatStatus); chatControls.add(chatField); chatControls.setBounds(0, 0, 200, 50); chatArea = new JTextArea("Welcome to the Chat room\n", 80, 80); chatArea.setEditable(false); JScrollPane jsp = new JScrollPane(chatArea); jsp.setBounds(0, 50, 200, 550); JPanel chatPanel = new JPanel(null); chatPanel.setSize(1000, 600); chatPanel.add(chatControls); chatPanel.add(jsp); // LOGIN COMPONENTS mainLogin = new MainPanel(); mainLogin.add(new JLabel("Main Login")); usernameField = new JTextField("user", 15); passwordField = new JTextField("password", 15); login = new CButton("Login"); login.addActionListener(this); sideLogin = new SidePanel(new FlowLayout(FlowLayout.LEFT)); sideLogin.add(usernameField); sideLogin.add(passwordField); sideLogin.add(login); // MAIN MENU COMPONENTS mainMenu = new MainPanel(); mmLabel = new JLabel("Main Menu"); timer = new javax.swing.Timer(1000, this); mainMenu.add(mmLabel); sideMenu = new SidePanel(new FlowLayout(FlowLayout.LEFT)); cmButton = new CButton("Customize Map"); tmButton = new CButton("Troop Movement"); gsButton = new CButton("Game Start"); logout = new CButton("Logout"); cmButton.addActionListener(this); tmButton.addActionListener(this); gsButton.addActionListener(this); logout.addActionListener(this); sideMenu.add(cmButton); // sideMenu.add(tmButton); sideMenu.add(gsButton); sideMenu.add(logout); // CM COMPONENTS mainCM = new MainPanel(new GridLayout(mapSize, mapSize)); tiles = new Tile[mapSize][mapSize]; int tileSize = mainCM.getWidth() / mapSize; for (int i = 0; i < mapSize; i++) { tiles[i] = new Tile[mapSize]; for (int j = 0; j < mapSize; j++) { tiles[i][j] = new Tile(i, j); tiles[i][j].setPreferredSize(new Dimension(tileSize, tileSize)); tiles[i][j].setSize(tileSize, tileSize); tiles[i][j].addActionListener(this); if ((i + j) % 2 == 0) tiles[i][j].setBackground(new Color(102, 255, 51)); else tiles[i][j].setBackground(new Color(51, 204, 51)); mainCM.add(tiles[i][j]); } } sideCM = new SidePanel(new FlowLayout(FlowLayout.LEFT)); cmBack = new CButton("Main Menu"); cmBack.setSize(150, 30); cmBack.setPreferredSize(new Dimension(150, 30)); cmBack.addActionListener(this); sideCM.add(cmBack); // TM COMPONENTS mainTM = new MainPanel(null); mapTM = new Map(600); mapTM.setPreferredSize(new Dimension(600, 600)); mapTM.setSize(600, 600); mapTM.setBounds(0, 0, 600, 600); mainTM.add(mapTM); sideTM = new SidePanel(new FlowLayout(FlowLayout.LEFT)); tmBack = new CButton("Main Menu"); tmBack.setSize(150, 30); tmBack.setPreferredSize(new Dimension(150, 30)); tmBack.addActionListener(this); sideTM.add(tmBack); JRadioButton button; ButtonGroup group; ub = new ArrayList<JRadioButton>(); group = new ButtonGroup(); button = new JRadioButton("Barbarian"); button.addActionListener(this); ub.add(button); sideTM.add(button); group.add(button); button = new JRadioButton("Archer"); button.addActionListener(this); ub.add(button); sideTM.add(button); group.add(button); createBuildings(); bb = new ArrayList<JRadioButton>(); group = new ButtonGroup(); JRadioButton removeButton = new JRadioButton("Remove Building"); bb.add(removeButton); sideCM.add(removeButton); group.add(removeButton); for (int i = 0; i < bList.size(); i++) { button = new JRadioButton(bList.get(i).getName() + '-' + bList.get(i).getQuantity()); bb.add(button); sideCM.add(button); group.add(button); } mainPanels = new MainPanel(new CardLayout()); mainPanels.add(mainLogin, "Login"); mainPanels.add(mainMenu, "Menu"); mainPanels.add(mainCM, "CM"); mainPanels.add(mainTM, "TM"); sidePanels = new SidePanel(new CardLayout()); sidePanels.add(sideLogin, "Login"); sidePanels.add(sideMenu, "Menu"); sidePanels.add(sideCM, "CM"); sidePanels.add(sideTM, "TM"); JPanel mainPanel = new JPanel(null); mainPanel.setSize(1000, 600); mainPanel.add(sidePanels); mainPanel.add(mainPanels); mainPanel.add(chatPanel); add(mainPanel, BorderLayout.CENTER); try { setIconImage(ImageIO.read(new File("images/logo.png"))); } catch (IOException exc) { exc.printStackTrace(); } setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(1000, 600); setVisible(true); setResizable(false); chatField.requestFocus(); }
/** * Use the GUI results to set up the variables needed to run the algorithm. * * @return <code>true</code> if parameters set successfully, <code>false</code> otherwise. */ private boolean setVariables() { String tmpStr; System.gc(); if (replaceImage.isSelected()) { displayLoc = REPLACE; } else if (newImage.isSelected()) { displayLoc = NEW; } tmpStr = textSearchWindowSide.getText(); if (testParameter(tmpStr, 5, 101)) { searchWindowSide = Integer.valueOf(tmpStr).intValue(); } else { MipavUtil.displayError("Search window side must be between 5 and 101"); textSearchWindowSide.requestFocus(); textSearchWindowSide.selectAll(); return false; } if ((searchWindowSide % 2) == 0) { MipavUtil.displayError("Search window side must be an odd number"); textSearchWindowSide.requestFocus(); textSearchWindowSide.selectAll(); return false; } tmpStr = textSimilarityWindowSide.getText(); if (testParameter(tmpStr, 3, 99)) { similarityWindowSide = Integer.valueOf(tmpStr).intValue(); } else { MipavUtil.displayError("Similarity window side must be between 3 and 99"); textSimilarityWindowSide.requestFocus(); textSimilarityWindowSide.selectAll(); return false; } if ((similarityWindowSide % 2) == 0) { MipavUtil.displayError("Similarity window side must be an odd number"); textSimilarityWindowSide.requestFocus(); textSimilarityWindowSide.selectAll(); return false; } if (similarityWindowSide >= searchWindowSide) { MipavUtil.displayError("Similarity window side must be less than search window side"); textSimilarityWindowSide.requestFocus(); textSimilarityWindowSide.selectAll(); return false; } tmpStr = textNoiseStandardDeviation.getText(); if (testParameter(tmpStr, 0.001, 1000.0)) { noiseStandardDeviation = Float.valueOf(tmpStr).floatValue(); } else { MipavUtil.displayError("Radius must be between 0.001 and 1000.0"); textNoiseStandardDeviation.requestFocus(); textNoiseStandardDeviation.selectAll(); return false; } doRician = doRicianCheckBox.isSelected(); if (doRician) { tmpStr = textDegree.getText(); if (testParameter(tmpStr, 1.0, 10.0)) { degreeOfFiltering = Float.valueOf(tmpStr).floatValue(); } else { MipavUtil.displayError("Degree of filtering must be between 1.0 and 10.0"); textDegree.requestFocus(); textDegree.selectAll(); } } if (image.getNDims() > 2) { image25D = image25DCheckBox.isSelected(); } return true; }
/** Called when the panel becomes active. */ public void panelActivate() { passwordField.requestFocus(); }
public void setReady() { textField.setEditable(true); textField.requestFocus(); }
/** * Use the GUI results to set up the variables needed to run the algorithm. * * @return <code>true</code> if parameters set successfully, <code>false</code> otherwise. */ private boolean setVariables() { String tmpStr; tmpStr = textXDim.getText(); try { subXDim = Integer.parseInt(tmpStr); } catch (NumberFormatException e) { MipavUtil.displayError("New XDIM string is not a valid integer"); textXDim.requestFocus(); textXDim.selectAll(); return false; } if (subXDim < 3) { MipavUtil.displayError("New XDIM must be at least 3"); textXDim.requestFocus(); textXDim.selectAll(); return false; } else if (subXDim > image.getExtents()[0]) { MipavUtil.displayError("New XDIM cannot exceed " + image.getExtents()[0]); textXDim.requestFocus(); textXDim.selectAll(); return false; } tmpStr = textYDim.getText(); try { subYDim = Integer.parseInt(tmpStr); } catch (NumberFormatException e) { MipavUtil.displayError("New YDIM string is not a valid integer"); textYDim.requestFocus(); textYDim.selectAll(); return false; } if (subYDim < 3) { MipavUtil.displayError("New YDIM must be at least 3"); textYDim.requestFocus(); textYDim.selectAll(); return false; } else if (subYDim > image.getExtents()[1]) { MipavUtil.displayError("New YDIM cannot exceed " + image.getExtents()[1]); textYDim.requestFocus(); textYDim.selectAll(); return false; } tmpStr = textNumberImages.getText(); try { numberOfImagesInMosaic = Integer.parseInt(tmpStr); } catch (NumberFormatException e) { MipavUtil.displayError("New numberOfImagesInMosaic string is not a valid integer"); textNumberImages.requestFocus(); textNumberImages.selectAll(); return false; } if (numberOfImagesInMosaic < 1) { MipavUtil.displayError("New numberOfImagesInMosaic must be at least 1"); textNumberImages.requestFocus(); textNumberImages.selectAll(); return false; } else if (numberOfImagesInMosaic > (subXDim * subYDim)) { MipavUtil.displayError("New numberOfImagesInMosaic cannot exceed (newXDim) * (newYDim)"); textNumberImages.requestFocus(); textNumberImages.selectAll(); return false; } displayLoc = NEW; return true; }