public void addKeyListener(KeyListener kl) {
    super.addKeyListener(kl);

    m_titleLabel.addKeyListener(kl);
    m_southPanel.addKeyListener(kl);
    m_inputPanel.addKeyListener(kl);
    m_responsePanel.addKeyListener(kl);
  }
示例#2
0
  /** Erzeugt ein neues Objekt dieser Klasse */
  public SimpleJFrame() {

    /* Panel als Contentpane erzeugen. */
    JPanel panel = new JPanel();
    panel.setLayout(null);
    this.setContentPane(panel);

    JTextField textField = new JTextField(20);
    textField.setBounds(200, 400, 100, 30);
    panel.add(textField);

    panel.setFocusable(true);

    panel.requestFocusInWindow();

    panel.addKeyListener(this);

    /* Irgendwo muessen wir die Buttons referenzieren.. */
    JButton[] buttons = new JButton[5];

    for (int i = 0; i < buttons.length; i++) {

      /* Button mit dynamischer Position und fester Groesse erzeugen. */
      buttons[i] = new JButton(i + ". Button");
      buttons[i].setBounds(i * 110, i * 110, 100, 100);

      panel.add(buttons[i]);
    }

    /* Statische Fenster-Groesse. */
    this.setSize(800, 600);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setVisible(true);
  }
示例#3
0
  /** Default class constructor. */
  public PongFrame() {
    setTitle("Pong Game - Java SE Example");
    setSize(746, 544);
    setResizable(false);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Main panel
    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());
    mainPanel.addKeyListener(null);

    // Auxiliar panels
    final GamePoints points = new GamePoints();

    mainPanel.add(points, BorderLayout.SOUTH);

    final GamePanel game = new GamePanel(points);

    mainPanel.add(game, BorderLayout.CENTER);

    // Add main panel to JFrame
    add(mainPanel);

    // Set visible
    setLocationRelativeTo(null);
    setVisible(true);
    repaint();
    // System.out.println("Game Dimensions: " + game.getSize());
    Graphics2D g2 = (Graphics2D) game.getGraphics();
    g2.drawRect(0, 0, 10, 416);

    // Keyboard Event listener
    addKeyListener(
        new KeyListener() {
          @Override
          public void keyTyped(KeyEvent ke) {
            // Nothing to do.
          }

          @Override
          public void keyPressed(KeyEvent ke) {
            int keyCode = ke.getKeyCode();
            if (keyCode == KeyEvent.VK_SPACE) {
              game.timerStartStop();
            } else {
              game.setFlag(keyCode, true);
            }
          }

          @Override
          public void keyReleased(KeyEvent ke) {
            int keyCode = ke.getKeyCode();
            game.setFlag(keyCode, false);
          }
        });
  }
示例#4
0
  /**
   * Sets up the event handler mechanics, including invoking the initGUIHandlers method, which would
   * be provided by the game developer using this framework, and would presumably be different for
   * each game.
   */
  private void initHandlers() {
    // SETUP THE LOW-LEVEL HANDLER WHO WILL
    // RELAY EVERYTHING
    MiniGameEventRelayer mger = new MiniGameEventRelayer(this);
    canvas.addMouseListener(mger);
    canvas.addMouseMotionListener(mger);
    window.setFocusable(true);
    window.addKeyListener(mger);
    canvas.addKeyListener(mger);

    // AND NOW LET THE GAME DEVELOPER PROVIDE
    // CUSTOM HANDLERS
    initGUIHandlers();
  }
示例#5
0
  public void run() {
    gamePlay.setLayout(null);
    gamePlay.setBackground(new Color(0, 255, 0));
    // gamePlay.setSize(size, size);
    System.out.print(
        jframe.getContentPane().getSize().width + "/" + jframe.getContentPane().getSize().height);
    ImageIcon im = new ImageIcon("man.png");
    ply = new JLabel(im);
    gamePlay.add(ply);
    Dimension sizejl = ply.getPreferredSize();
    ply.setBounds(32, 32, sizejl.width, sizejl.height);
    gamePlay.addKeyListener(keyl);
    setBoundry();
    setBackground();
    setBreakableWall();
    initiateEnemy();
    jframe.add(gamePlay);
    // jframe.setDefaultCloseOperation(0);
    gamePlay.setMinimumSize((new Dimension(BomborMan.sizeGlobal, BomborMan.sizeGlobal)));

    BomborMan.Jp = new JProgressBar(0, 100);
    BomborMan.Jp.setValue(0);
    BomborMan.Jp.setStringPainted(true);
    BomborMan.jpP.add(BomborMan.Jp);
    BomborMan.Jp.setBounds(
        0,
        0,
        BomborMan.sizeGlobal
        // BomborMan.Jp.getPreferredSize().width
        ,
        BomborMan.Jp.getPreferredSize().height);

    BomborMan.jpP.setPreferredSize(new Dimension(BomborMan.sizeGlobal, 30));
    BomborMan.jpP.setMaximumSize(new Dimension(BomborMan.sizeGlobal, 30));
    BomborMan.jpP.setVisible(true);
    jframe.add(BomborMan.jpP);
    jframe.pack();
    jframe.setSize(BomborMan.sizeGlobalx, BomborMan.sizeGlobaly + 28);

    jframe.setResizable(false);
    jframe.setVisible(true);
    gamePlay.setFocusable(true);
    gamePlay.requestFocus();
    jframe.setLocation(100, 50);
  }
  private void setup() {

    pnlPrincipal.addKeyListener(this);
    bnt05.addKeyListener(this);
    btn00.addKeyListener(this);
    btn01.addKeyListener(this);
    btn02.addKeyListener(this);
    btn03.addKeyListener(this);
    btn04.addKeyListener(this);
    btn06.addKeyListener(this);
    btn07.addKeyListener(this);
    btn08.addKeyListener(this);
    btn09.addKeyListener(this);
    btnDel.addKeyListener(this);
    btnDel1.addKeyListener(this);
    btnExit.addKeyListener(this);
    btnOk.addKeyListener(this);
    txtDisplay.addKeyListener(this);
  }
  /** Builds the GUI. */
  private void buildGUI() {
    // We initialize our layout
    JPanel contentPane = (JPanel) getContentPane();
    layout = new GridBagLayout();
    contentPane.setLayout(layout);
    gbConstraints = new GridBagConstraints();
    gbConstraints.insets = new Insets(5, 5, 5, 5);

    // We prepare our action handler
    ActionsHandler handler = new ActionsHandler();

    // Prepares the glass pane to block gui interaction when needed
    JPanel glassPane = (JPanel) getGlassPane();
    glassPane.addMouseListener(new MouseAdapter() {});
    glassPane.addMouseMotionListener(new MouseMotionAdapter() {});
    glassPane.addKeyListener(new KeyAdapter() {});

    // We set-up the buttons factory
    ButtonFactory.useButtonIcons();
    ButtonFactory.useHighlightButtons();

    // We put our components

    warningLabel =
        new JLabel(
            langpack.getString("uninstaller.warning"),
            icons.getImageIcon("warning"),
            JLabel.TRAILING);
    buildConstraints(gbConstraints, 0, 0, 2, 1, 1.0, 0.0);
    gbConstraints.anchor = GridBagConstraints.WEST;
    gbConstraints.fill = GridBagConstraints.NONE;
    layout.addLayoutComponent(warningLabel, gbConstraints);
    contentPane.add(warningLabel);

    targetDestroyCheckbox =
        new JCheckBox(langpack.getString("uninstaller.destroytarget") + installPath, false);
    buildConstraints(gbConstraints, 0, 1, 2, 1, 1.0, 0.0);
    layout.addLayoutComponent(targetDestroyCheckbox, gbConstraints);
    contentPane.add(targetDestroyCheckbox);
    gbConstraints.fill = GridBagConstraints.HORIZONTAL;

    progressBar = new JProgressBar();
    progressBar.setStringPainted(true);
    progressBar.setString(langpack.getString("InstallPanel.begin"));
    buildConstraints(gbConstraints, 0, 2, 2, 1, 1.0, 0.0);
    layout.addLayoutComponent(progressBar, gbConstraints);
    contentPane.add(progressBar);

    destroyButton =
        ButtonFactory.createButton(
            langpack.getString("uninstaller.uninstall"),
            icons.getImageIcon("delete"),
            buttonsHColor);
    destroyButton.addActionListener(handler);
    buildConstraints(gbConstraints, 0, 3, 1, 1, 0.5, 0.0);
    gbConstraints.fill = GridBagConstraints.NONE;
    gbConstraints.anchor = GridBagConstraints.WEST;
    layout.addLayoutComponent(destroyButton, gbConstraints);
    contentPane.add(destroyButton);

    quitButton =
        ButtonFactory.createButton(
            langpack.getString("installer.quit"), icons.getImageIcon("stop"), buttonsHColor);
    quitButton.addActionListener(handler);
    buildConstraints(gbConstraints, 1, 3, 1, 1, 0.5, 0.0);
    gbConstraints.anchor = GridBagConstraints.EAST;
    layout.addLayoutComponent(quitButton, gbConstraints);
    contentPane.add(quitButton);
  }
示例#8
0
  void initial() {
    JPanel dpanel = new JPanel();
    dpanel.setLayout(new GridLayout(3, 1, 4, 4));

    display = new JLabel(" ", JLabel.RIGHT);
    display.setFont(new Font(DLGFONTNAME, DLGFONTSTYLE, 18));
    display.setForeground(Color.white);
    display.setBackground(Color.black);
    display.setOpaque(true);

    dpanel.add(display);

    ButtonGroup group = new ButtonGroup();
    faxNumButton = new JRadioButton("Fax number", true);
    broadcastButton = new JRadioButton("Group Send", false);
    broadcastButton.setFont(new Font(DLGFONTNAME, DLGFONTSTYLE, 14));
    faxNumButton.setFont(new Font(DLGFONTNAME, DLGFONTSTYLE, 14));
    faxNumButton.addKeyListener(this);
    broadcastButton.addKeyListener(this);
    group.add(faxNumButton);
    group.add(broadcastButton);

    dpanel.add(faxNumButton);
    dpanel.add(broadcastButton);
    dpanel.addKeyListener(this);

    JPanel npanel = new JPanel();
    npanel.setLayout(new GridLayout(4, 3, 4, 4));
    button = new JButton[20];

    for (int i = 0; i < 11; i++) {
      button[i] = new JButton(NBUTTON_NAME[i]);
      button[i].setFont(new Font(DLGFONTNAME, DLGFONTSTYLE, 16));
      //			if ((i % 5) == 3)
      //			if ((i % 5) == 4) button[i].setForeground(Color.red);
      button[i].setFocusPainted(false);
      button[i].addActionListener(this);
      button[i].addKeyListener(this);
      if (NBUTTON_NAME[i].equals(" ")) button[i].setVisible(false);
      npanel.add(button[i]);

      addKeyListener(this);
    }

    Container container = getContentPane();
    container.setLayout(new BorderLayout());
    container.add(dpanel, BorderLayout.NORTH);
    container.add(npanel, BorderLayout.CENTER);

    JPanel cpanel = new JPanel();
    cpanel.setLayout(new GridLayout(3, 1, 4, 4));
    cbutton = new JButton[20];

    for (int i = 0; i < 3; i++) {
      cbutton[i] = new JButton(CBUTTON_NAME[i]);
      cbutton[i].setFont(new Font(DLGFONTNAME, DLGFONTSTYLE, 16));
      cbutton[i].setFocusPainted(false);
      cbutton[i].addActionListener(this);
      cbutton[i].addKeyListener(this);
      cbutton[i].setForeground(Color.blue);
      // if (CBUTTON_NAME[i].equals(" ")) cbutton[i].setVisible(false);
      cpanel.add(cbutton[i]);

      addKeyListener(this);
    }

    faxNumberStr = "0";
    not1stChar = 0;

    container.add(cpanel, BorderLayout.EAST);
    container.addKeyListener(this);
  }
  private void init(
      String title, String message, int dialogType, int buttonType, boolean customTitle)
      throws Exception {
    if (customTitle) {
      setTitle(title);
    } else {
      setTitle(Language.getLocalizedString(getClass(), title));
    }
    setLayout(new BorderLayout());

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, 0));

    this.keyListener =
        new KeyAdapter() {

          @Override
          public void keyTyped(KeyEvent e) {
            String event = OptionDialog.this.eventKeyMap.get(Character.valueOf(e.getKeyChar()));
            if (event != null) {
              OptionDialog.this.actionPerformed(new ActionEvent(e.getSource(), e.getID(), event));
            }
          }
        };
    panel.addKeyListener(this.keyListener);

    if (imageIcons != null) {
      JLabel l = new JLabel(imageIcons[dialogType]);
      l.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
      panel.add(l);
      panel.add(Box.createVerticalStrut(5));
    }

    JHtmlLabel l =
        new JHtmlLabel() {

          @Override
          public Dimension getPreferredSize() {
            return new Dimension(400, super.getPreferredSize().height);
          }
        };
    l.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    message = message.replace('[', '<');
    message = message.replace(']', '>');
    message = message.replaceAll("\r\n", "<br>");
    message = message.replaceAll("\r", "<br>");
    message = message.replaceAll("\n", "<br>");
    l.setText(message);
    panel.add(l);
    add(panel, "Center");

    panel = new JPanel();
    panel.setLayout(new FlowLayout(1, 5, 5));
    switch (buttonType) {
      case 0:
        panel.add(createButton(Language.getLocalizedString(getClass(), "ok"), "ok", "o", true));
        break;
      case 1:
        panel.add(createButton(Language.getLocalizedString(getClass(), "yes"), "yes", "y", true));
        panel.add(createButton(Language.getLocalizedString(getClass(), "no"), "no", "n", false));
        break;
      case 2:
        panel.add(createButton(Language.getLocalizedString(getClass(), "yes"), "yes", "y", true));
        panel.add(createButton(Language.getLocalizedString(getClass(), "no"), "no", "n", false));
        panel.add(
            createButton(Language.getLocalizedString(getClass(), "cancel"), "cancel", "c", false));
        break;
      case 3:
        panel.add(createButton(Language.getLocalizedString(getClass(), "ok"), "ok", "o", true));
        panel.add(
            createButton(Language.getLocalizedString(getClass(), "cancel"), "cancel", "c", false));
    }

    add(panel, "South");

    setResizable(false);
  }