private JPanel getPanelWithTable(ArrayList list, Table element) throws InvalidTemplateException { JTable table = getTable(list, element); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.add(new JScrollPane(table)); for (int j = 0; j < list.size(); j++) { elementsAndPanels.put(list.get(j), panel); } return panel; }
public void setBackground(Color bg) { super.setBackground(bg); if (label != null) { label.setBackground(bg); draw.setBackground(bg); } }
public void setForeground(Color fg) { super.setForeground(fg); if (label != null) { label.setForeground(fg); draw.setForeground(fg); } }
private void initialise() { setSize(180, 120); setLocation(300, 200); setTitle("Working..."); setVisible(false); setModal(true); setResizable(false); setDefaultCloseOperation(0); _stopped = false; getContentPane().setLayout(new BorderLayout()); JPanel topPanel = new JPanel(); topPanel.setLayout(new BorderLayout()); busyTextLabel = new JLabel("Busy - please wait"); topPanel.add(busyTextLabel, "Center"); busyIcon = FTAUtilities.loadImageIcon("busy.gif"); busyIconLabel = new JLabel(busyIcon); topPanel.add(busyIconLabel, "West"); progressBar = new JProgressBar(); topPanel.add(progressBar, "South"); getContentPane().add(topPanel); stopButton = new JButton("Stop"); stopButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // System.out.println("'Stop' button pressed"); _stopped = true; } }); this.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { _stopped = true; } }); // create panel to hold buttons JPanel buttonPanel = new JPanel(new FlowLayout()); buttonPanel.add(stopButton); getContentPane().add(buttonPanel, BorderLayout.SOUTH); }
// 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 MainWindow() { JMenuItem showTextItem, showContentItem, showStatsItem; JMenuItem consoleWinItem, treeWinItem, traceWinItem; // our libgist execution thread opThread = new OpThread(this); Libgist.setBreakHandler(opThread); opThread.start(); cmd = new LibgistCommand(); menuBar = new JMenuBar(); setJMenuBar(menuBar); // create toolbar and console window with text area getContentPane().removeAll(); getContentPane().setLayout(new BorderLayout()); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); // desktop pane + console frame desktop = new JDesktopPane(); desktop.setOpaque(true); desktop.setBackground(Color.lightGray); consoleFrame = new ConsoleWindow(200, desktop); desktop.add(consoleFrame, JLayeredPane.PALETTE_LAYER); // debugging actions for toolbar: // notify opThread of what to do when it hits a breakpoint stepAction = new AbstractAction("Step") { public void actionPerformed(ActionEvent e) { opThread.step(); } }; cancelAction = new AbstractAction("Cancel") { public void actionPerformed(ActionEvent e) { scriptWasCancelled = true; // don't call it after next line! opThread.cancel(); } }; nextAction = new AbstractAction("Next") { public void actionPerformed(ActionEvent e) { opThread.next(); } }; contAction = new AbstractAction("Continue") { public void actionPerformed(ActionEvent e) { opThread.cont(); } }; // opThread is currently executing a script and we want it to stop: // tell libgist directly to suspend execution once opThread is done // with the current operation stopAction = new AbstractAction("Stop") { public void actionPerformed(ActionEvent e) { Libgist.singleStep(); } }; // toolbar JToolBar toolbar = new JToolBar(); toolbar.add(stepAction).setText("Step"); toolbar.add(nextAction).setText("Next"); toolbar.add(contAction).setText("Continue"); toolbar.add(stopAction).setText("Stop"); toolbar.add(cancelAction).setText("Cancel"); panel.add(toolbar, BorderLayout.NORTH); panel.add(desktop, BorderLayout.CENTER); getContentPane().add(panel); createFileMenu(); createOpsMenu(); createDebugMenu(); createTreeStatsMenu(); createAnalysisMenu(); createWindowsMenu(); setGuiState(INITSTATE); // nothing opened yet // addWindowListener(this); // So we do the right thing on window closing. }
/** * Sets up the airplane seating GUI. Adds in all the buttons, keeping a space for the aisle. * * @precondition the button is still clickable */ public void run() { Airplane.aLock.lock(); JFrame manualreservation = new JFrame(); manualreservation.setTitle("Airplane Reservation System"); manualreservation.setPreferredSize(new Dimension(500, 500)); JPanel panel = new JPanel(new GridLayout(50, 5)); JPanel container = new JPanel(); for (int rows = 0; rows < 50; rows++) { for (int columns = 0; columns < 5; columns++) { if (columns == 2) { JButton empty = new JButton(""); empty.setEnabled(false); panel.add(empty); } else { JButton button = new JButton(); if (columns > 2) { button.setText((rows) + "," + (columns - 1)); Airplane.buttons.add(button); } else { button.setText((rows) + "," + (columns)); Airplane.buttons.add(button); } /** * Attached an Action Listener to every button. Sets the clicked button to un-clickable * and updates the button ArrayList and seating array. */ button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent seatselected) { JButton buttonclicked = (JButton) seatselected.getSource(); String[] temp = buttonclicked.getText().split(","); int[] location = new int[temp.length]; for (int i = 0; i < temp.length; i++) { location[i] = Integer.parseInt(temp[i]); } int loc = location[0] * 4 + location[1]; airplane.setSeat(location[0], location[1], 3); buttonclicked.setText("3"); buttonclicked.setEnabled(false); Airplane.buttons.add(buttonclicked); Airplane.buttons.get(loc).setEnabled(false); Airplane.buttons.get(loc).setText("3"); } }); panel.add(button); } } } container.add(panel); JScrollPane jsp = new JScrollPane(container); manualreservation.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); manualreservation.add(jsp); manualreservation.pack(); manualreservation.setVisible(true); Airplane.aLock.unlock(); }