void jbInit() throws Exception { titledBorder1 = new TitledBorder( BorderFactory.createLineBorder(new Color(153, 153, 153), 2), "Assembler messages"); this.getContentPane().setLayout(borderLayout1); this.setIconifiable(true); this.setMaximizable(true); this.setResizable(true); this.setTitle("EDIT"); splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); splitPane.setDividerLocation(470); sourceArea.setFont(new java.awt.Font("Monospaced", 0, 12)); controlPanel.setLayout(gridBagLayout1); controlPanel.setBorder(BorderFactory.createLoweredBevelBorder()); positionPanel.setLayout(gridBagLayout2); fileLabel.setText("Source file:"); fileText.setEditable(false); browseButton.setSelected(false); browseButton.setText("Browse ..."); assembleButton.setEnabled(false); assembleButton.setText("Assemble file"); saveButton.setEnabled(false); saveButton.setText("Save file"); lineLabel.setText("Line:"); lineText.setMinimumSize(new Dimension(50, 20)); lineText.setPreferredSize(new Dimension(50, 20)); lineText.setEditable(false); columnLabel.setText("Column:"); columnText.setMinimumSize(new Dimension(41, 20)); columnText.setPreferredSize(new Dimension(41, 20)); columnText.setEditable(false); columnText.setText(""); messageScrollPane.setBorder(titledBorder1); messageScrollPane.setMinimumSize(new Dimension(33, 61)); messageScrollPane.setPreferredSize(new Dimension(60, 90)); optionsButton.setEnabled(false); optionsButton.setText("Assembler options ..."); messageScrollPane.getViewport().add(messageList, null); messageList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); this.getContentPane().add(splitPane, BorderLayout.CENTER); splitPane.add(textScrollPane, JSplitPane.TOP); splitPane.add(controlPanel, JSplitPane.BOTTOM); textScrollPane.getViewport().add(sourceArea, null); controlPanel.add( fileLabel, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 0), 0, 0)); controlPanel.add( fileText, new GridBagConstraints( 1, 0, 3, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 0), 0, 0)); controlPanel.add( browseButton, new GridBagConstraints( 4, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 5), 0, 0)); controlPanel.add( optionsButton, new GridBagConstraints( 2, 1, 1, 1, 1.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 0), 0, 0)); controlPanel.add( assembleButton, new GridBagConstraints( 3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 0), 0, 0)); controlPanel.add( saveButton, new GridBagConstraints( 4, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 5), 0, 0)); controlPanel.add( positionPanel, new GridBagConstraints( 0, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 0, 0), 0, 0)); positionPanel.add( lineLabel, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); positionPanel.add( lineText, new GridBagConstraints( 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0)); positionPanel.add( columnLabel, new GridBagConstraints( 2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 10, 0, 0), 0, 0)); positionPanel.add( columnText, new GridBagConstraints( 3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0)); controlPanel.add( messageScrollPane, new GridBagConstraints( 0, 2, 5, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); }
/** Install the Rotate-Button into the toolbar */ private void installRotateButton() { URL imgURL = ClassLoader.getSystemResource("ch/tbe/pics/rotate.gif"); ImageIcon rotateIcon = new ImageIcon(imgURL); rotate = new JButton(rotateIcon); rotate.setEnabled(false); rotatePanel = new JToolBar(); rotatePanel.setOrientation(1); rotatePanel.setLayout(new BorderLayout(0, 1)); rotateSlider = new JSlider(); rotateSlider.setMaximum(359); rotateSlider.setMinimum(0); rotateSlider.setMaximumSize(new Dimension(100, 100)); rotateSlider.setOrientation(1); Box box = Box.createVerticalBox(); sliderValue.setPreferredSize(new Dimension(30, 20)); rotateSlider.setAlignmentY(Component.TOP_ALIGNMENT); box.add(sliderValue); box.add(rotateSlider); sliderValue.setAlignmentY(Component.TOP_ALIGNMENT); rotatePanel.add(box, BorderLayout.NORTH); sliderValue.addFocusListener( new FocusListener() { private int oldValue = 0; public void focusGained(FocusEvent arg0) { oldValue = Integer.parseInt(sliderValue.getText()); } public void focusLost(FocusEvent arg0) { int newValue = 0; try { newValue = Integer.parseInt(sliderValue.getText()); } catch (Exception ex) { sliderValue.setText(Integer.toString(oldValue)); } if (newValue >= 0 && newValue <= 359) { RotateCommand rc = new RotateCommand(board.getSelectedItems()); ArrayList<Command> actCommands = new ArrayList<Command>(); actCommands.add(rc); TBE.getInstance().addCommands(actCommands); rotateSlider.setValue(newValue); } else { sliderValue.setText(Integer.toString(oldValue)); } } }); rotateSlider.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent arg0) { if (board.getSelectionCount() == 1 && board.getSelectionCells()[0] instanceof ShapeItem) { sliderValue.setText(Integer.toString(rotateSlider.getValue())); ShapeItem s = (ShapeItem) board.getSelectionCells()[0]; board.removeItem(new ItemComponent[] {s}); s.setRotation(rotateSlider.getValue()); board.addItem(s); } } }); rotateSlider.addMouseListener( new MouseAdapter() { private int value; public void mousePressed(MouseEvent e) { value = rotateSlider.getValue(); } public void mouseReleased(MouseEvent e) { if (value != rotateSlider.getValue()) { RotateCommand rc = new RotateCommand(board.getSelectedItems()); ArrayList<Command> actCommands = new ArrayList<Command>(); actCommands.add(rc); TBE.getInstance().addCommands(actCommands); rc.setRotation(value); } } }); rotate.setToolTipText(workingViewLabels.getString("rotate")); rotate.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (board.getSelectionCount() == 1 && board.getSelectedItems()[0] instanceof ShapeItem) { rotateSlider.setValue(((ShapeItem) board.getSelectedItems()[0]).getRotation()); } rotatePanel.setVisible(!rotatePanel.isVisible()); showRotate = !showRotate; } }); rotate.setContentAreaFilled(false); rotate.setBorderPainted(false); toolbar.add(rotate); rotatePanel.setVisible(false); this.add(rotatePanel, BorderLayout.EAST); }
/** Instantiates a new game panel. */ public GamePanel() { super(); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); CARD_BACK.add(new CardPanel("img/cards/BACK.png")); // The code below is just for reference // dealerCards = new ArrayList<>(); // for (int i = 0; i < dealerInHand.size(); i++) // { // dealerCards.add(new CardPanel("img/cards/" + dealerInHand.get(i) + ".png")); // } // // playerCardsOne = new ArrayList<>(); // for (int i = 0; i < playerInHandOne.size(); i++) // { // playerCardsOne.add(new CardPanel("img/cards/" + playerInHandOne.get(i) + ".png")); // } // // playerCardsTwo = new ArrayList<>(); // for (int i = 0; i < playerInHandTwo.size(); i++) // { // playerCardsTwo.add(new CardPanel("img/cards/" + playerInHandTwo.get(i) + ".png")); // } // The code above is just for reference dealerDeckContainer = new CardDeckContainer(); dealerStatContainer = new JPanel(new BorderLayout()); dealerStatContainer.setOpaque(false); JLabel dealerStatTitle = new JLabel("Dealer in Hand"); dealerStatTitle.setForeground(Color.WHITE); dealerStatTitle.setHorizontalAlignment(JLabel.CENTER); dealerStatTitle.setFont(new Font("", Font.PLAIN, 12)); dealerStatPoint.setForeground(Color.WHITE); dealerStatPoint.setHorizontalAlignment(JLabel.CENTER); dealerStatPoint.setFont(new Font("", Font.PLAIN, 12)); dealerStatContainer.add(dealerStatTitle, BorderLayout.NORTH); dealerStatContainer.add(dealerStatPoint, BorderLayout.CENTER); playerDeckOneContainer = new CardDeckContainer(); playerStatOneContainer = new JPanel(new BorderLayout()); playerStatOneContainer.setOpaque(false); JLabel playerStatOneTitle = new JLabel("Player in Hand"); playerStatOneTitle.setForeground(Color.WHITE); playerStatOneTitle.setHorizontalAlignment(JLabel.CENTER); playerStatOneTitle.setFont(new Font("", Font.PLAIN, 12)); playerStatOnePoint.setForeground(Color.WHITE); playerStatOnePoint.setHorizontalAlignment(JLabel.CENTER); playerStatOnePoint.setFont(new Font("", Font.PLAIN, 12)); playerStatOneDescription.setForeground(Color.WHITE); playerStatOneDescription.setHorizontalAlignment(JLabel.CENTER); playerStatOneDescription.setFont(new Font("", Font.BOLD, 12)); playerStatOneContainer.add(playerStatOneTitle, BorderLayout.NORTH); playerStatOneContainer.add(playerStatOnePoint, BorderLayout.CENTER); playerStatOneContainer.add(playerStatOneDescription, BorderLayout.SOUTH); playerDeckTwoContainer = new CardDeckContainer(new CardDeckPanel(CARD_BACK)); playerStatTwoContainer = new JPanel(new BorderLayout()); playerStatTwoContainer.setOpaque(false); JLabel playerStatTwoTitle = new JLabel("Player Hand 2"); playerStatTwoTitle.setForeground(Color.WHITE); playerStatTwoTitle.setHorizontalAlignment(JLabel.CENTER); playerStatTwoTitle.setFont(new Font("", Font.PLAIN, 12)); playerStatTwoPoint.setForeground(Color.WHITE); playerStatTwoPoint.setHorizontalAlignment(JLabel.CENTER); playerStatTwoPoint.setFont(new Font("", Font.PLAIN, 12)); playerStatTwoDescription.setForeground(Color.WHITE); playerStatTwoDescription.setHorizontalAlignment(JLabel.CENTER); playerStatTwoDescription.setFont(new Font("", Font.BOLD, 12)); playerStatTwoContainer.add(playerStatTwoTitle, BorderLayout.NORTH); playerStatTwoContainer.add(playerStatTwoPoint, BorderLayout.CENTER); playerStatTwoContainer.add(playerStatTwoDescription, BorderLayout.SOUTH); gameStatPanel = new JPanel(); gameStatPanelPlayerName = new JLabel(); gameStatPanelCurrentChips = new JLabel(); gameStatPanelCurrentBet = new JLabel(); gameStatPanelPlayerName.setFont(new Font("", Font.PLAIN, 14)); gameStatPanelPlayerName.setForeground(Color.WHITE); gameStatPanelPlayerName.setBorder(new EmptyBorder(0, 0, 0, 5)); gameStatPanelCurrentChips.setFont(new Font("", Font.PLAIN, 14)); gameStatPanelCurrentChips.setForeground(Color.WHITE); gameStatPanelCurrentChips.setBorder(new EmptyBorder(0, 5, 0, 5)); gameStatPanelCurrentBet.setFont(new Font("", Font.PLAIN, 14)); gameStatPanelCurrentBet.setForeground(Color.WHITE); gameStatPanelCurrentBet.setBorder(new EmptyBorder(0, 5, 0, 0)); gameStatPanel.add(gameStatPanelPlayerName); gameStatPanel.add(gameStatPanelCurrentChips); gameStatPanel.add(gameStatPanelCurrentBet); gameStatPanel.setOpaque(false); gameButtonPanel = new JPanel(cardLayout); betButtonPanel = new JPanel(); playButtonPanel = new JPanel(); JLabel pleaseBet = new JLabel("Please bet: "); pleaseBet.setFont(new Font("", Font.PLAIN, 14)); pleaseBet.setForeground(Color.WHITE); betButtonPanel.add(pleaseBet); betField = new JTextField(); betField.setFont(new Font("", Font.PLAIN, 14)); betField.setPreferredSize(new Dimension(80, 28)); betButtonPanel.add(betField); JButton betButton = new JButton("Bet"); JButton backButton = new JButton("Back"); betButtonPanel.add(betButton); betButtonPanel.add(backButton); betButtonPanel.setOpaque(false); hitButton = new JButton("Hit"); standButton = new JButton("Stand"); doubleButton = new JButton("Double"); // JButton splitButton = new JButton("Split"); // splitButton.setEnabled(false); playButtonPanel.add(hitButton); playButtonPanel.add(standButton); playButtonPanel.add(doubleButton); // playButtonPanel.add(splitButton); playButtonPanel.setOpaque(false); gameButtonPanel.add("betbutton", betButtonPanel); gameButtonPanel.add("playbutton", playButtonPanel); gameButtonPanel.setOpaque(false); add(gameStatPanel); add(dealerDeckContainer); add(playerDeckTwoContainer); add(playerDeckOneContainer); add(gameButtonPanel); this.addComponentListener( new ComponentAdapter() { @Override public void componentShown(ComponentEvent e) { Game.initGame(); } }); betButtonPanel.addComponentListener( new ComponentAdapter() { @Override public void componentShown(ComponentEvent e) { betField.setText(""); if (BlackJack.player.getChip() <= 0) { JOptionPane.showMessageDialog( null, "You are penniless!", "Information", JOptionPane.INFORMATION_MESSAGE); User.deleteUserByName(BlackJack.player.getName()); BlackJack.player = new Player(true); BlackJack.dealer = new Player(false); BlackjackFrame.cardLayout.show(getParent(), "welcome"); } hitButton.setEnabled(true); standButton.setEnabled(true); doubleButton.setEnabled(true); BlackJack.player.setBet(0); BlackJack.player.getHandOne().clear(); BlackJack.player.getHandTwo().clear(); BlackJack.dealer.getHandOne().clear(); GamePanel.gameStatPanelPlayerName.setText("Player: " + BlackJack.player.getName()); GamePanel.gameStatPanelCurrentChips.setText("Chips: " + BlackJack.player.getChip()); GamePanel.gameStatPanelCurrentBet.setText("Bet: 0"); GamePanel.gameStatPanel.repaint(); } }); betField.addKeyListener( new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { int keyChar = e.getKeyChar(); if (keyChar < KeyEvent.VK_0 || keyChar > KeyEvent.VK_9) { e.consume(); } } }); betButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Game.bet(Integer.parseInt(betField.getText())); } }); backButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int choice = JOptionPane.showConfirmDialog( null, "Do you want to go back to main menu?\nYour record will be saved.", "Go Back", JOptionPane.YES_NO_OPTION); if (choice == JOptionPane.YES_OPTION) { User.updateUser(); BlackJack.player = new Player(true); BlackJack.dealer = new Player(false); BlackjackFrame.cardLayout.show(getParent(), "welcome"); } } }); hitButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doubleButton.setEnabled(false); Game.hit(); } }); standButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { hitButton.setEnabled(false); standButton.setEnabled(false); doubleButton.setEnabled(false); playerStatOneDescription.setText("Stand"); playerStatOneDescription.repaint(); Game.dealerGame(); } }); doubleButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { hitButton.setEnabled(false); standButton.setEnabled(false); doubleButton.setEnabled(false); if (!Game.doubleDown()) { hitButton.setEnabled(true); standButton.setEnabled(true); doubleButton.setEnabled(false); } } }); }
void jbInit() throws Exception { panel1.setLayout(borderLayout1); jPanel1.setBorder(BorderFactory.createEtchedBorder()); jPanel1.setPreferredSize(new Dimension(14, 100)); jPanel1.setLayout(borderLayout2); jPanel2.setBorder(BorderFactory.createEtchedBorder()); jPanel2.setPreferredSize(new Dimension(10, 40)); jPanel2.setLayout(gridBagLayout1); jLabel2.setText("Oznaka banke:"); bPronadji.setPreferredSize(new java.awt.Dimension(80, 27)); bPronadji.setText("Pronadji "); bPronadji.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { bPronadji_actionPerformed(e); } }); bIzlaz.setPreferredSize(new Dimension(80, 27)); bIzlaz.setText("Izlaz"); bIzlaz.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { bIzlaz_actionPerformed(e); } }); txtOznakaBanke.setPreferredSize(new Dimension(120, 21)); getContentPane().add(panel1); panel1.add(jPanel1, BorderLayout.NORTH); { jLabel1 = new JLabel(); jPanel1.add(jLabel1, BorderLayout.CENTER); jLabel1.setText("PREGLED FILIJALA BANKE"); jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 18)); jLabel1.setPreferredSize(new java.awt.Dimension(588, 96)); jLabel1.setHorizontalTextPosition(SwingConstants.CENTER); jLabel1.setHorizontalAlignment(SwingConstants.CENTER); jLabel1.setVerticalAlignment(SwingConstants.TOP); { jLabel3 = new JLabel(); jLabel1.add(jLabel3); jLabel3.setText("NAZIV:"); jLabel3.setBounds(7, 49, 42, 28); jLabel3.setFont(new java.awt.Font("Times New Roman", 1, 12)); } { jLabel4 = new JLabel(); jLabel1.add(jLabel4); jLabel4.setText("ADRESA:"); jLabel4.setBounds(280, 49, 63, 28); jLabel4.setFont(new java.awt.Font("Times New Roman", 1, 12)); } { jLnazivBanke = new JLabel(); jLabel1.add(jLnazivBanke); jLnazivBanke.setBounds(56, 49, 203, 28); } { jLadresaBanke = new JLabel(); jLabel1.add(jLadresaBanke); jLadresaBanke.setBounds(336, 49, 238, 28); } } panel1.add(jPanel2, BorderLayout.SOUTH); jPanel2.add( jLabel2, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jPanel2.add( txtOznakaBanke, new GridBagConstraints( 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 10, 0, 0), 0, 0)); jPanel2.add( bPronadji, new GridBagConstraints( 5, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 10, 0, 0), 0, 0)); jPanel2.add( bIzlaz, new GridBagConstraints( 5, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 200, 0, 0), 0, 0)); panel1.add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.getViewport().add(tabBanke, null); TModelPrijave tMP = new TModelPrijave(tabBanke); tabBanke.setModel(tMP); ((TModelPrijave) tabBanke.getModel()).initColumns(); }
/** * Open the config dialog, send the config update to the robot, save it for future, and refresh * the preview tab. */ public void UpdateConfig() { final JDialog driver = new JDialog(mainframe, "Configure Limits", true); driver.setLayout(new GridBagLayout()); final JTextField mtop = new JTextField(String.valueOf(limit_top)); final JTextField mbottom = new JTextField(String.valueOf(limit_bottom)); final JTextField mleft = new JTextField(String.valueOf(limit_left)); final JTextField mright = new JTextField(String.valueOf(limit_right)); final JTextField ptop = new JTextField(String.valueOf(paper_top)); final JTextField pbottom = new JTextField(String.valueOf(paper_bottom)); final JTextField pleft = new JTextField(String.valueOf(paper_left)); final JTextField pright = new JTextField(String.valueOf(paper_right)); final JButton cancel = new JButton("Cancel"); final JButton save = new JButton("Save"); GridBagConstraints c = new GridBagConstraints(); c.gridx = 3; c.gridy = 0; driver.add(mtop, c); c.gridx = 3; c.gridy = 5; driver.add(mbottom, c); c.gridx = 0; c.gridy = 3; driver.add(mleft, c); c.gridx = 5; c.gridy = 3; driver.add(mright, c); c.gridx = 3; c.gridy = 1; driver.add(ptop, c); c.gridx = 3; c.gridy = 4; driver.add(pbottom, c); c.gridx = 1; c.gridy = 3; driver.add(pleft, c); c.gridx = 4; c.gridy = 3; driver.add(pright, c); c.gridx = 4; c.gridy = 6; driver.add(save, c); c.gridx = 5; c.gridy = 6; driver.add(cancel, c); Dimension s = ptop.getPreferredSize(); s.width = 80; ptop.setPreferredSize(s); pbottom.setPreferredSize(s); pleft.setPreferredSize(s); pright.setPreferredSize(s); mtop.setPreferredSize(s); mbottom.setPreferredSize(s); mleft.setPreferredSize(s); mright.setPreferredSize(s); ActionListener driveButtons = new ActionListener() { public void actionPerformed(ActionEvent e) { Object subject = e.getSource(); if (subject == save) { paper_top = Float.valueOf(ptop.getText()); paper_bottom = Float.valueOf(pbottom.getText()); paper_right = Float.valueOf(pright.getText()); paper_left = Float.valueOf(pleft.getText()); limit_top = Float.valueOf(mtop.getText()); limit_bottom = Float.valueOf(mbottom.getText()); limit_right = Float.valueOf(mright.getText()); limit_left = Float.valueOf(mleft.getText()); previewPane.setMachineLimits(limit_top, limit_bottom, limit_left, limit_right); previewPane.setPaperSize(paper_top, paper_bottom, paper_left, paper_right); SetRecentPaperSize(); SaveConfig(); SendConfig(); driver.dispose(); } if (subject == cancel) { driver.dispose(); } } }; save.addActionListener(driveButtons); cancel.addActionListener(driveButtons); SendLineToRobot("M114"); // "where" command driver.pack(); driver.setVisible(true); }
public ChatClient() { super(APPNAME); JPanel topPanel = new JPanel(); JPanel leftPanel = new JPanel(); JPanel buttomPanel = new JPanel(); JPanel roomPanel = new JPanel(); JPanel userPanel = new JPanel(); roomList = new JList(); userList = new JList(); msgTextArea = new JTextArea(); msgTextField = new JTextField(); nameTextField = new JTextField(); submitButton = new JButton("送信"); renameButton = new JButton("名前の変更"); addRoomButton = new JButton("部屋を追加"); enterRoomButton = new JButton("入室"); submitButton.addActionListener(this); submitButton.setActionCommand("submit"); renameButton.addActionListener(this); renameButton.setActionCommand("rename"); addRoomButton.addActionListener(this); addRoomButton.setActionCommand("addRoom"); enterRoomButton.addActionListener(this); enterRoomButton.setActionCommand("enterRoom"); roomPanel.setLayout(new BorderLayout()); roomPanel.add(new JLabel("チャットルーム"), BorderLayout.NORTH); roomPanel.add(new JScrollPane(roomList), BorderLayout.CENTER); roomPanel.add(enterRoomButton, BorderLayout.SOUTH); userPanel.setLayout(new BorderLayout()); userPanel.add(new JLabel("参加ユーザー"), BorderLayout.NORTH); userPanel.add(new JScrollPane(userList), BorderLayout.CENTER); topPanel.setLayout(new FlowLayout()); topPanel.add(new JLabel("名前")); topPanel.add(nameTextField); topPanel.add(renameButton); topPanel.add(addRoomButton); nameTextField.setPreferredSize(new Dimension(200, nameTextField.getPreferredSize().height)); leftPanel.setLayout(new GridLayout(2, 1)); leftPanel.add(roomPanel); leftPanel.add(userPanel); buttomPanel.setLayout(new BorderLayout()); buttomPanel.add(msgTextField, BorderLayout.CENTER); buttomPanel.add(submitButton, BorderLayout.EAST); // テキストエリアはメッセージを表示するだけなので編集不可に設定 msgTextArea.setEditable(false); // コンポーネントの状態を退室状態で初期化 exitedRoom(); this.getContentPane().add(new JScrollPane(msgTextArea), BorderLayout.CENTER); this.getContentPane().add(topPanel, BorderLayout.NORTH); this.getContentPane().add(leftPanel, BorderLayout.WEST); this.getContentPane().add(buttomPanel, BorderLayout.SOUTH); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { try { close(); } catch (Exception err) { } } }); connectServer(); // メッセージ受信監視用のスレッドを生成してスタートさせる thread = new Thread(this); thread.start(); // 現在の部屋を取得する sendMessage("getRooms"); }