Esempio n. 1
0
  /** GUIコンポーネントを初期化する。 */
  public void initComponent() {

    frame = new JFrame(ClientContext.getFrameTitle(title));
    frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    frame.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
            stop();
          }
        });

    JPanel contentPane = createBrowsePane();
    contentPane.setBorder(BorderFactory.createEmptyBorder(12, 12, 11, 11));

    contentPane.setOpaque(true);
    frame.setContentPane(contentPane);
    frame.pack();

    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    int n = ClientContext.isMac() ? 3 : 2;
    int x = (screen.width - frame.getPreferredSize().width) / 2;
    int y = (screen.height - frame.getPreferredSize().height) / n;
    frame.setLocation(x, y);

    blockGlass = new BlockGlass();
    frame.setGlassPane(blockGlass);

    frame.setVisible(true);
  }
Esempio n. 2
0
  // 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);
  }