Exemplo n.º 1
0
 public RoundedShadowBorder() {
   insets = new Insets(0, 0, 0, 0);
   insets.bottom = bottomLeftCorner.getIconHeight() + backgroundThickness;
   insets.top = topLeftCorner.getIconHeight() + backgroundThickness;
   insets.left = topLeftCorner.getIconHeight() + backgroundThickness;
   insets.right = topRightCorner.getIconHeight() + backgroundThickness;
 }
Exemplo n.º 2
0
 public Player(double x) {
   hp = 100;
   pX = x;
   playerTex = new ImageIcon("TEXTURE/stickman.png");
   pY = Constants.GROUND - playerTex.getIconHeight();
   pRect =
       new Rectangle2D.Double(x + playerTex.getIconWidth() / 2, pY, 1, playerTex.getIconHeight());
 }
Exemplo n.º 3
0
  private void updateImages() {
    mainIcon.setIcon(model.getCharacterToken().getIcon());
    if (model.getCharacter().getGameObject().hasThisAttribute(CharacterInfoCard.NO_INVERT_ICON)) {
      ImageIcon icon = model.getCharacter().getFullSizedIcon();
      BufferedImage bi =
          new BufferedImage(
              icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_3BYTE_BGR);
      Graphics big = bi.getGraphics();
      big.setColor(Color.black);
      big.fillRect(0, 0, icon.getIconWidth(), icon.getIconHeight());
      big.drawImage(icon.getImage(), 0, 0, null);
      invertedIcon.setIcon(new ImageIcon(bi));
    } else {
      invertedIcon.setIcon(getInvertedIcon());
    }

    repaint();
  }
Exemplo n.º 4
0
 public void squish(Graphics g, ImageIcon icon, int x, int y, double scale) {
   if (isVisible()) {
     g.drawImage(
         icon.getImage(),
         x,
         y,
         (int) (icon.getIconWidth() * scale),
         (int) (icon.getIconHeight() * scale),
         this);
   }
 }
Exemplo n.º 5
0
 private static ImageIcon makeRolloverIcon(ImageIcon srcIcon) {
   RescaleOp op =
       new RescaleOp(new float[] {1.2f, 1.2f, 1.2f, 1f}, new float[] {0f, 0f, 0f, 0f}, null);
   BufferedImage img =
       new BufferedImage(
           srcIcon.getIconWidth(), srcIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
   Graphics g = img.getGraphics();
   // g.drawImage(srcIcon.getImage(), 0, 0, null);
   srcIcon.paintIcon(null, g, 0, 0);
   g.dispose();
   return new ImageIcon(op.filter(img, null));
 }
Exemplo n.º 6
0
 private static ImageIcon scale(ImageIcon src) {
   // System.out.println(scaleFactor);
   if (scaleFactor > 1) {
     int w = (int) (scaleFactor * src.getIconWidth());
     int h = (int) (scaleFactor * src.getIconHeight());
     int type = BufferedImage.TYPE_INT_ARGB;
     BufferedImage dst = new BufferedImage(w, h, type);
     Graphics2D g2 = dst.createGraphics();
     g2.drawImage(src.getImage(), 0, 0, w, h, null);
     g2.dispose();
     return new ImageIcon(dst);
   } else return src;
 }
Exemplo n.º 7
0
  public void resize() {

    height = (height == 0) ? 1 : height;

    ratio = (double) image.getIconWidth() / image.getIconHeight();

    Image img = image.getImage();
    width = width - 10;
    // 4 = Image.SCALE_SMOOTH
    Image newimg = img.getScaledInstance(width, (int) (width / ratio), 4);

    label1.setIcon(new ImageIcon(newimg));
  }
  // populate version for corrections
  public void showCorrectionTileUpgrades() {
    // deactivate correctionTokenMode and tokenmode
    correctionTokenMode = false;
    tokenMode = false;

    // activate upgrade panel
    upgradePanel.removeAll();
    GridLayout panelLayout = (GridLayout) upgradePanel.getLayout();
    List<TileI> tiles = orUIManager.tileUpgrades;

    if (tiles == null || tiles.size() == 0) {
      // reset to the number of elements
      panelLayout.setRows(defaultNbPanelElements);
      // set to position 0
      scrollPane.getVerticalScrollBar().setValue(0);
    } else {
      // set to the max of available or the default number of elements
      panelLayout.setRows(Math.max(tiles.size() + 2, defaultNbPanelElements));
      for (TileI tile : tiles) {

        BufferedImage hexImage = getHexImage(tile.getId());
        ImageIcon hexIcon = new ImageIcon(hexImage);

        // Cheap n' Easy rescaling.
        hexIcon.setImage(
            hexIcon
                .getImage()
                .getScaledInstance(
                    (int) (hexIcon.getIconWidth() * GUIHex.NORMAL_SCALE * 0.8),
                    (int) (hexIcon.getIconHeight() * GUIHex.NORMAL_SCALE * 0.8),
                    Image.SCALE_SMOOTH));

        HexLabel hexLabel = new HexLabel(hexIcon, tile.getId());
        hexLabel.setName(tile.getName());
        hexLabel.setTextFromTile(tile);
        hexLabel.setOpaque(true);
        hexLabel.setVisible(true);
        hexLabel.setBorder(border);
        hexLabel.addMouseListener(this);

        upgradePanel.add(hexLabel);
      }
    }

    upgradePanel.add(doneButton);
    upgradePanel.add(cancelButton);

    //      repaint();
    revalidate();
  }
Exemplo n.º 9
0
 private void paintBackground(Graphics2D g2d) {
   int x = c.getBackground().getPosition().getX();
   int y = c.getBackground().getPosition().getY();
   g2d.drawImage(
       c.getBackground().getImage(),
       x - c.getBackground().getDimension().getLength(),
       y,
       Config.getBoardDimension().getLength(),
       Config.getBoardDimension().getHeight(),
       this);
   g2d.drawImage(
       c.getBackground().getImage(),
       x,
       y,
       Config.getBoardDimension().getLength(),
       Config.getBoardDimension().getHeight(),
       this);
   g2d.drawImage(
       c.getBackground().getImage(),
       x + c.getBackground().getDimension().getLength(),
       y,
       Config.getBoardDimension().getLength(),
       Config.getBoardDimension().getHeight(),
       this);
   if (Config.getForeground().compareTo("") == 0) {
     ImageIcon foreground =
         new ImageIcon(
             this.getClass().getResource(Config.getImagePath() + Config.getForeground()));
     g2d.drawImage(
         foreground.getImage(),
         0,
         Config.getBoardDimension().getHeight() - foreground.getIconHeight(),
         Config.getBoardDimension().getLength(),
         foreground.getIconHeight(),
         this);
   }
 }
Exemplo n.º 10
0
  public void paint(Graphics g) {
    super.paint(g);
    if (thumbnail != null) {
      int x = getWidth() / 2 - thumbnail.getIconWidth() / 2;
      int y = getHeight() / 2 - thumbnail.getIconHeight() / 2;
      if (y < 0) {
        y = 0;
      }

      if (x < 5) {
        x = 5;
      }
      thumbnail.paintIcon(this, g, x, y);
    }
  }
Exemplo n.º 11
0
  Jf() {

    j.setBounds(500, 40, 500, 500);
    j.setVisible(true);
    j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    j.setLayout(null);
    ImageIcon image = new ImageIcon("im1.jpg");
    JLabel l = new JLabel(image);
    int m = image.getIconWidth();
    int m1 = image.getIconHeight();
    j.setResizable(false); // frame resize nahi hoga	
    l.setBounds(0, 0, m, m1);
    j.add(l);
    l.add(linfo);
    l.add(lid);
    l.add(fid);
    l.add(lpass);
    l.add(fpass);
    fpass.setEchoChar('*');

    l.add(blogin);
    l.add(bnewaccount);
    l.add(bforget);

    ImageIcon image1 = new ImageIcon("logo1.png");
    JLabel limage = new JLabel(image1);
    l.add(limage);
    limage.setBounds(10, 50, 190, 130);

    Font f = new Font("ALGERIAN", Font.BOLD, 20);
    linfo.setFont(f);
    linfo.setBounds(40, 10, 420, 30);
    lid.setBounds(210, 50, 70, 30);
    fid.setBounds(290, 50, 150, 30);
    lpass.setBounds(210, 90, 70, 30);
    fpass.setBounds(290, 90, 150, 30);
    blogin.setBounds(210, 130, 100, 50);
    bnewaccount.setBounds(320, 130, 160, 20);
    bforget.setBounds(320, 160, 160, 20);
    blogin.setBackground(Color.green);
    bnewaccount.setBackground(Color.cyan);
    bforget.setBackground(Color.pink);

    blogin.addActionListener(new Login());
    bnewaccount.addActionListener(new Account());
    bforget.addActionListener(new Forget());
  }
  /** Show splash - stays up untill user clicks, or closeSplash() is called. */
  public void showSplash() {
    JPanel content = (JPanel) getContentPane();
    content.setBackground(Color.white);

    // Set the window's bounds, centering the window
    ImageIcon im = new ImageIcon(getClass().getResource("/data/Splash.jpg"));
    int width = 450;
    int height = 115;

    if (im == null) {
      im = new ImageIcon();

    } else {
      width = im.getIconWidth() + 10;
      height = im.getIconHeight() + 10;
    }

    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (screen.width - width) / 2;
    int y = (screen.height - height) / 2;
    setBounds(x, y, width, height);
    setAlwaysOnTop(true);
    // Build the splash screen
    //  JLabel title = new JLabel
    // ("CONE: Collocation Network Explorer.", JLabel.CENTER);
    JLabel label = new JLabel(im);
    // JLabel copyrt = new JLabel
    // ("<html>&nbsp;&nbsp;&nbsp;&nbsp;Copyright 2010, David Gullick & Lancaster
    // University.<br/>Thanks to Francois taiani, Paul Rayson, John Mariani and Scott Piao</html>",
    // JLabel.CENTER);
    // copyrt.setFont(new Font("Sans-Serif", Font.BOLD, 12));
    content.add(new JLabel(im));
    // content.add(title, BorderLayout.NORTH);
    // content.add(copyrt, BorderLayout.SOUTH);
    // content.setBorder(BorderFactory.createLineBorder(Color.BLACK, 5));

    addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            setVisible(false);
            closeSplash();
          }
        });

    // Display it
    setVisible(true);
  }
Exemplo n.º 13
0
  /**
   * Read image from bytes
   *
   * @param imageBytes
   * @return
   */
  private BufferedImage getBufferedImageFromBytes(byte[] imageBytes) {
    try {
      // try to read image using ImageIO
      return ImageIO.read(new ByteArrayInputStream(imageBytes));
    } catch (Throwable e) {
      // try to load image trough awt - this is a workaround for Java 8 on OpenJDK on Linux
      ImageIcon icon = new ImageIcon(imageBytes);
      image =
          new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_RGB);
      Graphics g = image.createGraphics();
      // paint the Icon to the BufferedImage.
      icon.paintIcon(null, g, 0, 0);
      g.dispose();

      return image;
    }
  }
Exemplo n.º 14
0
  protected void paintComponent(Graphics g) {
    if (thumbnail == null) {
      loadImage();
    }
    if (thumbnail != null) {
      int x = getWidth() / 2 - thumbnail.getIconWidth() / 2;
      int y = getHeight() / 2 - thumbnail.getIconHeight() / 2;

      if (y < 0) {
        y = 0;
      }

      if (x < 5) {
        x = 5;
      }
      thumbnail.paintIcon(this, g, x, y);
    }
  }
Exemplo n.º 15
0
  /**
   * Draws an emblem (based on current theme) in the bottom left of the given component. Call this
   * in paintComponent() of the component.
   *
   * @param component the component to draw on
   * @param g the Graphics object from paintComponent()
   */
  public static void drawEmblem(JComponent component, Graphics g) {
    Themes currentTheme = Themes.getCurrentTheme();
    ImageIcon image = GUI.createImageIcon("translucent/" + currentTheme.getImageIconPath());

    /*if(Themes.getCurrentTheme() == Themes.SNOW){
        image = GUI.createImageIcon("translucent/snow.png");
    }*/

    int imageWidth = image.getIconWidth();
    int imageHeight = image.getIconHeight();
    // top left corner of where to start drawing
    int topLeftX = component.getWidth() - imageWidth; // x (horizontal) coordinate
    int topLeftY = component.getHeight() - imageHeight; // y (vertical) coordinate

    // draw in bottom right corner
    g.drawImage(image.getImage(), topLeftX, topLeftY, (java.awt.image.ImageObserver) null);
    // g.drawImage(image.getImage(), 0,0, (java.awt.image.ImageObserver)null);
  }
Exemplo n.º 16
0
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    // resize picture to appropriate size
    ImageIcon newPicture = GUI.scaleImage(picture, PICTURE_WIDTH, PICTURE_HEIGHT);

    int width = newPicture.getIconWidth();
    int height = newPicture.getIconHeight();

    // get offsets in order to center picture
    int verticalOffset = (PICTURE_HEIGHT - height) / 2;
    int horizontalOffset = (PICTURE_WIDTH - width) / 2;
    // if the image is thinner than this panel, offset it

    // paint the picture
    g.drawImage(newPicture.getImage(), horizontalOffset, verticalOffset, this);
    // offsets let the image be centered
  }
  // Takes resource name and returns button
  public JButton createButton(String name, String toolTip) {

    // load the image
    String imagePath = "./resources/" + name + ".png";
    ImageIcon iconRollover = new ImageIcon(imagePath);
    int w = iconRollover.getIconWidth();
    int h = iconRollover.getIconHeight();

    // get the cursor for this button
    Cursor cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);

    // make translucent default image
    Image image = createCompatibleImage(w, h, Transparency.TRANSLUCENT);
    Graphics2D g = (Graphics2D) image.getGraphics();
    Composite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f);
    g.setComposite(alpha);
    g.drawImage(iconRollover.getImage(), 0, 0, null);
    g.dispose();
    ImageIcon iconDefault = new ImageIcon(image);

    // make a pressed image
    image = createCompatibleImage(w, h, Transparency.TRANSLUCENT);
    g = (Graphics2D) image.getGraphics();
    g.drawImage(iconRollover.getImage(), 2, 2, null);
    g.dispose();
    ImageIcon iconPressed = new ImageIcon(image);

    // create the button
    JButton button = new JButton();
    button.addActionListener(this);
    button.setIgnoreRepaint(true);
    button.setFocusable(false);
    button.setToolTipText(toolTip);
    button.setBorder(null);
    button.setContentAreaFilled(false);
    button.setCursor(cursor);
    button.setIcon(iconDefault);
    button.setRolloverIcon(iconRollover);
    button.setPressedIcon(iconPressed);

    return button;
  }
  private void updateColors() {
    ImageIcon icon;
    if (selected) {
      panelMain.setBackground(activeBackgroundColor);

      pnlBottom.setBackground(new Color(0xccd1d7));
      icon = UnitUtilWrapper.BitcoinUnitWrapper.getWrapper(UnitUtil.BitcoinUnit.BTC).getBmpSlim();
    } else {
      panelMain.setBackground(inactiveBackGroundColor);

      pnlBottom.setBackground(new Color(0xeeeeee));
      icon = UnitUtilWrapper.BitcoinUnitWrapper.getWrapper(UnitUtil.BitcoinUnit.BTC).getBmpBlack();
    }
    float width = icon.getIconWidth();
    float height = icon.getIconHeight();
    float scale = (float) 1.0f;
    icon.setImage(
        icon.getImage()
            .getScaledInstance((int) (width * scale), (int) (height * scale), Image.SCALE_SMOOTH));
  }
Exemplo n.º 19
0
  /**
   * Constructor public Enemy()
   *
   * <p>This constructor sets the initial variables of the enemy ship, loads the images. It also
   * strats off the ship in randomly either the right or the left direction and sets the images
   * accordingly..
   */
  public Enemy(int speed) {
    this.x = ((int) (Math.random() * (750))) + 5;
    this.y = 0;

    ImageIcon iR = new ImageIcon("resources\\images\\EnemyShipRight.png");
    goingRight = iR.getImage();
    ImageIcon iL = new ImageIcon("resources\\images\\EnemyShipLeft.png");
    goingLeft = iL.getImage();

    double randomSelection = Math.random();
    if (randomSelection < 0.5) {
      speedX = speed;
      mainImage = goingRight;
    } else {
      speedX = -speed;
      mainImage = goingLeft;
    }
    this.width = iR.getIconWidth();
    this.height = iL.getIconHeight();
  }
Exemplo n.º 20
0
  public MainPanel() {
    super(new BorderLayout());
    ActionListener al =
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            JComponent c = (JComponent) e.getSource();
            if (ra.equals(c)) {
              label.setIcon(iia);
            } else if (rb.equals(c)) {
              label.setIcon(iib);
            } else {
              label.setIcon(new ImageIcon(createImage(source)));
            }
          }
        };
    JPanel p = new JPanel();
    ButtonGroup bg = new ButtonGroup();
    for (JRadioButton r : Arrays.asList(ra, rb, rr)) {
      r.addActionListener(al);
      bg.add(r);
      p.add(r);
    }
    ra.setSelected(true);
    add(label);
    add(p, BorderLayout.SOUTH);

    int w = iia.getIconWidth();
    int h = iia.getIconHeight();
    int[] pixelsA = getData(iia, w, h);
    int[] pixelsB = getData(iib, w, h);
    source = new MemoryImageSource(w, h, pixelsA, 0, w);
    for (int i = 0; i < pixelsA.length; i++) {
      if (pixelsA[i] == pixelsB[i]) {
        pixelsA[i] = pixelsA[i] & 0x44FFFFFF;
      }
    }

    setPreferredSize(new Dimension(320, 240));
  }
Exemplo n.º 21
0
  private JLabel makeLabelIcon() {
    ImageIcon i = new ImageIcon(getClass().getResource("duke.gif"));
    Dimension d = new Dimension(i.getIconWidth(), i.getIconHeight());
    final BufferedImage image = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_ARGB);
    Graphics g = image.createGraphics();
    i.paintIcon(null, g, 0, 0);
    g.dispose();
    final JLabel icon =
        new JLabel(i) {
          @Override
          public boolean contains(int x, int y) {
            return super.contains(x, y) && ((image.getRGB(x, y) >> 24) & 0xff) != 0;
          }
        };
    icon.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
    MouseAdapter l =
        new MouseAdapter() {
          private final transient Point start = new Point();
          private Point loc;

          @Override
          public void mousePressed(MouseEvent me) {
            start.setLocation(me.getPoint());
          }

          @Override
          public void mouseDragged(MouseEvent me) {
            loc = icon.getLocation(loc);
            int x = loc.x - start.x + me.getX();
            int y = loc.y - start.y + me.getY();
            icon.setLocation(x, y);
          }
        };
    icon.addMouseListener(l);
    icon.addMouseMotionListener(l);
    icon.setBounds(new Rectangle(22, 22, d.width, d.height));
    return icon;
  }
Exemplo n.º 22
0
 public Dimension getPreferredSize() {
   return new Dimension(1 + image.getIconWidth(), 1 + image.getIconHeight());
 }
  public void showUpgrades() {
    upgradePanel.removeAll();

    // reset to the number of elements
    GridLayout panelLayout = (GridLayout) upgradePanel.getLayout();
    panelLayout.setRows(defaultNbPanelElements);

    if (tokenMode && possibleTokenLays != null && possibleTokenLays.size() > 0) {

      Color fgColour = null;
      Color bgColour = null;
      String text = null;
      String description = null;
      TokenIcon icon;
      ActionLabel tokenLabel;
      tokenLabels = new ArrayList<ActionLabel>();
      for (LayToken action : possibleTokenLays) {
        if (action instanceof LayBaseToken) {
          PublicCompanyI comp = ((LayBaseToken) action).getCompany();
          fgColour = comp.getFgColour();
          bgColour = comp.getBgColour();
          description = text = comp.getName();
          if (action.getSpecialProperty() != null) {
            description += " (" + action.getSpecialProperty().getOriginalCompany().getName() + ")";
          }
        } else if (action instanceof LayBonusToken) {
          fgColour = Color.BLACK;
          bgColour = Color.WHITE;
          BonusToken token = (BonusToken) action.getSpecialProperty().getToken();
          description = token.getName();
          text = "+" + token.getValue();
        }
        icon = new TokenIcon(25, fgColour, bgColour, text);
        tokenLabel = new ActionLabel(icon);
        tokenLabel.setName(description);
        tokenLabel.setText(description);
        tokenLabel.setBackground(defaultLabelBgColour);
        tokenLabel.setOpaque(true);
        tokenLabel.setVisible(true);
        tokenLabel.setBorder(border);
        tokenLabel.addMouseListener(this);
        tokenLabel.addPossibleAction(action);
        tokenLabels.add(tokenLabel);

        upgradePanel.add(tokenLabel);
      }

      setSelectedToken();

    } else if (orUIManager.tileUpgrades == null) {;
    } else if (orUIManager.tileUpgrades.size() == 0) {
      orUIManager.setMessage(LocalText.getText("NoTiles"));
    } else {
      for (TileI tile : orUIManager.tileUpgrades) {
        BufferedImage hexImage = getHexImage(tile.getPictureId());
        ImageIcon hexIcon = new ImageIcon(hexImage);

        // Cheap n' Easy rescaling.
        hexIcon.setImage(
            hexIcon
                .getImage()
                .getScaledInstance(
                    (int) (hexIcon.getIconWidth() * GUIHex.NORMAL_SCALE * 0.8),
                    (int) (hexIcon.getIconHeight() * GUIHex.NORMAL_SCALE * 0.8),
                    Image.SCALE_SMOOTH));

        HexLabel hexLabel = new HexLabel(hexIcon, tile.getId());
        hexLabel.setName(tile.getName());
        hexLabel.setTextFromTile(tile);
        hexLabel.setOpaque(true);
        hexLabel.setVisible(true);
        hexLabel.setBorder(border);
        hexLabel.addMouseListener(this);

        upgradePanel.add(hexLabel);
      }
    }

    upgradePanel.add(doneButton);
    upgradePanel.add(cancelButton);

    // repaint();
    revalidate();
  }
Exemplo n.º 24
0
  public MyFrame(String title, Color col) {
    setTitle(title); // title is set in main method
    setSize(500, 500); // this may need changed but looks ok
    setLocationRelativeTo(null); // sets the location as the centre of the screen
    setResizable(false);

    Container c = getContentPane(); // container to hold the different panels
    c.setBackground(Color.white); // col from main
    c.setLayout(null); // no layout selected so we can place anywhere

    // add to container

    ImageIcon gameLogo =
        new ImageIcon(
            new ImageIcon(getClass().getResource("GameLogobBlank.png"))
                .getImage()
                .getScaledInstance(360, 80, java.awt.Image.SCALE_SMOOTH));
    JPanel logoPanel = new JPanel();
    JLabel logoLabel = new JLabel("", gameLogo, JLabel.CENTER);
    logoPanel.setBounds(50, 45, gameLogo.getIconWidth() + 20, gameLogo.getIconHeight() + 20);
    logoPanel.setBackground(Color.white);
    logoPanel.add(logoLabel);
    c.add(logoPanel);

    ImageIcon qubLogo =
        new ImageIcon(new ImageIcon(getClass().getResource("QUBLogo.png")).getImage());
    JPanel qubLogoPanel = new JPanel();
    JLabel qubLogoLabel = new JLabel("", qubLogo, JLabel.CENTER);
    qubLogoPanel.setBounds(15, 380, qubLogo.getIconWidth() + 10, qubLogo.getIconHeight() + 10);
    qubLogoPanel.setBackground(Color.white);
    qubLogoPanel.add(qubLogoLabel);
    c.add(qubLogoPanel);

    ImageIcon seseLogo =
        new ImageIcon(
            new ImageIcon(getClass().getResource("seseLogo.png"))
                .getImage()
                .getScaledInstance(120, 45, java.awt.Image.SCALE_SMOOTH));
    JPanel seseLogoPanel = new JPanel();
    JLabel seseLogoLabel = new JLabel("", seseLogo, JLabel.CENTER);
    seseLogoPanel.setBounds(350, 390, seseLogo.getIconWidth() + 10, seseLogo.getIconHeight() + 10);
    seseLogoPanel.setBackground(Color.white);
    seseLogoPanel.add(seseLogoLabel);
    c.add(seseLogoPanel);

    JPanel playerPanel = new JPanel(); // new panel for players
    playerPanel.setBounds(92, 200, 316, 27); // location
    playerPanel.setLayout(new GridLayout(1, 2)); // layout as grid
    playerPanel.setOpaque(false);
    c.add(playerPanel); // add to container

    combo.setBackground(Color.white);
    playerPanel.add(numOfP); // label to tell to select num of players
    playerPanel.add(combo); // drop down menu

    players.setEditable(false);
    players.setHorizontalAlignment(JLabel.CENTER);

    combo.addItemListener(
        new ItemListener() { // this is to set the number of players to be displayed
          public void itemStateChanged(ItemEvent ie) {

            if (ie.getStateChange() == ItemEvent.SELECTED) {
              String str =
                  (String)
                      combo
                          .getSelectedItem(); // if the number changes then change the number of
                                              // player message

              if (str == "2") {
                players.setText("2 players selected");
              }

              if (str == "3") {
                players.setText("3 players selected");
              }

              if (str == "4") {
                players.setText("4 players selected");
              }

              if (str == "5") {
                players.setText("5 players selected");
              }

              if (str == "6") {
                players.setText("6 players selected");
              }
            } // closes if statements
          } // closes method
        } // closes action listener
        ); // closes action listener

    JPanel startPanel = new JPanel(); // start panel for start button
    startPanel.setBounds(123, 239, 254, 70); // location
    startPanel.setLayout(new GridLayout(2, 1)); // using a grid layout
    startPanel.add(players); // text box says number of payers
    startPanel.setBackground(Color.white);

    startButton = new JButton();
    startButton.setText(
        "Start Game!"); // button has the label start												// actual start button
    startPanel.add(startButton); // button added
    startButton.addActionListener(startButtonActionListener); // added actionlistener
    c.add(startPanel); // added to container

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // close when closed
    setVisible(true); // takes off invisability cloak
  } // MyFrame constructor
 public int getIconHeight() {
   int height = arrow.getIconHeight();
   if (icon != null) height = Math.max(icon.getIconHeight(), height);
   return height;
 }
Exemplo n.º 26
0
  // Inner class to manage help modal diaglog object.
  class HelpHandler extends JDialog implements ActionListener {
    // Define and initialize AWT container.
    Container c = getContentPane();

    // Define and initialize Swing widgets.
    JButton okButton = new JButton("Check the Java API");
    ImageIcon imageIcon = new ImageIcon("surfing.gif");
    JLabel image = new JLabel(imageIcon);

    // Define and intialize phsyical size dimensions.
    int left = 0;
    int top = 0;
    int buttonWidth = 150;
    int buttonHeight = 25;
    int imageWidth = imageIcon.getIconWidth();
    int imageHeight = imageIcon.getIconHeight();
    int offsetMargin = 20;

    // The dialog width and height are derived from base objects.
    int dialogWidth = imageWidth + offsetMargin;
    int dialogHeight = imageHeight + buttonHeight + (3 * offsetMargin);

    // --------------------------- Constructor -------------------------------/

    // The inner class requires an owning frame and cannot be called from
    // a default constructor.  So, the default constructor is excluded.
    public HelpHandler(Frame owner, boolean modal) {
      super(owner, modal);
      buildDialogBox();
    }

    // -------------------------- Begin Methods ------------------------------/

    // Method to build the dialog box for help.
    private void buildDialogBox() {
      // Set the JDialog window properties.
      setTitle("Learning about Java");
      setResizable(false);
      setSize(dialogWidth, dialogHeight);

      // Define behaviors of container.
      c.setLayout(null);
      c.setBackground(Color.cyan);
      c.add(image);
      c.add(okButton);

      // Set the bounds for the image.
      image.setBounds(
          (dialogWidth / 2) - (imageWidth / 2),
          (top + (offsetMargin / 2)),
          imageWidth,
          imageHeight);

      // Set the behaviors, bounds and action listener for the button.
      okButton.setBounds(
          (dialogWidth / 2) - (buttonWidth / 2),
          (imageHeight + (int) 1.5 * offsetMargin),
          buttonWidth,
          buttonHeight);

      // Set the font to the platform default Font for the object with the
      // properties of bold and font size of 11.
      okButton.setFont(new Font(okButton.getFont().getName(), Font.BOLD, 11));

      // Set foreground and background of JButton(s).
      okButton.setForeground(Color.white);
      okButton.setBackground(Color.blue);

      // The class implements the ActionListener interface and therefore
      // provides an implementation of the actionPerformed() method.  When a
      // class implements ActionListener, the instance handler returns an
      // ActionListener.  The ActionListener then performs actionPerformed()
      // method on an ActionEvent.
      okButton.addActionListener(this);

      // Set the screen and display dialog window in relation to screen size.
      dim = tk.getScreenSize();
      setLocation((dim.width / 2) - (dialogWidth / 2), (dim.height / 2) - (dialogHeight / 2));

      // Display the dialog.
      show();
    } // End of buildDialogBox method.

    // --------------------- Window ActionListener ---------------------------/

    // Class listener based on implementing ActionListener.
    public void actionPerformed(ActionEvent e) {
      // Dispose of the help dialog.
      setVisible(false);
      dispose();
    } // End of actionPerformed method.

    // -------------------------- End Methods --------------------------------/

  } // End of HelpHandler inner class.
Exemplo n.º 27
0
 // getHeight
 public int getHeight() {
   return _image.getIconHeight();
 }