/** 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(); } }
// Function use to Clear all TextFields of Window. void txtClear() { txtNo.setText(""); txtName.setText(""); txtDate.setText(""); txtBal.setText(""); txtNo.requestFocus(); }
// Function use By Buttons of Window to Perform Action as User Click Them. public void actionPerformed(ActionEvent ae) { Object obj = ae.getSource(); if (obj == btnDel) { if (txtNo.getText().equals("")) { JOptionPane.showMessageDialog( this, "Please! Provide Id of Customer.", "BankSystem - EmptyField", JOptionPane.PLAIN_MESSAGE); txtNo.requestFocus(); } else { deletion(); // Confirm Deletion of Current Record. } } if (obj == btnCancel) { txtClear(); setVisible(false); dispose(); } }
// 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(); }
public void setReady() { textField.setEditable(true); textField.requestFocus(); }