public void init() {
    jf = new JFrame();
    jtf = new JTextField();

    Container c = jf.getContentPane(); // Returns the contentPane object for this frame.
    jtf.setHorizontalAlignment(JTextField.RIGHT); // 设置文本的水平对齐方式
    jtf.setLayout(new GridLayout());
    c.add(jtf, BorderLayout.NORTH); //

    JPanel jp = new JPanel();
    jp.setLayout(new GridLayout(4, 4)); // 对于GridLayout(int rows,int cols)详情请参见API
    c.add(jp, BorderLayout.CENTER); /*这里刚开始犯了一低级错误,将c写成了jp,逻辑调用都出现了问题*/

    JButton[] ja = new JButton[10];
    JButton[] jb = new JButton[5];
    for (int i = 0; i < 10; i++) {
      ja[i] = new JButton("" + i);
      ja[i].addActionListener(this);
    }
    for (int j = 0; j < 5; j++) {
      jb[j] = new JButton("" + b[j]);
      jb[j].addActionListener(this);
    }

    for (int i = 0; i < 10; i++) {
      jp.add(ja[i]);
    }
    for (int j = 0; j < 5; j++) {
      jp.add(jb[j]);
    }

    jp.add(jis);
    jis.addActionListener(this);
    jf.setSize(200, 300);
    jf.setVisible(true);
  }
  public static void setupAutoComplete(final JTextField txtInput, final List<String> popitems) {
    System.out.print("reset : ");
    for (String str : popitems) {
      System.out.print(str + " and ");
    }
    System.out.println();
    final DefaultComboBoxModel model = new DefaultComboBoxModel();
    final JComboBox cbInput =
        new JComboBox(model) {
          public Dimension getPreferredSize() {
            return new Dimension(super.getPreferredSize().width, 0);
          }
        };
    setAdjusting(cbInput, false);
    for (String item : popitems) {
      model.addElement(item);
    }
    cbInput.setSelectedItem(null);
    cbInput.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (!isAdjusting(cbInput)) {
              if (cbInput.getSelectedItem() != null) {
                txtInput.setText(cbInput.getSelectedItem().toString());
              }
            }
          }
        });

    txtInput.addKeyListener(
        new KeyAdapter() {

          @Override
          public void keyPressed(KeyEvent e) {
            setAdjusting(cbInput, true);
            if (e.getKeyCode() == KeyEvent.VK_SPACE) {
              if (cbInput.isPopupVisible()) {
                e.setKeyCode(KeyEvent.VK_ENTER);
              }
            }
            if (e.getKeyCode() == KeyEvent.VK_ENTER
                || e.getKeyCode() == KeyEvent.VK_UP
                || e.getKeyCode() == KeyEvent.VK_DOWN) {
              e.setSource(cbInput);
              cbInput.dispatchEvent(e);
              if (e.getKeyCode() == KeyEvent.VK_ENTER) {

                if (cbInput != null && cbInput.getSelectedItem() != null) {
                  txtInput.setText(cbInput.getSelectedItem().toString());
                }

                // 按下回车时触发loseFocuse事件来更新table model
                txtInput.setFocusable(false);
                txtInput.setFocusable(true);
                cbInput.setPopupVisible(false);
              }
            }
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
              cbInput.setPopupVisible(false);
            }
            setAdjusting(cbInput, false);
          }
        });
    txtInput
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {
              public void insertUpdate(DocumentEvent e) {
                updateList();
                //  System.out.println("insertUpdate");
              }

              public void removeUpdate(DocumentEvent e) {
                updateList();
                //   System.out.println("removeUpdate");
              }

              public void changedUpdate(DocumentEvent e) {
                updateList();
                //   System.out.println("changedUpdate");
              }

              private void updateList() {
                setAdjusting(cbInput, true);
                model.removeAllElements();
                String input = txtInput.getText();
                if (!input.isEmpty()) {
                  for (String item : popitems) {
                    System.out.print(item + " updateList ");
                    //	if (item.toLowerCase().startsWith(input.toLowerCase()) &&
                    // !item.toLowerCase().equals(input.toLowerCase())) {
                    if (item.toLowerCase().startsWith(input.toLowerCase())) {
                      model.addElement(item);
                    }
                  }
                  System.out.println();
                }

                cbInput.setPopupVisible(model.getSize() > 0);
                setAdjusting(cbInput, false);
              }
            });
    txtInput.setLayout(new BorderLayout());
    txtInput.add(cbInput, BorderLayout.SOUTH);
  }
示例#3
0
  /**
   * UI�� �ʱ�ȭ �ϰų�, ��ü���� �ʱ�ȭ �ϴ� ������ �Ѵ�. MainUI() �����ڿ����� ȣ���� �� �ִ�. �� �ѹ��� ȣ��ȴ�.
   */
  private void init() {
    // �������� ũ�� ����
    setBounds(
        (Resolution.X * 2 / 5), Resolution.Y / 4, UIConstant.MYPCR_WIDTH, UIConstant.MYPCR_HEIGHT);
    // Ÿ��Ʋ ����
    setTitle("MyPCR version 3.2");

    // ����� ���α׷� ����
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // �ִ�ȭ ����
    setResizable(false);

    // title icon ����
    setIconImage(new ImageIcon(getClass().getClassLoader().getResource("icon.png")).getImage());

    // ���� ������Ʈ�� ������� Panel
    // ���̾ƿ��� ������ǥ�� ����ϱ� ���� null�� ����
    m_Panel = new JPanel();
    m_Panel.setLayout(null);
    m_Panel.setBackground(UIConstant.BACKGROUND_COLOR);

    // 3���� GroupBox�� title
    String[] titles = {"Serial Number", "CHAMBER", "LID HEATER"};

    /** ������Ʈ ���� * */
    m_ProtocolText = new ProtocolText();
    m_PCRStatusText = StatusText.getInstance(UIConstant.GROUP_SIZE, titles);
    m_ProtocolList = ProtocolList.getInstance();
    m_ButtonUI = ButtonUI.getInstance(this);
    m_LidText = new JTextField();
    m_LidText.setLayout(null);
    m_LidText.setBounds(310, 55, 40, 20);
    m_LidText.setText("104");
    m_LidText.addKeyListener(this);

    // �ΰ� �߰�
    JLabel labelLogo =
        new JLabel(new ImageIcon(getClass().getClassLoader().getResource("logo.jpg")));
    labelLogo.setBounds(100, 385, 182, 37);

    // for bootloader mode
    labelLogo.addMouseListener(
        new MouseListener() {
          public void mouseReleased(MouseEvent e) {}

          public void mousePressed(MouseEvent e) {}

          public void mouseExited(MouseEvent e) {}

          public void mouseEntered(MouseEvent e) {}

          public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 3 && currentVersion != null) {
              String res =
                  JOptionPane.showInputDialog(
                      null,
                      "Please input admin password for bootloader",
                      "Admin Mode(Firmware V" + currentVersion + ")",
                      JOptionPane.OK_CANCEL_OPTION);

              if (res != null) {
                if (res.equals(Constants.ADMIN_PASSWORD)) {
                  if (m_ButtonUI.isEnable(ButtonUI.BUTTON_START))
                    OnHandleMessage(MESSAGE_STOP_PCR, null);
                  Thread tempThread =
                      new Thread() {
                        public void run() {
                          try {
                            Thread.sleep(1000);
                            OnMessage(DISCONNECTED, null, 0);
                            Thread.sleep(1000);
                            m_Device.write(m_PCRTask.m_TxAction.Tx_BootLoader());
                          } catch (Exception e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                          }
                        }
                      };
                  tempThread.start();
                } else
                  JOptionPane.showMessageDialog(
                      null, "Wrong password!", "Admin Mode", JOptionPane.WARNING_MESSAGE);
              }
            }
          }
        });

    // LED added
    icon_blueOff = new ImageIcon(url_blueOff);
    icon_blueOn = new ImageIcon(url_blueOn);
    icon_greenOff = new ImageIcon(url_greenOff);
    icon_greenOn = new ImageIcon(url_greenOn);
    icon_redOff = new ImageIcon(url_redOff);
    icon_redOn = new ImageIcon(url_redOn);

    ledBlue = new JLabel(icon_blueOff);
    ledBlue.setBounds(310, 1, 22, 29);
    ledRed = new JLabel(icon_redOff);
    ledRed.setBounds(332, 1, 22, 29);
    ledGreen = new JLabel(icon_greenOff);
    ledGreen.setBounds(354, 1, 22, 29);

    m_Panel.add(m_ProtocolText);
    m_Panel.add(m_PCRStatusText);
    m_Panel.add(m_ProtocolList.getPane());
    m_Panel.add(m_ButtonUI.getPanel());
    m_Panel.add(m_LidText);

    // 150509 logo and led added
    m_Panel.add(labelLogo);
    m_Panel.add(ledBlue);
    m_Panel.add(ledGreen);
    m_Panel.add(ledRed);
    /** ������Ʈ ���� * */

    // �dz��� ���� �����ӿ� ����
    add(m_Panel);

    // 150507 ȭ�鿡 UI �� ���� ���� ��ġ Ȯ���� ���� �ϱ� ���� ó��
    // ȭ�鿡 ���̵���
    // setVisible(true);

    // Device ���� üũ�� �ݹ� �Լ� ����
    try {
      // DeviceManager �ν��Ͻ� ����
      m_Manager = HIDManager.getInstance();
      // Device ���� ���¸� ǥ�����ִ� �ݹ��Լ� ���
      m_Callback_DeviceChange = CallbackDeviceChange.getInstance(m_Manager, this);
      m_Callback_DeviceChange.setDaemon(true);
      m_Callback_DeviceChange.start();
    } catch (IOException e) {
      e.printStackTrace();
    }

    // MyPCR ���� ����� ��� �ִ� ��ü�� �ν��Ͻ��� ����
    m_PCRTask = PCR_Task.getInstance(this);
  }
示例#4
0
  public ImagePanel(
      final MD5dbmaker parentmaker,
      JPanel parentpanel,
      final String imagepath,
      int width,
      int height,
      final boolean clickable)
      throws IOException, NoSuchAlgorithmException {
    this.parentmaker = parentmaker;

    if (colors == null) {
      colors = new ArrayList<Color>();
      colors.add(Color.gray);
      colors.add(Color.red);
      colors.add(Color.blue);
      colors.add(Color.green);
      colors.add(Color.black);
      colors.add(Color.white);
    }

    File f = new File(".");
    this.filename = imagepath;
    // System.err.println("ARGH: " +f.getCanonicalPath() + md5db_maker.sep + imagepath);
    this.image = ImageIO.read(new File(f.getCanonicalPath() + "/" + imagepath));
    this.parentpanel = parentpanel;
    this.parentpanel.add(this);
    setBackground(Color.MAGENTA);
    setSize(width, height + MD5dbmaker.TEXTFIELD_HEIGHT);
    this.setVisible(true);
    this.setLayout(null);

    // bottomtext = Gishlevel.getMD5fromImage(image);
    bottomtext = imagepath;
    textField = new JTextField(bottomtext);
    textField.setLayout(null);
    textField.setEditable(false);
    textField.setFont(new Font("Arial", Font.PLAIN, 10));
    textField.setSize(MD5dbmaker.IMAGE_SIZE, MD5dbmaker.TEXTFIELD_HEIGHT);
    textField.setLocation(0, MD5dbmaker.IMAGE_SIZE);
    textField.setAlignmentY(BOTTOM_ALIGNMENT);

    this.add(textField);

    this.addMouseListener(
        new MouseListener() {

          public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON1) {
              if (clickable) {
                parentmaker.addEntry(filename);
                // System.err.println("CLICKED ON:  " + filename);
                if (e.isShiftDown()) {
                  // System.err.println("SHIFT IS ON");
                  try {
                    bottomtext = imagepath + " - " + Gishlevel.getMD5fromImage(image);
                    textField.setText(bottomtext);
                  } catch (IOException ex) {
                    Logger.getLogger(ImagePanel.class.getName()).log(Level.SEVERE, null, ex);
                  } catch (NoSuchAlgorithmException ex) {
                    Logger.getLogger(ImagePanel.class.getName()).log(Level.SEVERE, null, ex);
                  }
                }
              }
            } else {
              colorindex += 1;
              if (colorindex >= colors.size()) {
                colorindex = 0;
              }
              setBackground(colors.get(colorindex));
            }
          }

          public void mousePressed(MouseEvent e) {
            // throw new UnsupportedOperationException("Not supported yet.");
          }

          public void mouseReleased(MouseEvent e) {
            // throw new UnsupportedOperationException("Not supported yet.");
          }

          public void mouseEntered(MouseEvent e) {
            setBackground(colors.get(colorindex));
            if (clickable) {
              setBorder(BorderFactory.createLineBorder(Color.red, 3));
            }
          }

          public void mouseExited(MouseEvent e) {
            setBackground(Color.MAGENTA);
            if (clickable) {
              setBorder(BorderFactory.createCompoundBorder());
            }
          }
        });
  }