public void init() {
    // 添加按钮
    JPanel buttonPanel = new JPanel();
    buttonPanel.add(okButton);

    mainPanel.setLayout(new GridLayout(0, 3));
    mainWin.add(mainPanel, BorderLayout.CENTER);

    JFormattedTextField intField0 =
        new JFormattedTextField(
            new InternationalFormatter(NumberFormat.getIntegerInstance()) {
              protected DocumentFilter getDocumentFilter() {
                return new NumberFilter();
              }
            });
    intField0.setValue(100);
    addRow("只接受数字的文本框", intField0);

    JFormattedTextField intField1 = new JFormattedTextField(NumberFormat.getIntegerInstance());
    intField1.setValue(new Integer(100));
    // 添加输入校验器
    intField1.setInputVerifier(new FormattedTextFieldVerifier());
    addRow("带输入校验器的文本框", intField1);

    // 创建自定义格式器对象
    IPAddressFormatter ipFormatter = new IPAddressFormatter();
    ipFormatter.setOverwriteMode(false);
    // 以自定义格式器对象创建格式化文本框
    JFormattedTextField ipField = new JFormattedTextField(ipFormatter);
    ipField.setValue(new byte[] {(byte) 192, (byte) 168, 4, 1});
    addRow("IP地址格式", ipField);

    mainWin.add(buttonPanel, BorderLayout.SOUTH);
    mainWin.pack();
    mainWin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mainWin.setVisible(true);
  }
示例#2
0
  public SyntaxTest() {

    JFrame frame = new JFrame();
    frame.setSize(300, 300);

    JEditorPane editor = new JEditorPane();
    DefaultSyntaxKit.initKit();
    editor.setContentType("text/banking");

    frame.setLayout(new GridBagLayout());

    GridBagConstraints c = new GridBagConstraints();
    c.weightx = 1.0;
    c.weighty = 1.0;
    c.fill = GridBagConstraints.BOTH;

    frame.add(editor, c);

    frame.pack();
    frame.setVisible(true);
  }
示例#3
0
 public void init() {
   jf.setLayout(new GridLayout(2, 4));
   // 使用静态工厂方法创建BevelBorder
   Border bb =
       BorderFactory.createBevelBorder(
           BevelBorder.RAISED, Color.RED, Color.GREEN, Color.BLUE, Color.GRAY);
   jf.add(getPanelWithBorder(bb, "BevelBorder"));
   // 使用静态工厂方法创建LineBorder
   Border lb = BorderFactory.createLineBorder(Color.ORANGE, 10);
   jf.add(getPanelWithBorder(lb, "LineBorder"));
   // 使用静态工厂方法创建EmptyBorder,EmptyBorder就是在组件四周留空
   Border eb = BorderFactory.createEmptyBorder(20, 5, 10, 30);
   jf.add(getPanelWithBorder(eb, "EmptyBorder"));
   // 使用静态工厂方法创建EtchedBorder
   Border etb = BorderFactory.createEtchedBorder(EtchedBorder.RAISED, Color.RED, Color.GREEN);
   jf.add(getPanelWithBorder(etb, "EtchedBorder"));
   // 直接创建TitledBorder,TitledBorder边框就是为原有的边框增加标题
   TitledBorder tb =
       new TitledBorder(
           lb,
           "测试标题",
           TitledBorder.LEFT,
           TitledBorder.BOTTOM,
           new Font("StSong", Font.BOLD, 18),
           Color.BLUE);
   jf.add(getPanelWithBorder(tb, "TitledBorder"));
   // 直接创建MatteBorder,MatteBorder边框是EmptyBorder的子类,
   // 它可以指定留空区域的颜色或背景,此处是指定颜色
   MatteBorder mb = new MatteBorder(20, 5, 10, 30, Color.GREEN);
   jf.add(getPanelWithBorder(mb, "MatteBorder"));
   // 直接创建CompoundBorder,CompoundBorder边框将两个边框组合成新边框
   CompoundBorder cb = new CompoundBorder(new LineBorder(Color.RED, 8), tb);
   jf.add(getPanelWithBorder(cb, "CompoundBorder"));
   jf.pack();
   jf.setVisible(true);
 }
示例#4
0
  /** ** Constructor. Sets up user interface and initializations */
  public Secondtry() {
    operators = true;
    doClear = false;

    frame = new JFrame("Calculator");
    frame.setLayout(new BorderLayout(10, 10));

    display = new JTextArea();
    display.setSize(245, 100);
    display.setFont(new Font("SansSerif", Font.BOLD, 28));
    display.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

    // create the numeric buttons for calculator
    for (int i = 0; i < 10; i++) {
      jb[i] = new JButton("" + (i));
      jb[i].addActionListener(this);
      jb[i].setFont(new Font("SansSerif", Font.BOLD, 14));
    }
    // create the square root button
    root = new JButton("\u221A");
    root.addActionListener(this);
    root.setFont(new Font("SansSerif", Font.BOLD, 14));

    // create the clear button
    clear = new JButton("C");
    clear.addActionListener(this);
    clear.setFont(new Font("SansSerif", Font.BOLD, 14));

    // create the plus button
    plus = new JButton("\u002B");
    plus.addActionListener(this);
    plus.setFont(new Font("SansSerif", Font.BOLD, 14));

    // create the minus button
    minus = new JButton("\u002D");
    minus.addActionListener(this);
    minus.setFont(new Font("SansSerif", Font.BOLD, 14));

    // create the multiply button
    mult = new JButton("\u002A");
    mult.addActionListener(this);
    mult.setFont(new Font("SansSerif", Font.BOLD, 14));

    // create the division button
    div = new JButton("\u002F");
    div.addActionListener(this);
    div.setFont(new Font("SansSerif", Font.BOLD, 14));

    // create the equals button
    equals = new JButton("\u003D");
    equals.addActionListener(this);
    equals.setFont(new Font("SansSerif", Font.BOLD, 14));

    equals.setPreferredSize(new Dimension(50, 60));

    // create the point button
    point = new JButton("\u002E");
    point.addActionListener(this);
    point.setFont(new Font("SansSerif", Font.BOLD, 14));

    // button grid
    JPanel buttons = new JPanel(new GridLayout(5, 4, 4, 4));

    // add buttons to grid
    buttons.add(clear);
    buttons.add(root);
    buttons.add(div);
    buttons.add(mult);
    // add numeric buttons to grid
    for (int i = 7; i < 10; i++) buttons.add(jb[i]);
    buttons.add(minus);
    // add numeric buttons to grid
    for (int i = 4; i < 7; i++) buttons.add(jb[i]);
    buttons.add(plus);
    // add numeric buttons to grid
    for (int i = 1; i < 4; i++) buttons.add(jb[i]);
    buttons.add(equals);
    buttons.add(jb[0]);
    buttons.add(point);

    frame.add(display, BorderLayout.CENTER);
    frame.add(buttons, BorderLayout.SOUTH);

    frame.setSize(300, 400);
    frame.setVisible(true);
    frame.setResizable(false);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
示例#5
0
文件: Memory.java 项目: mattec92/KTH
 // Action - vad som händer om man klickar på de olika knapparna
 public void actionPerformed(ActionEvent e) {
   // Om man trycker på startknappen
   if (e.getSource() == go) {
     for (int i = 0; i < 4; i++) {
       // Skapar spelare och AI, beroende på om textfälten och checkboxarna är ifyllda
       if (textfields.get(i).getText().length() > 0) {
         // Om checkboxen är itryckt, skapa ett AI
         if (boxes.get(i).isSelected()) {
           try {
             if (Integer.parseInt(intfields.get(i).getText()) >= 0) {
               players.add(
                   new AI(
                       textfields.get(i).getText(), Integer.parseInt(intfields.get(i).getText())));
             }
             // Om intellegensen är angivet negativt använder vi ett minne av storleken 0.
             else {
               players.add(new AI(textfields.get(i).getText(), 0));
             }
           }
           // Om intellegensen inte är angiven i siffror, använd standardintellegensen på 20 korts
           // minne
           catch (NumberFormatException ex) {
             players.add(new AI(textfields.get(i).getText(), 20));
           }
         }
         // Om spelaren inte är ett AI, lägg till en vanlig spelare
         else {
           players.add(new Player(textfields.get(i).getText()));
         }
       }
     }
     // Stänger ner menyn och startar spelet, skickar med spelarinfon
     if (players.size() >= 1) {
       this.dispose();
       f.dispose();
       new Memory(players);
     }
   }
   // Om man trycker på hjälpknappen visas en ruta med lite instruktioner
   if (e.getSource() == help) {
     f.setVisible(true);
     f.setBounds(300, 200, 500, 200);
     f.setResizable(false);
     String text =
         "<html>Om inställningar:<br>Skriv in spelarnas namn för att lägga till dem.<br>"
             + "Om AI önskas: Klicka i rutan och ange intellegens. (Antal kort AIn kommer ihåg.)<br>"
             + "Tryck på 'Starta' för att starta spelet.<br><br>"
             + "Hur man spelar:<br>Spelaren vars tur det är får sitt namn markerat med grön färg längst ner.<br>"
             + "För att göra ditt drag, tryck på korten. Du kan inte välja samma kort två gånger<br><br>"
             + "Det är ett vanligt memory, lets go!</html>";
     f.add(new JLabel(text), BorderLayout.NORTH);
   }
   for (int i = 0; i < boxes.size(); i++) {
     // Om checkboxarna är ikryssade lägger den till ett eget namn för AIn som ska skapas och visar
     // rutan för intellegensbestämning
     if (boxes.get(i).isSelected()) {
       textfields.get(i).setText("AI " + (i + 1));
       textfields.get(i).setEnabled(false);
       intfields.get(i).setText("" + 20);
       intfields.get(i).setVisible(true);
     }
     // Om checkboxarna blir urklickade igen, nollställ textfälten, och ta bort rutan för
     // intellegensbestämning
     else if (!boxes.get(i).isSelected()) {
       if (textfields.get(i).getText().indexOf("AI") != -1) {
         textfields.get(i).setText("");
         intfields.get(i).setVisible(false);
       }
       textfields.get(i).setEnabled(true);
     }
   }
 }
示例#6
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();
  }
示例#7
0
  /**
   * Create a new, empty, not-visible TaxRef window. Really just activates the setup frame and setup
   * memory monitor components, then starts things off.
   */
  public MainFrame() {
    setupMemoryMonitor();

    // Set up the main frame.
    mainFrame = new JFrame(basicTitle);
    mainFrame.setJMenuBar(setupMenuBar());
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Set up the JTable.
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setSelectionBackground(COLOR_SELECTION_BACKGROUND);
    table.setShowGrid(true);

    // Add a blank table model so that the component renders properly on
    // startup.
    table.setModel(blankDataModel);

    // Add a list selection listener so we can tell the matchInfoPanel
    // that a new name was selected.
    table
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              @Override
              public void valueChanged(ListSelectionEvent e) {
                if (currentCSV == null) return;

                int row = table.getSelectedRow();
                int column = table.getSelectedColumn();

                columnInfoPanel.columnChanged(column);

                Object o = table.getModel().getValueAt(row, column);
                if (Name.class.isAssignableFrom(o.getClass())) {
                  matchInfoPanel.nameSelected(currentCSV.getRowIndex(), (Name) o, row, column);
                } else {
                  matchInfoPanel.nameSelected(currentCSV.getRowIndex(), null, -1, -1);
                }
              }
            });

    // Set up the left panel (table + matchInfoPanel)
    JPanel leftPanel = new JPanel();

    matchInfoPanel = new MatchInformationPanel(this);
    leftPanel.setLayout(new BorderLayout());
    leftPanel.add(matchInfoPanel, BorderLayout.SOUTH);
    leftPanel.add(new JScrollPane(table));

    // Set up the right panel (columnInfoPanel)
    JPanel rightPanel = new JPanel();

    columnInfoPanel = new ColumnInformationPanel(this);

    progressBar.setStringPainted(true);

    rightPanel.setLayout(new BorderLayout());
    rightPanel.add(columnInfoPanel);
    rightPanel.add(progressBar, BorderLayout.SOUTH);

    // Set up a JSplitPane to split the panels up.
    JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, leftPanel, rightPanel);
    split.setResizeWeight(1);
    mainFrame.add(split);
    mainFrame.pack();

    // Set up a drop target so we can pick up files
    mainFrame.setDropTarget(
        new DropTarget(
            mainFrame,
            new DropTargetAdapter() {
              @Override
              public void dragEnter(DropTargetDragEvent dtde) {
                // Accept any drags.
                dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
              }

              @Override
              public void dragOver(DropTargetDragEvent dtde) {}

              @Override
              public void dropActionChanged(DropTargetDragEvent dtde) {}

              @Override
              public void dragExit(DropTargetEvent dte) {}

              @Override
              public void drop(DropTargetDropEvent dtde) {
                // Accept a drop as long as its File List.

                if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                  dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);

                  Transferable t = dtde.getTransferable();

                  try {
                    java.util.List<File> files =
                        (java.util.List<File>) t.getTransferData(DataFlavor.javaFileListFlavor);

                    // If we're given multiple files, pick up only the last file and load that.
                    File f = files.get(files.size() - 1);
                    loadFile(f, DarwinCSV.FILE_CSV_DELIMITED);

                  } catch (UnsupportedFlavorException ex) {
                    dtde.dropComplete(false);

                  } catch (IOException ex) {
                    dtde.dropComplete(false);
                  }
                }
              }
            }));
  }
 public static void main(String[] args) {
   JFrame f = new JFrame();
   f.add(new MenuButtonAcqMode());
   f.setVisible(true);
 }