@Override
 public void onOvalButtonPressed(Color c) {
   System.out.println("button pressed" + c);
   System.out.println(jTextField1.getForeground());
   if (jTextField1.getForeground().getRed() == c.getRed()
       && jTextField1.getForeground().getGreen() == c.getGreen()
       && jTextField1.getForeground().getBlue() == c.getBlue()) {
     newScore += 100;
     System.out.println("score:" + newScore);
     generateButtons();
     revalidate();
     repaint();
   } else {
     newScore -= 100;
     System.out.println("score:" + newScore);
     generateButtons();
     revalidate();
     repaint();
   }
   numOfGames++;
   System.out.println(numOfGames);
   if (numOfGames == 5) {
     colorListener.onColorGameFinished(newScore);
     numOfGames = 0;
     return;
   }
 }
Example #2
0
 private boolean verifyFields() {
   boolean ok = true;
   Color red = new Color(255, 0, 0);
   Color black = new Color(0, 0, 0);
   if (txtName.getText().equals("")) {
     lblStatus.setForeground(red);
     lblName.setText("Name*");
     lblName.setForeground(red);
     ok = false;
   } else if (lblName.getForeground().equals(red)) {
     lblName.setForeground(black);
     lblName.setText("Name");
   }
   if (txtSurname.getText().equals("")) {
     lblSurename.setText("Vorname*");
     lblSurename.setForeground(red);
     ok = false;
   } else if (lblSurename.getForeground().equals(red)) {
     lblSurename.setForeground(black);
     lblSurename.setText("Vorname");
   }
   if (txtStreet.getText().equals("")) {
     lblStreet.setText("Strasse*");
     lblStreet.setForeground(red);
     ok = false;
   } else if (lblStreet.getForeground().equals(red)) {
     lblStreet.setForeground(black);
     lblStreet.setText("Strasse");
   }
   if (txtZip.getText().equals("")) {
     lblZip.setText("PLZ*");
     lblZip.setForeground(red);
     ok = false;
   } else if (!checkZip()) {
     return false;
   } else if (lblZip.getForeground().equals(red)) {
     lblZip.setForeground(black);
     lblZip.setText("PLZ");
   }
   if (txtCity.getText().equals("")) {
     lblCity.setText("Ort*");
     lblCity.setForeground(red);
     ok = false;
   } else if (lblCity.getForeground().equals(red)) {
     lblCity.setForeground(black);
     lblCity.setText("Ort");
   }
   if (ok) {
     lblStatus.setText(" ");
   } else {
     lblStatus.setText("Bitte f�llen Sie die Markierten Felder aus");
     lblStatus.setForeground(red);
   }
   return ok;
 }
 /** To highlight a message, call #warnUser. */
 private void setStatusBarTextHighlighted(boolean highlighted, Color color) {
   // Use #coordinateLabel rather than (unattached) dummy label because
   // dummy label's background does not change when L&F changes. [Jon
   // Aquino]
   messageLabel.setForeground(highlighted ? Color.black : coordinateLabel.getForeground());
   messageLabel.setBackground(highlighted ? color : coordinateLabel.getBackground());
 }
Example #4
0
  public Element toXML() {
    Element result = new Element("timer");

    XMLUtil.createElement("title", getTitle(), result);
    XMLUtil.createElement("started", started == null ? "" : started.toString(), result);
    XMLUtil.createElement("total", period.toString(), result);
    XMLUtil.createElement("speed", update_speed, result);

    XMLUtil.createElement("x", getX(), result);
    XMLUtil.createElement("y", getY(), result);
    XMLUtil.createElement("width", getWidth(), result);
    XMLUtil.createElement("height", getHeight(), result);

    XMLUtil.createElement(
        "foreground", String.format("%08x", total.getForeground().getRGB()), result);
    XMLUtil.createElement(
        "background", String.format("%08x", panel.getBackground().getRGB()), result);

    XMLUtil.createElement("visible", isVisible(), result);

    Element times = new Element("times");
    for (TimeSpan ts : this.times) {
      times.addContent(ts.toXML());
    }
    result.addContent(times);
    return result;
  }
Example #5
0
    public @Override void paint(Graphics g) {
      if (!indicatorLabel.getFont().equals(chartFrame.getChartProperties().getFont()))
        indicatorLabel.setFont(chartFrame.getChartProperties().getFont());
      if (!indicatorLabel.getForeground().equals(chartFrame.getChartProperties().getFontColor()))
        indicatorLabel.setForeground(chartFrame.getChartProperties().getFontColor());
      if (!indicatorLabel.getText().equals(indicator.getLabel()))
        indicatorLabel.setText(indicator.getLabel());

      Rectangle oldClip = g.getClipBounds();
      Rectangle newClip = getBounds();
      g.setClip(newClip);

      Graphics2D g2 = (Graphics2D) g.create();

      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g2.setRenderingHint(
          RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
      g2.setRenderingHint(
          RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);

      g2.setPaintMode();

      if (mouseOver) {
        g2.setColor(backColor);
        RoundRectangle2D roundRectangle =
            new RoundRectangle2D.Double(getX(), getY(), getWidth(), getHeight(), 10, 10);
        g2.fill(roundRectangle);
      }

      super.paint(g);

      g2.dispose();
      g.setClip(oldClip);
    }
Example #6
0
 private void blink() {
   if (lblTitle.getForeground() == Color.BLACK) {
     lblTitle.setForeground(new Color(255, 130, 13));
   } else {
     lblTitle.setForeground(Color.BLACK);
   }
   if (parent.indexOfComponent(owner) == parent.getSelectedIndex()) {
     this.stopBlink();
   }
 }
Example #7
0
 protected void paintEnabledText(JLabel l, Graphics g, String s, int textX, int textY) {
   int mnemIndex = -1;
   if (JTattooUtilities.getJavaVersion() >= 1.4) {
     mnemIndex = l.getDisplayedMnemonicIndex();
   } else {
     mnemIndex =
         JTattooUtilities.findDisplayedMnemonicIndex(l.getText(), l.getDisplayedMnemonic());
   }
   g.setColor(l.getForeground());
   JTattooUtilities.drawStringUnderlineCharAt(l, g, s, mnemIndex, textX, textY);
 }
Example #8
0
  public void initializeUI() throws Exception {
    // initialize components
    btnPrev.setActionCommand("PREVIOUS");
    btnPrev.setFont(new Font("dialog", Font.PLAIN, 10));
    btnNext.setActionCommand("NEXT");
    btnNext.setFont(new Font("dialog", Font.PLAIN, 10));
    btnPrev.setEnabled(false);
    btnPrev.addActionListener(this);
    btnNext.addActionListener(this);

    jtaMsgTarget.setEditable(false);

    setLayout(new BorderLayout());

    JPanel pnlAll = new JPanel(new BorderLayout());
    ImageIcon imgIcon = new ImageIcon();

    pnlContent.add(pnlDStarget, "OPEN_DS_TARGET");

    pnlShowConnectTarget.add(jtaMsgTarget, BorderLayout.CENTER);
    pnlContent.add(pnlShowConnectTarget, "DS_TARGET_MSG");

    rlp = new RestoreLoaderPanel();
    pnlContent.add(rlp, "DB_OPEN_FILE");

    JPanel pnlButtons = new JPanel();
    pnlButtons.add(btnPrev);
    pnlButtons.add(btnNext);
    pnlButtons.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, pnlButtons.getForeground()));

    jlblTitle.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, jlblTitle.getForeground()));

    // add title no NORTH
    pnlAll.add(jlblTitle, BorderLayout.NORTH);
    pnlAll.add(pnlContent, BorderLayout.CENTER);
    pnlAll.add(new JLabel(imgIcon), BorderLayout.WEST);
    pnlAll.add(pnlButtons, BorderLayout.SOUTH);

    add(pnlAll, BorderLayout.CENTER);
    pnlAll.setPreferredSize(new Dimension(500, 300));
    pnlAll.setMinimumSize(new Dimension(500, 300));
  }
  public ColorChooserDemo() {
    super(new BorderLayout());

    // 设置一个标签,做广告的。也用来显示用户选择的颜色。
    banner = new JLabel("欢迎使用颜色选择器!", JLabel.CENTER);
    banner.setForeground(Color.yellow);
    banner.setBackground(Color.blue);
    banner.setOpaque(true);
    banner.setFont(new Font("SansSerif", Font.BOLD, 24));
    banner.setPreferredSize(new Dimension(100, 65));

    JPanel bannerPanel = new JPanel(new BorderLayout());
    bannerPanel.add(banner, BorderLayout.CENTER);
    bannerPanel.setBorder(BorderFactory.createTitledBorder("广告"));

    // 设置选择颜色选择器
    tcc = new JColorChooser(banner.getForeground()); // 设置初始颜色
    tcc.getSelectionModel().addChangeListener(this); // 给所有模式添加监听
    tcc.setBorder(BorderFactory.createTitledBorder("选择颜色"));

    add(bannerPanel, BorderLayout.CENTER);
    add(tcc, BorderLayout.PAGE_END);
  }
Example #10
0
 private JLabel header(String buyAndAddPremiumAccount_layoutDialogContent_get) {
   JLabel ret = SwingUtils.toBold(new JLabel(buyAndAddPremiumAccount_layoutDialogContent_get));
   ret.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, ret.getForeground()));
   return ret;
 }
Example #11
0
 protected void paintEnabledText(JLabel l, Graphics g, String s, int textX, int textY) {
   int accChar = l.getDisplayedMnemonic();
   g.setColor(l.getForeground());
   drawString(g, s, accChar, textX, textY);
 }
  // ************ Constructor start
  public SpaceInvadersPanel() {
    setLayout(null);

    // Used to evaluate if functions should be done, they stop null pointer
    // exceptions
    playing = true;
    won = false;
    lost = false;

    difficultyLabel = new JLabel("Choose difficulty:");
    difficultyLabel.setBounds(350, 350, 200, 50);
    difficultyLabel.setForeground(Color.WHITE);
    difficultyLabel.setVisible(true);
    add(difficultyLabel);

    instructionLabel = new JLabel("Use arrow keys to move and press up to shoot");
    instructionLabel.setBounds(350, 300, 350, 50);
    instructionLabel.setForeground(Color.WHITE);
    instructionLabel.setVisible(true);
    add(instructionLabel);

    difficultyButton = new JButton[4];
    // Array of buttons that show at start and after restart
    for (int i = 0; i < 4; i++) {
      difficultyButton[i] = new JButton("" + (i + 1));
      difficultyButton[i].setBounds((i * bWidth) + 200, 450, bWidth, bHeight);
      difficultyButton[i].setVisible(true);
      difficultyButton[i].addActionListener(this);
      difficultyButton[i].addKeyListener(this);
      difficultyButton[i].setFocusable(false);
      add(difficultyButton[i]);
    }

    // Not really changed
    speed = 20;

    ticks = 0;
    velocityX = 0;
    score = 0;
    rand = new Random();

    // Your shootything
    playerProj = new PlayerProjectile(450, 700);
    playerProj.setVisible(false);
    add(playerProj);

    // This class implements listeners, so this class has this to add to
    // them
    addKeyListener(this);
    this.setFocusable(true);
    // So players can't use tab to switch focus
    this.setFocusTraversalKeysEnabled(false);

    // Arrays of FUN
    enemies = new InvaderEntity[10][10]; // Y < 4; X < 10
    livesImages = new JLabel[3];
    enemyProjX = new int[projectileAmount];
    enemyProj = new InvaderProjectile[projectileAmount];

    // Making projectiles...
    // Not all are used, but to avoid outofbounds, the projectileAmount MUST
    // be final
    for (int i = 0; i < projectileAmount; i++) {
      enemyProj[i] = new InvaderProjectile(200, 100);
      enemyProj[i].setVisible(false);
      add(enemyProj[i]);
    }

    // Labels for lives
    for (int i = 0; i < 3; i++) {
      livesImages[i] = new JLabel();
      Image img = null;
      try {
        img = ImageIO.read(new File("player.png"));
      } catch (IOException e) {
        e.printStackTrace();
      }

      ImageIcon icon = new ImageIcon(img);
      livesImages[i].setIcon(icon);
      livesImages[i].setBounds((i * 40) + 70, 10, 40, 40);
      livesImages[i].setVisible(false);
      add(livesImages[i]);
    }

    tickLabel = new JLabel();
    tickLabel.setForeground(Color.WHITE);
    tickLabel.setBounds(450, 25, 200, 45);
    tickLabel.setVisible(false);
    add(tickLabel);

    outcomeLabel = new JLabel();
    outcomeLabel.setForeground(Color.WHITE);
    outcomeLabel.setBounds(450, 450, 200, 20);
    outcomeLabel.setVisible(false);
    add(outcomeLabel);

    scoreLabel = new JLabel();
    scoreLabel.setForeground(Color.WHITE);
    scoreLabel.setBounds(900 - 200, 25, 200, 45);
    scoreLabel.setVisible(false);
    add(scoreLabel);

    shield =
        new JLabel(
            "------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
    shield.setForeground(Color.BLUE);
    shield.setBounds(0, 650, 900, 10);
    shield.setVisible(false);
    add(shield);

    ceiling = new JLabel(shield.getText());
    ceiling.setForeground(Color.WHITE);
    ceiling.setBounds(0, 50, 900, 10);
    ceiling.setVisible(false);
    add(ceiling);

    floor = new JLabel(shield.getText());
    floor.setForeground(ceiling.getForeground());
    floor.setSize(ceiling.getWidth(), ceiling.getHeight());
    floor.setLocation(0, 755);
    floor.setVisible(false);
    add(floor);

    playerLabel = new JLabel("Ships left:");
    playerLabel.setForeground(Color.WHITE);
    playerLabel.setBounds(0, 10, 93, 45);
    playerLabel.setVisible(false);
    add(playerLabel);

    exitButton = new JButton("Exit");
    exitButton.setBounds((bWidth * 4) + 250, 450, bWidth, bHeight);
    exitButton.addActionListener(this);
    exitButton.addKeyListener(this);
    exitButton.setFocusable(false);
    exitButton.setVisible(true);
    add(exitButton);

    resetButton = new JButton("Restart");
    resetButton.setBounds(bWidth, 800, bWidth, bHeight);
    resetButton.addActionListener(this);
    resetButton.addKeyListener(this);
    resetButton.setFocusable(false);
    resetButton.setVisible(false);
    add(resetButton);

    // Make gunners and Tankers
    for (int y = 0; y < 4; y++) {
      for (int x = 0; x < 10; x++) {
        if (y < 2) {
          enemies[y][x] = new Gunner(x, y);
        } else {
          enemies[y][x] = new Tanker(x, y);
        }
        enemies[y][x].setVisible(false);
        add(enemies[y][x]);
      }
    }

    // Instantiate PlayerEntity
    player = new PlayerEntity(PLAYER_START_X, PLAYER_START_Y);
    player.addKeyListener(this);
    player.setFocusable(false);
    player.setVisible(false);
    add(player);

    askDifficulty();
  }
Example #13
0
  // Experience suggests that one should avoid using weights when using the
  // GridBagLayout. I find that nonzero weights can cause layout bugs that are
  // hard to track down. [Jon Aquino]
  void jbInit() throws Exception {
    _descriptionTextArea.setOpaque(false);
    get_okCancelPanel()
        .addActionListener(
            new java.awt.event.ActionListener() {
              public void actionPerformed(ActionEvent e) {
                okCancelPanel_actionPerformed(e);
              }
            });
    this.addComponentListener(
        new java.awt.event.ComponentAdapter() {
          public void componentShown(ComponentEvent e) {
            this_componentShown(e);
          }
        });

    // _outerMainPanel.setLayout(new GridBagLayout());
    // _outerMainPanel.setAlignmentX((float) 0.7);
    _outerMainPanel.setLayout(new BorderLayout());
    this.setResizable(true);
    this.getContentPane().setLayout(new BorderLayout());
    _imagePanel.setBorder(BorderFactory.createEtchedBorder());
    _imagePanel.setLayout(new GridBagLayout());
    _mainPanel.setLayout(new BorderLayout());
    try {
      _descriptionTextArea.setPreferredSize(new Dimension(100, 100));
      _descriptionTextArea.setOpaque(false);
      _descriptionTextArea.setEnabled(false);
      _descriptionTextArea.setEditable(false);
      _descriptionTextArea.setContentType("text/html");
    } catch (RuntimeException e1) {
      // Problemas para instanciar el kit text/html en el Plugin
      logger.error("jbInit()", e1);
      if (logger.isDebugEnabled()) {
        logger.debug(
            "jbInit() - La clase a instanciar para html es:"
                + _descriptionTextArea.getEditorKitForContentType("text/html"));
      }
    }

    documentExtendedForm = new DocumentExtendedForm();
    documentExtendedForm.initialize(this);
    setDescription();
    _imagePanel.add(
        _descriptionTextArea,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            0.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH,
            new Insets(10, 10, 10, 10),
            0,
            0));

    _imagePanel.add(
        _infoFeatures,
        new GridBagConstraints(
            0,
            2,
            1,
            1,
            0.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH,
            new Insets(10, 10, 10, 10),
            0,
            0));
    _imagePanel.add(
        _strutPanel,
        new GridBagConstraints(
            0,
            20,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0));
    _outerMainPanel.add(_mainPanel, BorderLayout.CENTER);
    _outerMainPanel.add(_imagePanel, BorderLayout.WEST);

    _descriptionTextArea.setFont(_imageLabel.getFont());
    _descriptionTextArea.setDisabledTextColor(_imageLabel.getForeground());
    if (features.size() > 1) _infoFeatures.add(getFeaturesComboBox(), null);
    this.setContentPane(getContentPanel()); // Generated
    _strutPanel.add(getZoomFeatureButton(), null); // Generated
    _strutPanel.add(getFlashFeatureButton(), null); // Generated
  }
  @Override
  public void editLabel() {
    if (logger.isLoggable(Level.FINE)) {
      logger.fine("Edit ie hyperlink");
    }
    labelEditing = true;
    _jLabelTextField =
        new JTextField(getModel().getValue()) {
          /**
           * Overrides paint
           *
           * @see javax.swing.JComponent#paint(java.awt.Graphics)
           */
          @Override
          public void paint(Graphics g) {
            super.paint(g);
            if (getModel().isCustomButton()) {
              Rectangle bounds = getBounds();
              g.setColor(getBackgroundColor());
              g.fillRect(0, 0, ROUNDED_BORDER_SIZE, ROUNDED_BORDER_SIZE);
              g.fillRect(
                  0, bounds.height - ROUNDED_BORDER_SIZE, ROUNDED_BORDER_SIZE, ROUNDED_BORDER_SIZE);
              g.fillRect(
                  bounds.width - ROUNDED_BORDER_SIZE, 0, ROUNDED_BORDER_SIZE, ROUNDED_BORDER_SIZE);
              g.fillRect(
                  bounds.width - ROUNDED_BORDER_SIZE,
                  bounds.height - ROUNDED_BORDER_SIZE,
                  ROUNDED_BORDER_SIZE,
                  ROUNDED_BORDER_SIZE);
            }
          }

          /**
           * Overrides getPreferredSize
           *
           * @see javax.swing.JComponent#getPreferredSize()
           */
          @Override
          public Dimension getPreferredSize() {
            if (getModel().isCustomButton()) {
              String s = _jLabelTextField.getText();
              if (s == null) {
                return new Dimension(30, 15);
              } else {
                return new Dimension(
                    (int)
                        (getFontMetrics(getFont()).getStringBounds(s, getGraphics()).getWidth()
                            + 32),
                    15);
              }
            } else {
              return super.getPreferredSize();
            }
          }
        };
    _jLabelTextField.setFont(_jLabel.getFont());
    _jLabelTextField.setForeground(_jLabel.getForeground());
    _jLabelTextField.setBackground(_jLabel.getBackground());
    if (getModel().isCustomButton()) {
      _jLabelTextField.setBorder(
          BorderFactory.createMatteBorder(0, 15, 1, 15, _jLabel.getBackground()));
    } else {
      _jLabelTextField.setBorder(BorderFactory.createEmptyBorder(0, 10, 1, 10));
    }
    // _jLabelTextField.setForeground(getFlexoNode().getTextColor());
    _jLabelTextField.setBounds(_jLabel.getBounds());
    _jLabelTextField.setHorizontalAlignment(SwingConstants.CENTER);
    _jLabelTextField.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent event) {
            finalizeEditHyperlink();
          }
        });
    _jLabelTextField.getDocument().addDocumentListener(new TriggerRepaintDocumentListener(this));
    _jLabelTextField.addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusLost(FocusEvent arg0) {
            finalizeEditHyperlink();
          }
        });
    remove(_jLabel);
    add(_jLabelTextField);
    _jLabelTextField.requestFocusInWindow();
    _jLabelTextField.selectAll();
    _jLabelTextField.revalidate();
    _jLabelTextField.repaint();
    revalidate();
    repaint();
  }