Esempio n. 1
0
  public AnimationFrame() {
    ArrayComponent comp = new ArrayComponent();
    add(comp, BorderLayout.CENTER);

    final Sorter sorter = new Sorter(comp);

    JButton runButton = new JButton("Run");
    runButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            sorter.setRun();
          }
        });

    JButton stepButton = new JButton("Step");
    stepButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            sorter.setStep();
          }
        });

    JPanel buttons = new JPanel();
    buttons.add(runButton);
    buttons.add(stepButton);
    add(buttons, BorderLayout.NORTH);
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    Thread t = new Thread(sorter);
    t.start();
  }
 private static void initGui() {
   try {
     UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
   } catch (Exception exception) {
     exception.printStackTrace();
   }
   JFrame frame = new JFrame("DarkBot");
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setLayout(new GridBagLayout());
   Insets noInsets = new Insets(0, 0, 0, 0);
   final JToggleButton sessionsButton = new JToggleButton("Login (0)");
   frame.add(
       sessionsButton,
       new GridBagConstraints(
           0, 0, 2, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, noInsets, 0, 0));
   sessionsButton.addActionListener(
       new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
           sessions.set(sessionsButton.isSelected());
           synchronized (sessions) {
             sessions.notifyAll();
           }
         }
       });
   final JToggleButton joinsButton = new JToggleButton("Join (0)");
   frame.add(
       joinsButton,
       new GridBagConstraints(
           0, 1, 2, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, noInsets, 0, 0));
   joinsButton.addActionListener(
       new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
           joins.set(joinsButton.isSelected());
           synchronized (joins) {
             joins.notifyAll();
           }
         }
       });
   final JTextField field = new JTextField();
   frame.add(
       field,
       new GridBagConstraints(
           0, 2, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, noInsets, 0, 0));
   final JButton button = new JButton("Start");
   frame.add(
       button,
       new GridBagConstraints(
           1, 2, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, noInsets, 0, 0));
   button.addActionListener(
       new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
           if (button.getText().startsWith("Start")) {
             field.setEnabled(false);
             spamMessage = field.getText();
             button.setText("Stop");
           } else {
             spamMessage = null;
             button.setText("Start");
             field.setEnabled(true);
           }
         }
       });
   Timer timer =
       new Timer(
           500,
           new ActionListener() {
             @Override
             public void actionPerformed(ActionEvent e) {
               sessionsButton.setText(
                   sessionsButton.getText().split(" ")[0]
                       + " ("
                       + Integer.toString(sessionCount.get())
                       + ")");
               joinsButton.setText(
                   joinsButton.getText().split(" ")[0]
                       + " ("
                       + Integer.toString(amountJoined.get())
                       + ")");
             }
           });
   timer.setRepeats(true);
   timer.start();
   frame.pack();
   frame.setSize(500, frame.getHeight());
   frame.setLocationRelativeTo(null);
   frame.setVisible(true);
 }
Esempio n. 3
0
  public void setFrame() {
    f = new JFrame("数据通讯参数设置");
    // 获取屏幕分辨率的工具集
    Toolkit tool = Toolkit.getDefaultToolkit();
    // 利用工具集获取屏幕的分辨率
    Dimension dim = tool.getScreenSize();
    // 获取屏幕分辨率的高度
    int height = (int) dim.getHeight();
    // 获取屏幕分辨率的宽度
    int width = (int) dim.getWidth();
    // 设置位置
    f.setLocation((width - 300) / 2, (height - 400) / 2);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    f.setVisible(true);
    f.setContentPane(this);
    f.setSize(320, 260);
    f.setResizable(false);

    lblIP = new JLabel("主机名");
    txtIp = new JTextField(20);
    try {
      InetAddress addr = InetAddress.getLocalHost();
      txtIp.setText(addr.getHostAddress().toString());
    } catch (Exception ex) {
    }

    lblNo = new JLabel("端口号");
    cmbNo = new JComboBox();
    cmbNo.setEditable(true);
    cmbNo.addPopupMenuListener(
        new PopupMenuListener() {
          @Override
          public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            cmbNo.removeAllItems();
            CommPortIdentifier portId = null;
            Enumeration portList;
            portList = CommPortIdentifier.getPortIdentifiers();
            while (portList.hasMoreElements()) {
              portId = (CommPortIdentifier) portList.nextElement();
              cmbNo.addItem(portId.getName());
            }
          }

          @Override
          public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            // To change body of implemented methods use File | Settings | File Templates.
          }

          @Override
          public void popupMenuCanceled(PopupMenuEvent e) {
            // To change body of implemented methods use File | Settings | File Templates.
          }
        });

    lblName = new JLabel("工程名");
    txtProjectName = new JComboBox();
    txtProjectName.setEditable(true);
    txtProjectName.addPopupMenuListener(
        new PopupMenuListener() {
          @Override
          public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            txtProjectName.removeAllItems();
            Mongo m1 = null;
            try {
              m1 = new Mongo(txtIp.getText().toString(), 27017);
            } catch (UnknownHostException ex) {
              ex.printStackTrace();
            }
            for (String name : m1.getDatabaseNames()) {
              txtProjectName.addItem(name);
            }
            m1.close();
          }

          @Override
          public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            // To change body of implemented methods use File | Settings | File Templates.
          }

          @Override
          public void popupMenuCanceled(PopupMenuEvent e) {
            // To change body of implemented methods use File | Settings | File Templates.
          }
        });

    lblBote = new JLabel("波特率");
    cmbBote = new JComboBox();
    cmbBote.addItem(9600);
    cmbBote.addItem(19200);
    cmbBote.addItem(57600);
    cmbBote.addItem(115200);

    lblLength = new JLabel("数据长度");
    cmbLength = new JComboBox();
    cmbLength.addItem(8);
    cmbLength.addItem(7);

    lblParity = new JLabel("校验");
    cmbParity = new JComboBox();
    cmbParity.addItem("None");
    cmbParity.addItem("Odd");
    cmbParity.addItem("Even");

    lblStopBit = new JLabel("停止位");
    cmbStopBit = new JComboBox();
    cmbStopBit.addItem(1);
    cmbStopBit.addItem(2);

    lblDelay = new JLabel("刷新");
    txtDelay = new JTextField(20);

    btnOk = new JButton("确定");
    btnOk.addActionListener(
        new AbstractAction() {
          @Override
          public void actionPerformed(ActionEvent e) {
            paramIp = txtIp.getText().toString();
            paramName = txtProjectName.getSelectedItem().toString();
            paramNo = cmbNo.getSelectedItem().toString();
            paramBote = Integer.parseInt(cmbBote.getSelectedItem().toString());
            parmLength = Integer.parseInt(cmbLength.getSelectedItem().toString());
            parmParity = cmbParity.getSelectedIndex();
            parmStopBit = Integer.parseInt(cmbStopBit.getSelectedItem().toString());
            parmDelay = Integer.parseInt(txtDelay.getText().toString());

            if (!paramName.equals("") && !paramNo.equals("")) {
              receiveData(
                  paramIp,
                  paramName,
                  paramNo,
                  paramBote,
                  parmLength,
                  parmParity,
                  parmStopBit,
                  parmDelay);
            } else {

            }
          }
        });
    btnCancel = new JButton("取消");
    btnCancel.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            System.exit(0);
          }
        });

    JPanel p1 = new JPanel();
    p1.setLayout(new GridLayout(9, 2));

    p1.add(lblIP);
    p1.add(txtIp);

    p1.add(lblNo);
    p1.add(cmbNo);

    p1.add(lblName);
    p1.add(txtProjectName);

    p1.add(lblBote);
    p1.add(cmbBote);

    p1.add(lblLength);
    p1.add(cmbLength);

    p1.add(lblParity);
    p1.add(cmbParity);

    p1.add(lblStopBit);
    p1.add(cmbStopBit);

    p1.add(lblDelay);
    p1.add(txtDelay);
    txtDelay.setText("500");

    p1.add(btnOk);
    p1.add(btnCancel);

    p1.validate();

    f.add(p1);
    f.validate();
  }
Esempio n. 4
0
  /**
   * Creates an instance of <tt>ShowPreviewDialog</tt>
   *
   * @param chatPanel The <tt>ChatConversationPanel</tt> that is associated with this dialog.
   */
  ShowPreviewDialog(final ChatConversationPanel chatPanel) {
    this.chatPanel = chatPanel;

    this.setTitle(
        GuiActivator.getResources().getI18NString("service.gui.SHOW_PREVIEW_DIALOG_TITLE"));
    okButton = new JButton(GuiActivator.getResources().getI18NString("service.gui.OK"));
    cancelButton = new JButton(GuiActivator.getResources().getI18NString("service.gui.CANCEL"));

    JPanel mainPanel = new TransparentPanel();
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
    mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    // mainPanel.setPreferredSize(new Dimension(200, 150));
    this.getContentPane().add(mainPanel);

    JTextPane descriptionMsg = new JTextPane();
    descriptionMsg.setEditable(false);
    descriptionMsg.setOpaque(false);
    descriptionMsg.setText(
        GuiActivator.getResources().getI18NString("service.gui.SHOW_PREVIEW_WARNING_DESCRIPTION"));

    Icon warningIcon = null;
    try {
      warningIcon =
          new ImageIcon(
              ImageIO.read(
                  GuiActivator.getResources().getImageURL("service.gui.icons.WARNING_ICON")));
    } catch (IOException e) {
      logger.debug("failed to load the warning icon");
    }
    JLabel warningSign = new JLabel(warningIcon);

    JPanel warningPanel = new TransparentPanel();
    warningPanel.setLayout(new BoxLayout(warningPanel, BoxLayout.X_AXIS));
    warningPanel.add(warningSign);
    warningPanel.add(Box.createHorizontalStrut(10));
    warningPanel.add(descriptionMsg);

    enableReplacement =
        new JCheckBox(
            GuiActivator.getResources()
                .getI18NString("plugin.chatconfig.replacement.ENABLE_REPLACEMENT_STATUS"));
    enableReplacement.setOpaque(false);
    enableReplacement.setSelected(cfg.getBoolean(ReplacementProperty.REPLACEMENT_ENABLE, true));
    enableReplacementProposal =
        new JCheckBox(
            GuiActivator.getResources()
                .getI18NString("plugin.chatconfig.replacement.ENABLE_REPLACEMENT_PROPOSAL"));
    enableReplacementProposal.setOpaque(false);

    JPanel checkBoxPanel = new TransparentPanel();
    checkBoxPanel.setLayout(new BoxLayout(checkBoxPanel, BoxLayout.Y_AXIS));
    checkBoxPanel.add(enableReplacement);
    checkBoxPanel.add(enableReplacementProposal);

    JPanel buttonsPanel = new TransparentPanel(new FlowLayout(FlowLayout.CENTER));
    buttonsPanel.add(okButton);
    buttonsPanel.add(cancelButton);

    mainPanel.add(warningPanel);
    mainPanel.add(Box.createVerticalStrut(10));
    mainPanel.add(checkBoxPanel);
    mainPanel.add(buttonsPanel);

    okButton.addActionListener(this);
    cancelButton.addActionListener(this);

    this.setPreferredSize(new Dimension(390, 230));
  }