示例#1
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);
  }
示例#2
0
  public LicenseDialog(Component parent) {
    setTitle("Licensing information");

    pnlButtons.add(bttnOk);

    cbLang.addItem("English");
    cbLang.addItem("Eesti");

    FlowLayout fl = new FlowLayout();
    fl.setAlignment(FlowLayout.LEFT);

    pnlHeader.setLayout(fl);

    pnlHeader.add(lblLang);
    pnlHeader.add(cbLang);

    pnlMain.setLayout(new BorderLayout());
    pnlMain.add(pnlHeader, BorderLayout.NORTH);
    pnlMain.add(scrollPane, BorderLayout.CENTER);
    pnlMain.add(pnlButtons, BorderLayout.SOUTH);

    taLicenseText.setText(getLicenseText());
    taLicenseText.setCaretPosition(0);
    taLicenseText.setLineWrap(true);
    taLicenseText.setEditable(false);
    taLicenseText.setWrapStyleWord(true);

    getContentPane().add(pnlMain);
    setPreferredSize(new Dimension(500, 600));
    setLocationRelativeTo(parent);

    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    bttnOk.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            if (evt.getSource() == bttnOk) {
              dispose();
            }
          } // end actionPerformed
        }); // end bttnOk Action Listener

    cbLang.addItemListener(
        new ItemListener() {
          public void itemStateChanged(final ItemEvent event) {
            if (event.getSource() == cbLang
                && event.getStateChange() == ItemEvent.SELECTED
                && cbLang.getItemCount() > 0) {
              taLicenseText.setText(getLicenseText());
              taLicenseText.setCaretPosition(0);
            }
          }
        }); // end cbLang item listener

    pack();
    setVisible(true);
  } // PortPropertiesDialog
示例#3
0
  /**
   * Méthode de création du panelInit
   *
   * @return
   */
  private JPanel createPanelInit() {

    JPanel panRight = new JPanel();
    panRight.setLayout(new BoxLayout(panRight, BoxLayout.Y_AXIS));

    butListParty = new JButton("Liste des parties");
    butListParty.addActionListener(this);

    JPanel panCreate = new JPanel();
    panCreate.setLayout(new BoxLayout(panCreate, BoxLayout.X_AXIS));
    textCreate = new JTextField("", 40);
    textCreate.setMaximumSize(textCreate.getPreferredSize());
    butCreateParty = new JButton("Creation de parties ");
    butCreateParty.addActionListener(this);
    SpinnerModel model = new SpinnerNumberModel(3, 2, 8, 1);
    spinNbPlayer = new JSpinner(model);
    spinNbPlayer.setMaximumSize(spinNbPlayer.getPreferredSize());
    panCreate.add(new JLabel("Nouveau nom de partie : "));
    panCreate.add(textCreate);
    panCreate.add(Box.createHorizontalStrut(20));
    panCreate.add(new JLabel("Nombres de joueurs : "));
    panCreate.add(spinNbPlayer);
    panCreate.add(butCreateParty);

    JPanel panJoin = new JPanel();
    panJoin.setLayout(new BoxLayout(panJoin, BoxLayout.X_AXIS));
    textJoin = new JTextField("", 2);
    textJoin.setMaximumSize(textJoin.getPreferredSize());
    butJoinParty = new JButton("Rejoindre la partie ");
    butJoinParty.addActionListener(this);
    panJoin.add(new JLabel("Num Partie : "));
    panJoin.add(textJoin);
    panJoin.add(butJoinParty);

    panRight.add(butListParty);
    panRight.add(panCreate);
    panRight.add(panJoin);
    panRight.add(Box.createVerticalGlue());

    textInfoInit = new JTextArea(20, 100);
    textInfoInit.setLineWrap(true);

    JScrollPane scroll =
        new JScrollPane(
            textInfoInit,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    JPanel panAll = new JPanel();
    panAll.setLayout(new BoxLayout(panAll, BoxLayout.X_AXIS));
    panAll.add(scroll);
    panAll.add(panRight);

    return panAll;
  }
示例#4
0
 /*
  * Creates the JTextArea for the GUI with the ScrollPane.
  */
 private JScrollPane responseArea() {
   responseArea = new JTextArea();
   responseArea.setSize(10, 10);
   responseArea.setLineWrap(true);
   responseArea.setWrapStyleWord(true);
   scrollPane =
       new JScrollPane(
           responseArea,
           ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
           ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
   return scrollPane;
 }
示例#5
0
 void addTextArea(JPanel panel, String key, String label) {
   JLabel lab = new JLabel(label);
   lab.setAlignmentX(LEFT_ALIGNMENT);
   panel.add(lab);
   JTextArea field = new JTextArea();
   field.setText(sketch.configFile.get(key));
   field.setLineWrap(true);
   field.setWrapStyleWord(true);
   fields.put(key, field);
   JScrollPane scroll = new JScrollPane(field);
   scroll.setAlignmentX(0.0f);
   panel.add(scroll);
 }
示例#6
0
  /**
   * Creates a new instance of ListInputPanel with initialized components.
   *
   * @param file_parser An object that can bring up a file chooser, parse selected files and append
   *     the extracted contents to this object's text area. The Load button is disabled if this is
   *     null.
   */
  public ListInputPanel(ListInputParser file_parser) {
    // Call superclass constructor
    super(new BorderLayout(4, 4));

    // Store the file parser
    this.file_parser = file_parser;

    // Initialize layout settings
    int horizontal_gap = 4;
    int vertical_gap = 4;

    // Set up the button panel and attach action listeners to the buttons
    JPanel button_panel = new JPanel(new GridLayout(1, 4));
    load_button = new JButton("Load");
    save_button = new JButton("Save");
    clear_button = new JButton("Clear");
    organize_button = new JButton("Organize");
    button_panel.add(load_button);
    button_panel.add(save_button);
    button_panel.add(clear_button);
    button_panel.add(organize_button);
    save_button.addActionListener(this);
    load_button.addActionListener(this);
    clear_button.addActionListener(this);
    organize_button.addActionListener(this);

    // Disable the load button if appropriate
    if (file_parser == null) load_button.setEnabled(false);

    // Prepare text_area
    text_area = new JTextArea();
    text_area.setLineWrap(false);
    text_area.setEditable(true);
    text_area.setText("");

    // Make scrollable
    JScrollPane scroll_pane = new JScrollPane(text_area);

    // Add contents to this JPanel
    add(button_panel, BorderLayout.NORTH);
    add(scroll_pane, BorderLayout.CENTER);
  }
示例#7
0
  /**
   * Méthode de création du panel de Jeu
   *
   * @return
   */
  private JPanel createPanelPlay() {

    JPanel panAll = new JPanel(new BorderLayout());

    textInfoParty = new JTextArea(20, 100);
    textInfoParty.setLineWrap(true);
    JScrollPane scroll =
        new JScrollPane(
            textInfoParty,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

    JPanel panPlay = new JPanel();
    textPlay = new JTextField("", 5);
    textPlay.setMaximumSize(textPlay.getPreferredSize());
    butPlay = new JButton("Jouer");
    butPlay.addActionListener(this);
    panPlay.add(new JLabel("Ordre :  "));
    panPlay.add(textPlay);
    enableOrder(false);
    JPanel panRight = new JPanel(new BorderLayout());
    panRight.add(panPlay, BorderLayout.CENTER);
    panRight.add(butPlay, BorderLayout.SOUTH);

    JPanel panMain = new JPanel();
    panMain.add(scroll);
    panMain.add(panRight);

    butQuit = new JButton("Quitter");
    butQuit.addActionListener(this);

    panAll.add(panMain, BorderLayout.CENTER);
    panAll.add(butQuit, BorderLayout.SOUTH);

    return panAll;
  }
示例#8
0
  /** Creates the GUI. */
  public void majorLayout() {
    //
    // Setup Menu
    //
    JMenuBar menuBar = new JMenuBar();
    JMenu file = new JMenu(ResourceHandler.getMessage("menu.file"));
    file.setMnemonic(ResourceHandler.getAcceleratorKey("menu.file"));

    file.add(exitMenuItem = new JMenuItem(ResourceHandler.getMessage("menu.exit")));
    exitMenuItem.setMnemonic(ResourceHandler.getAcceleratorKey("menu.exit"));
    exitMenuItem.addActionListener(this);
    menuBar.add(file);

    JMenu edit = new JMenu(ResourceHandler.getMessage("menu.edit"));
    edit.setMnemonic(ResourceHandler.getAcceleratorKey("menu.edit"));

    edit.add(optionMenuItem = new JMenuItem(ResourceHandler.getMessage("menu.option")));
    optionMenuItem.setMnemonic(ResourceHandler.getAcceleratorKey("menu.option"));
    optionMenuItem.addActionListener(this);
    menuBar.add(edit);

    JMenu help = new JMenu(ResourceHandler.getMessage("menu.help"));
    help.setMnemonic(ResourceHandler.getAcceleratorKey("menu.help"));

    help.add(helpMenuItem = new JMenuItem(ResourceHandler.getMessage("menu.help")));
    helpMenuItem.setMnemonic(ResourceHandler.getAcceleratorKey("menu.help"));

    help.add(new JSeparator());
    help.add(aboutMenuItem = new JMenuItem(ResourceHandler.getMessage("menu.about")));
    aboutMenuItem.setMnemonic(ResourceHandler.getAcceleratorKey("menu.about"));
    helpMenuItem.addActionListener(this);
    aboutMenuItem.addActionListener(this);
    menuBar.add(help);

    setJMenuBar(menuBar);

    //
    // Setup main GUI
    //

    dirLabel = new JLabel(ResourceHandler.getMessage("converter_gui.lablel0"));
    dirTF = new JTextField();
    dirBttn = new JButton(ResourceHandler.getMessage("button.browse.dir"));
    dirBttn.setMnemonic(ResourceHandler.getAcceleratorKey("button.browse.dir"));

    matchingLabel = new JLabel(ResourceHandler.getMessage("converter_gui.lablel1"));
    matchingTF = new JTextField(ResourceHandler.getMessage("converter_gui.lablel2"));
    recursiveCheckBox = new JCheckBox(ResourceHandler.getMessage("converter_gui.lablel3"));
    recursiveCheckBox.setMnemonic(ResourceHandler.getAcceleratorKey("converter_gui.lablel3"));

    backupLabel = new JLabel(ResourceHandler.getMessage("converter_gui.lablel5"));
    backupTF = new JTextField();
    backupBttn = new JButton(ResourceHandler.getMessage("button.browse.backup"));
    backupBttn.setMnemonic(ResourceHandler.getAcceleratorKey("button.browse.backup"));

    templateLabel = new JLabel(ResourceHandler.getMessage("converter_gui.lablel7"));
    templateCh = new TemplateFileChoice();

    staticVersioningLabel = new JLabel(ResourceHandler.getMessage("static.versioning.label"));
    String version = System.getProperty("java.version");
    if (version.indexOf("-") > 0) {
      version = version.substring(0, version.indexOf("-"));
    }
    int dotIndex = version.indexOf(".");
    dotIndex = version.indexOf(".", dotIndex + 1);
    String familyVersion = version.substring(0, dotIndex);

    MessageFormat formatter =
        new MessageFormat(ResourceHandler.getMessage("static.versioning.radio.button"));
    staticVersioningRadioButton = new JRadioButton(formatter.format(new Object[] {version}));
    staticVersioningRadioButton.setMnemonic(
        ResourceHandler.getAcceleratorKey("static.versioning.radio.button"));

    formatter = new MessageFormat(ResourceHandler.getMessage("dynamic.versioning.radio.button"));
    dynamicVersioningRadioButton = new JRadioButton(formatter.format(new Object[] {familyVersion}));
    dynamicVersioningRadioButton.setMnemonic(
        ResourceHandler.getAcceleratorKey("dynamic.versioning.radio.button"));

    staticVersioningTextArea = new JTextArea(ResourceHandler.getMessage("static.versioning.text"));

    formatter = new MessageFormat(ResourceHandler.getMessage("dynamic.versioning.text"));
    dynamicVersioningTextArea = new JTextArea(formatter.format(new Object[] {familyVersion}));

    ButtonGroup versioningButtonGroup = new ButtonGroup();
    versioningButtonGroup.add(staticVersioningRadioButton);
    versioningButtonGroup.add(dynamicVersioningRadioButton);

    runBttn = new JButton(ResourceHandler.getMessage("button.convert"));
    runBttn.setMnemonic(ResourceHandler.getAcceleratorKey("button.convert"));

    recursiveCheckBox.setOpaque(false);
    staticVersioningRadioButton.setOpaque(false);
    dynamicVersioningRadioButton.setOpaque(false);

    staticVersioningTextArea.setEditable(false);
    staticVersioningTextArea.setLineWrap(true);
    staticVersioningTextArea.setWrapStyleWord(true);
    dynamicVersioningTextArea.setEditable(false);
    dynamicVersioningTextArea.setLineWrap(true);
    dynamicVersioningTextArea.setWrapStyleWord(true);

    staticVersioningPanel.setLayout(new BorderLayout());
    staticVersioningPanel.add(staticVersioningTextArea, "Center");
    staticVersioningPanel.setBorder(new LineBorder(Color.black));

    dynamicVersioningPanel.setLayout(new BorderLayout());
    dynamicVersioningPanel.add(dynamicVersioningTextArea, "Center");
    dynamicVersioningPanel.setBorder(new LineBorder(Color.black));

    if (converter.isStaticVersioning()) {
      staticVersioningRadioButton.setSelected(true);
    } else {
      dynamicVersioningRadioButton.setSelected(true);
    }

    addListeners();

    final int buf = 10, // Buffer (between components and form)
        sp = 10, // Space between components
        vsp = 5, // Vertical space
        indent = 20; // Indent between form (left edge) and component

    GridBagConstraints gbc = new GridBagConstraints();
    GridBagLayout gbl = new GridBagLayout();
    getContentPane().setLayout(gbl);

    //
    // Setup top panel
    //
    GridBagLayout topLayout = new GridBagLayout();
    JPanel topPanel = new JPanel();
    topPanel.setOpaque(false);
    topPanel.setLayout(topLayout);

    topLayout.setConstraints(
        dirLabel,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(10, 0, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        dirTF,
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            1,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(vsp, 2, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        dirBttn,
        new GridBagConstraints(
            2,
            0,
            1,
            1,
            0,
            0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(10, sp, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        matchingLabel,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            0,
            0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(10, 0, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        matchingTF,
        new GridBagConstraints(
            1,
            1,
            1,
            1,
            1,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(vsp, 2, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        recursiveCheckBox,
        new GridBagConstraints(
            2,
            1,
            GridBagConstraints.REMAINDER,
            1,
            1,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(vsp, 10, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        backupLabel,
        new GridBagConstraints(
            0,
            3,
            1,
            1,
            0,
            0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(10, 0, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        backupTF,
        new GridBagConstraints(
            1,
            3,
            1,
            1,
            1,
            0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(vsp, 2, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        backupBttn,
        new GridBagConstraints(
            2,
            3,
            1,
            1,
            0,
            0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(10, sp, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        templateLabel,
        new GridBagConstraints(
            0,
            4,
            1,
            1,
            0,
            0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(10, 0, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        templateCh,
        new GridBagConstraints(
            1,
            4,
            1,
            1,
            0,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(vsp, 2, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        sep1,
        new GridBagConstraints(
            0,
            5,
            GridBagConstraints.REMAINDER,
            1,
            1,
            0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(10, 10, 10, 10),
            0,
            0));
    topLayout.setConstraints(
        staticVersioningLabel,
        new GridBagConstraints(
            0,
            6,
            1,
            1,
            0,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(10, 0, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        staticVersioningRadioButton,
        new GridBagConstraints(
            0,
            7,
            GridBagConstraints.REMAINDER,
            1,
            1,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(vsp, 10, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        staticVersioningPanel,
        new GridBagConstraints(
            0,
            8,
            GridBagConstraints.REMAINDER,
            1,
            0,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.BOTH,
            new Insets(vsp, 25, 10, 0),
            0,
            0));
    topLayout.setConstraints(
        dynamicVersioningRadioButton,
        new GridBagConstraints(
            0,
            9,
            GridBagConstraints.REMAINDER,
            1,
            1,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(vsp, 10, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        dynamicVersioningPanel,
        new GridBagConstraints(
            0,
            10,
            GridBagConstraints.REMAINDER,
            1,
            0,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.BOTH,
            new Insets(vsp, 25, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        sep2,
        new GridBagConstraints(
            0,
            11,
            GridBagConstraints.REMAINDER,
            1,
            1,
            0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(10, 10, 0, 10),
            0,
            0));

    invisibleBttn = new JButton();
    invisibleBttn.setVisible(false);
    topLayout.setConstraints(
        invisibleBttn,
        new GridBagConstraints(
            2,
            6,
            1,
            1,
            0,
            0,
            GridBagConstraints.CENTER,
            GridBagConstraints.CENTER,
            new Insets(indent, sp, 0, 0),
            0,
            0));

    topPanel.add(dirLabel);
    topPanel.add(dirTF);
    topPanel.add(dirBttn);
    topPanel.add(matchingLabel);
    topPanel.add(matchingTF);
    topPanel.add(recursiveCheckBox);
    topPanel.add(backupLabel);
    topPanel.add(backupTF);
    topPanel.add(backupBttn);
    topPanel.add(templateLabel);
    topPanel.add(templateCh);
    topPanel.add(sep1);
    topPanel.add(staticVersioningLabel);
    topPanel.add(staticVersioningRadioButton);
    topPanel.add(staticVersioningPanel);
    topPanel.add(dynamicVersioningRadioButton);
    topPanel.add(dynamicVersioningPanel);
    topPanel.add(sep2);
    topPanel.add(invisibleBttn);

    //
    // Setup bottom panel
    //
    GridBagLayout buttomLayout = new GridBagLayout();
    JPanel buttomPanel = new JPanel();
    buttomPanel.setOpaque(false);
    buttomPanel.setLayout(buttomLayout);

    buttomLayout.setConstraints(
        runBttn,
        new GridBagConstraints(
            3,
            0,
            1,
            1,
            0,
            0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(sp, 0, 0, 0),
            0,
            0));
    buttomPanel.add(runBttn);

    //
    // Setup main panel
    //
    GridBagLayout mainLayout = new GridBagLayout();
    JPanel mainPanel = new JPanel();

    mainPanel.setOpaque(false);
    mainPanel.setLayout(mainLayout);

    mainLayout.setConstraints(
        topPanel,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            1,
            0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(buf, buf, 0, buf),
            0,
            0));
    mainLayout.setConstraints(
        buttomPanel,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            1,
            1,
            GridBagConstraints.SOUTH,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, buf, buf, buf),
            0,
            0));
    mainPanel.add(topPanel);
    mainPanel.add(buttomPanel);

    Border border = BorderFactory.createEtchedBorder();
    mainPanel.setBorder(border);

    GridBagLayout layout = new GridBagLayout();
    getContentPane().setLayout(layout);

    layout.setConstraints(
        mainPanel,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            1,
            1,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));

    getContentPane().add(mainPanel);

    pack();
    setResizable(false);
  }
 // Create the JTextComponent subclass.
 protected JTextComponent createTextComponent() {
   JTextArea ta = new JTextArea();
   ta.setLineWrap(true);
   return ta;
 }
示例#10
0
  public void launchChess() {

    mainWindow = new JFrame("网络黑白棋	作者:张炀");
    jpWest = new JPanel();
    jpEast = new JPanel();
    jpNorth = new JPanel();
    jpSouth = new JPanel();
    jpCenter = new JPanel();

    turnLabel = new JLabel();
    blackNumberLabel = new JLabel("黑棋:\n" + black + "		");
    whiteNumberLabel = new JLabel("白棋:\n" + white + "		");
    timeLabel = new JLabel("时间:  " + time + "		s");
    noticeLabel = new JLabel();

    noticeLabel = new JLabel("请选择:");
    numberPane = new JPanel();
    readyPane = new JPanel();
    jt1 = new JTextField(18); // 发送信息框
    jt2 = new JTextArea(3, 30); // 显示信息框
    js = new JScrollPane(jt2);
    jt2.setLineWrap(true);
    jt2.setEditable(false);
    //		jt1.setLineWrap(true);

    send = new JButton("发送");
    cancel = new JButton("取消");
    regret = new JButton("悔棋");
    submit = new JButton("退出");
    begin = new JButton("开始");
    save = new JButton("存盘");

    save.setEnabled(true);
    begin.setEnabled(true);

    fighter = new JRadioButton("下棋");
    audience = new JRadioButton("观看");
    group = new ButtonGroup();
    group.add(audience);
    group.add(fighter);
    group.add(AIPlayer);

    submit.addActionListener(this);
    begin.addActionListener(this);
    save.addActionListener(this);
    send.addActionListener(this);
    cancel.addActionListener(this);
    regret.addActionListener(this);
    fighter.addActionListener(this);
    audience.addActionListener(this);

    jpNorth.setLayout(new BorderLayout());
    jpNorth.add(turnLabel, BorderLayout.NORTH);
    jpNorth.add(jpCenter, BorderLayout.CENTER);
    jpSouth.add(js);
    jpSouth.add(jt1);
    jpSouth.add(send);
    jpSouth.add(cancel);
    jpEast.setLayout(new GridLayout(3, 1));
    submit.setBackground(new Color(130, 251, 241));
    panel x = new panel();
    jpEast.add(x);
    jpEast.add(numberPane);
    jpEast.add(readyPane);

    numberPane.add(blackNumberLabel);
    numberPane.add(whiteNumberLabel);
    numberPane.add(timeLabel);
    numberPane.add(submit);
    numberPane.add(begin);
    numberPane.add(save);
    numberPane.add(regret);

    readyPane.add(noticeLabel);
    readyPane.add(fighter);
    readyPane.add(audience);
    //		readyPane.add(save);
    //		readyPane.add(regret);

    jpCenter.setSize(400, 400);
    jmb = new JMenuBar();
    document = new JMenu("游戏		");
    edit = new JMenu("设置		");
    insert = new JMenu("棋盘			");
    help = new JMenu("帮助		");
    jmb.add(document);
    jmb.add(edit);
    jmb.add(insert);
    jmb.add(help);
    // mainWindow.setJMenuBar(jmb);

    mainWindow.setBounds(80, 80, 600, 600);
    mainWindow.setResizable(false);

    jsLeft = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, jpNorth, jpSouth);
    jsBase = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, jsLeft, jpEast);

    mainWindow.add(jsBase);
    mainWindow.setVisible(true);
    mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    jsBase.setDividerLocation(0.7);
    jsLeft.setDividerLocation(0.78);

    jpCenter.setLayout(new GridLayout(8, 8, 0, 0));
    ImageIcon key = new ImageIcon("chess1.jpg");
    for (int i = 0; i < cell.length; i++)
      for (int j = 0; j < cell.length; j++) {
        cell[i][j] = new ChessBoard(i, j);
        cell[i][j].addMouseListener(this);
        jpCenter.add(cell[i][j]);
      }

    cell[3][3].state = cell[4][4].state = '黑';
    cell[4][3].state = cell[3][4].state = '白';
    cell[3][3].taken = cell[4][4].taken = true;
    cell[4][3].taken = cell[3][4].taken = true;

    RememberState();

    new Thread(new TurnLabel(this)).start();

    file = new File("D:/" + myRole);
    try {
      fout = new FileOutputStream(file);
      out = new ObjectOutputStream(fout);
    } catch (IOException e1) {
      e1.printStackTrace();
    }

    Connect();

    try {
      out99 = new ObjectOutputStream(socket99.getOutputStream());
      in99 = new ObjectInputStream(socket99.getInputStream());

      out66 = new ObjectOutputStream(socket66.getOutputStream());
      in66 = new ObjectInputStream(socket66.getInputStream());

      out88 = new DataOutputStream(socket88.getOutputStream());
    } catch (IOException e) {
      e.printStackTrace();
    }

    new Thread(new Client9999(this)).start();
    new Thread(new Client6666(this)).start();
  }
示例#11
0
  private JPanel getContentPanel(WizardData wzd) {

    JPanel contentPanel1 = new JPanel();

    welcomeTitle = new JLabel();

    contentPanel1.setLayout(new java.awt.BorderLayout());

    welcomeTitle.setFont(new java.awt.Font("MS Sans Serif", Font.BOLD, 11));
    welcomeTitle.setText("Please insert already existing language files!");
    contentPanel1.add(welcomeTitle, BorderLayout.NORTH);

    // ------------------------------------------------------------------------
    Container mainPanel = new JPanel();
    SpringLayout layout = new SpringLayout();
    mainPanel.setLayout(layout);

    JTextArea infoText = new JTextArea();
    infoText.setLineWrap(false);
    infoText.setEditable(false);
    infoText.setFocusable(false);
    infoText.setBackground(mainPanel.getBackground());
    infoText.append(TInfoText.runtime.getText("newwizard", "site2"));

    JDialog parent = null;
    if (wzd.getWizard() != null) {
      parent = wzd.getWizard().getDialog();
    }
    table = new LanguageManagerPanel(TGlobal.projects.getCurrentProject(), parent, true);

    rescanButton.addActionListener(this);
    baseButton.addActionListener(this);

    // Create and add the components.
    mainPanel.add(infoText);
    mainPanel.add(baseLabel);
    mainPanel.add(baseField);
    mainPanel.add(baseButton);
    mainPanel.add(rescanButton);
    mainPanel.add(table);

    // infoText
    layout.putConstraint(SpringLayout.WEST, infoText, 5, SpringLayout.WEST, mainPanel);
    layout.putConstraint(SpringLayout.NORTH, infoText, 5, SpringLayout.NORTH, mainPanel);

    // baseLabel -------------------------------------------------------------
    layout.putConstraint(SpringLayout.WEST, baseLabel, 0, SpringLayout.WEST, infoText);
    layout.putConstraint(SpringLayout.NORTH, baseLabel, 12, SpringLayout.SOUTH, infoText);

    // nameField
    layout.putConstraint(SpringLayout.WEST, baseField, 5, SpringLayout.EAST, baseLabel);
    layout.putConstraint(SpringLayout.NORTH, baseField, 10, SpringLayout.SOUTH, infoText);

    // baseButton
    layout.putConstraint(SpringLayout.WEST, baseButton, 5, SpringLayout.EAST, baseField);
    layout.putConstraint(SpringLayout.NORTH, baseButton, 7, SpringLayout.SOUTH, infoText);

    // rescanButton
    layout.putConstraint(SpringLayout.WEST, rescanButton, 5, SpringLayout.EAST, baseButton);
    layout.putConstraint(SpringLayout.NORTH, rescanButton, 7, SpringLayout.SOUTH, infoText);

    // table
    layout.putConstraint(SpringLayout.WEST, table, 5, SpringLayout.WEST, mainPanel);
    layout.putConstraint(SpringLayout.NORTH, table, 15, SpringLayout.SOUTH, baseField);

    // panel edges ------------------------------------------------------
    layout.putConstraint(SpringLayout.EAST, mainPanel, 5, SpringLayout.EAST, infoText);
    layout.putConstraint(SpringLayout.SOUTH, mainPanel, 5, SpringLayout.SOUTH, table);

    layout.layoutContainer(mainPanel);
    contentPanel1.add(mainPanel, BorderLayout.CENTER);

    return contentPanel1;
  }
 /**
  * Sets a custom style for the given text area.
  *
  * @param textArea the text area to style
  */
 private void setTextAreaStyle(JTextArea textArea) {
   textArea.setOpaque(false);
   textArea.setLineWrap(true);
   textArea.setWrapStyleWord(true);
 }
  public void go() {
    // build gui

    frame = new JFrame("Quiz Card Buider");
    JPanel mainPanel = new JPanel();
    Font bigFont = new Font("sanserif", Font.BOLD, 24);
    question = new JTextArea(6, 20);
    question.setLineWrap(true);
    question.setWrapStyleWord(true);
    question.setFont(bigFont);

    JScrollPane qScroller = new JScrollPane(question);
    qScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    qScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

    answer = new JTextArea(6, 20);
    answer.setLineWrap(true);
    answer.setWrapStyleWord(true);
    answer.setFont(bigFont);

    JScrollPane aScroller = new JScrollPane(question);
    aScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    aScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

    JButton nextButton = new JButton("Next Card");

    cardList = new ArrayList<QuizCard>();

    JLabel qLabel = new JLabel("Question");
    JLabel aLabel = new JLabel("Answer");

    mainPanel.add(qLabel);
    mainPanel.add(qScroller);
    mainPanel.add(aLabel);
    mainPanel.add(aScroller);
    mainPanel.add(nextButton);

    nextButton.addActionListener(new NextCardListener());

    JMenuBar menuBar = new JMenuBar();

    JMenu fileMenu = new JMenu("File");

    JMenuItem newMenuItem = new JMenuItem("New");
    JMenuItem saveMenuItem = new JMenuItem("Save");
    newMenuItem.addActionListener(new NewMenuListener());
    saveMenuItem.addActionListener(new SaveMenuListener());

    fileMenu.add(newMenuItem);
    fileMenu.add(saveMenuItem);
    menuBar.add(fileMenu);
    frame.setJMenuBar(menuBar);
    frame.getContentPane().add(BorderLayout.CENTER, mainPanel);
    frame.setSize(500, 600);
    frame.setVisible(true);
    // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  }
  public void go() {
    frame = new JFrame("Quiz Card Player");
    JPanel mainPanel = new JPanel();
    Font bigFont = new Font("sanserif", Font.BOLD, 24);

    display = new JTextArea(10, 20);
    display.setFont(bigFont);
    display.setLineWrap(true);
    display.setEditable(false);

    JScrollPane qScroller = new JScrollPane(display);
    qScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    qScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

    nextButton = new JButton("Show Questions");
    nextButton.addActionListener(new NextCardListener());

    mainPanel.add(qScroller);
    mainPanel.add(nextButton);

    JMenuBar menuBar = new JMenuBar();
    JMenu fileMenu = new JMenu("File");
    JMenuItem loadMenuItem = new JMenuItem("Load Card Set");
    loadMenuItem.addActionListener(new OpenMenuListener());
    fileMenu.add(loadMenuItem);
    menuBar.add(fileMenu);

    frame.setJMenuBar(menuBar);
    frame.getContentPane().add(BorderLayout.CENTER, mainPanel);
    frame.setSize(640, 500);
    frame.setVisible(true);
  }