Пример #1
1
 public MapBuilder(String name, File toLoad, File toSave, String tileDir) {
   super(name);
   currTileImg = null;
   currTileLoc = "";
   try {
     System.out.println(tileDir);
     currTileImg = new ImageIcon(getTile(tileDir, 0, 0, DISPLAY_SCALE));
     currTileLoc = "0_0";
   } catch (IOException e) {
     System.out.println("Generating current tile failed.");
     System.out.println(e);
     System.exit(0);
   }
   currTileDisplay = new JLabel(new ImageIcon(scaleImage(currTileImg.getImage(), 2)));
   this.input = toLoad;
   output = toSave;
   this.tileDir = tileDir;
   if (toLoad != null) {
     try {
       backEnd = loadMap(toLoad);
     } catch (FileNotFoundException e) {
       System.err.println("Could not find input file.");
       System.exit(0);
     }
   } else {
     backEnd = emptyMap(DEFAULT_WIDTH, DEFAULT_HEIGHT);
   }
   mapWidth = backEnd.getWidth();
   mapHeight = backEnd.getHeight();
 }
Пример #2
0
 public void mouseClicked(MouseEvent e) {
   Tile t = (Tile) e.getSource();
   ImageIcon temp = (ImageIcon) t.getIcon();
   currTileImg = new ImageIcon(scaleImage(temp.getImage(), DISPLAY_SCALE));
   currTileDisplay.setIcon(new ImageIcon(scaleImage(temp.getImage(), DISPLAY_SCALE * 2)));
   currTileLoc = t.getSource();
 }
Пример #3
0
 // method overload the constructor so you can have ImageIcon buttons, Image buttons, or String
 // buttons (like JButton);
 public BillyButton(ImageIcon img, String filename) {
   // set up images with the black one for when its selected
   this.img = img;
   enabled = true;
   image = img.getImage();
   this.filename = filename;
   BWimg = new ImageIcon("Real Pok Pics\\" + filename + "Chosen.gif");
   BWimage = BWimg.getImage();
   mode = "ImageIcon";
   visible = true;
 }
Пример #4
0
  public FileNameRenderer(JTable table) {
    Border b = UIManager.getBorder("Table.noFocusBorder");
    if (Objects.isNull(b)) { // Nimbus???
      Insets i = focusCellHighlightBorder.getBorderInsets(textLabel);
      b = BorderFactory.createEmptyBorder(i.top, i.left, i.bottom, i.right);
    }
    noFocusBorder = b;

    p.setOpaque(false);
    panel.setOpaque(false);

    // http://www.icongalore.com/ XP Style Icons - Windows Application Icon, Software XP Icons
    nicon = new ImageIcon(getClass().getResource("wi0063-16.png"));
    sicon =
        new ImageIcon(
            p.createImage(
                new FilteredImageSource(nicon.getImage().getSource(), new SelectedImageFilter())));

    iconLabel = new JLabel(nicon);
    iconLabel.setBorder(BorderFactory.createEmptyBorder());

    p.add(iconLabel, BorderLayout.WEST);
    p.add(textLabel);
    panel.add(p, BorderLayout.WEST);

    Dimension d = iconLabel.getPreferredSize();
    dim.setSize(d);
    table.setRowHeight(d.height);
  }
 /** Stop animating this instance of <code>AbstractIconAnimator</code>. */
 public void stop() {
   icon.setImageObserver(null);
   icon.getImage().flush();
   Map map = (Map) contexts.get(context);
   if (map != null) {
     map.remove(key);
     if (map.size() == 0) contexts.remove(context);
   }
 }
Пример #6
0
  public MainPanel() {
    super(new GridLayout(0, 1));
    orgImage = new ImageIcon(getClass().getResource("i03-10.gif"));

    JPanel p1 = new JPanel(new GridLayout(1, 2));
    p1.add(makeLabel(makeGrayImageIcon1(orgImage.getImage()), "ColorConvertOp"));
    p1.add(makeLabel(makeGrayImageIcon2(orgImage.getImage()), "TYPE_BYTE_GRAY"));
    add(p1);
    add(makeLabel(makeGrayImageIcon3(orgImage.getImage()), "GrayFilter.createDisabledImage"));
    JPanel p3 = new JPanel(new GridLayout(1, 2));
    p3.add(makeLabel(makeGrayImageIcon4(orgImage.getImage()), "GrayFilter(true, 50)"));
    p3.add(makeLabel(makeGrayImageIcon5(orgImage.getImage()), "GrayImageFilter"));
    add(p3);

    p1.setBackground(Color.WHITE);
    p3.setBackground(Color.WHITE);
    setBackground(Color.WHITE);
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setPreferredSize(new Dimension(320, 240));
  }
Пример #7
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;
 }
Пример #8
0
 //     private BufferedImage makeBI(String str) {
 //         BufferedImage image;
 //         try {
 //             image = ImageIO.read(getClass().getResource(str));
 //         } catch (IOException ioe) {
 //             ioe.printStackTrace();
 //             return null;
 //         }
 //         return image;
 //     }
 private static int[] getData(ImageIcon imageIcon, int w, int h) {
   Image img = imageIcon.getImage();
   BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
   Graphics g = image.createGraphics();
   g.drawImage(img, 0, 0, null);
   g.dispose();
   return ((DataBufferInt) (image.getRaster().getDataBuffer())).getData();
   //         int[] pixels = new int[w * h];
   //         try {
   //             new PixelGrabber(image, 0, 0, width, height, pixels, 0, width).grabPixels();
   //         } catch (InterruptedException ex) {
   //             ex.printStackTrace();
   //         }
   //         return pixels;
 }
Пример #9
0
  /**
   * Creates a new GMap object based on a base directory specified in the constructure.
   *
   * @param cache - Base directory to search for cached image folders.
   */
  public GMap(String cache) {
    // data source
    this.gDataSourceMap = new GDataSourceMap(cache + "/map_cache");
    this.gDataSourceSatellite = new GDataSourceSatellite(cache + "/sat_cache");
    // this.gDataSourceOverlay = new GDataSourceOverlay(cache+"/overlay_cache");
    this.gDataSourceHybrid = new GDataSourceHybrid(cache + "/hybrid_cache", gDataSourceSatellite);

    // build default image
    defaultImage = getDefaultImage(GDataSource.sourceSize.width, GDataSource.sourceSize.height);

    // init gdraw draw object
    this.gDraw = new GDraw();

    // mode
    this.mode = MAP_MODE;

    // icon
    ImageIcon loadImage = new ImageIcon("images/google.png");
    googleImage = loadImage.getImage();
  }
 /**
  * Create an object to animate <code>icon</code> on the given <code>Component</code> at the
  * substructure location represented by the <code>key</code>.
  *
  * @param context Component on which the animation is to be painted
  * @param key Substructure location identifier
  * @param icon The animated icon
  */
 public JGraphAbstractIconAnimator(final Component context, final Object key, ImageIcon icon) {
   this.context = context;
   this.key = key;
   // Make a copy, since the original icon may be used repeatedly.
   this.icon = new ImageIcon(icon.getImage());
   this.icon.setImageObserver(
       new ImageObserver() {
         public boolean imageUpdate(Image image, int flags, int x, int y, int w, int h) {
           if ((flags & (FRAMEBITS | ALLBITS)) != 0) {
             repaint(context, key);
           }
           return (flags & (ALLBITS | ABORT)) == 0;
         }
       });
   Map map = (Map) contexts.get(context);
   if (map == null) {
     map = new HashMap();
     contexts.put(context, map);
   }
   map.put(key, this);
 }
Пример #11
0
  // get an image from the given filename
  private static Image getImage(String filename) {

    // to read from file
    ImageIcon icon = new ImageIcon(filename);

    // try to read from URL
    if ((icon == null) || (icon.getImageLoadStatus() != MediaTracker.COMPLETE)) {
      try {
        URL url = new URL(filename);
        icon = new ImageIcon(url);
      } catch (Exception e) {
        /* not a url */
      }
    }

    // in case file is inside a .jar
    if ((icon == null) || (icon.getImageLoadStatus() != MediaTracker.COMPLETE)) {
      URL url = StdDraw.class.getResource(filename);
      if (url == null) throw new RuntimeException("image " + filename + " not found");
      icon = new ImageIcon(url);
    }

    return icon.getImage();
  }
Пример #12
0
  public void drawBuffer() {
    Graphics2D b = buffer.createGraphics(); // DrawPanel
    Graphics2D pl_b = buffer.createGraphics();
    Graphics2D pl_c = buffer.createGraphics();
    rkt = buffer.createGraphics();
    AffineTransform rkt_aff = new AffineTransform();
    Graphics2D envi[] = new Graphics2D[amountEnv];
    AffineTransform enviTrans[] = new AffineTransform[amountEnv];

    b.setColor(Color.BLACK);
    b.fillRect(0, 0, w, h);

    // #if (Default)
    // @
    // #elif (Blue_White)
    // @        	ii_bg = new ImageIcon("imgs/Hintergrund/HgBlauWeiss1.gif");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Blue_White_Green)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/HgBlauWeissGruen.gif");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Purple_White)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/HgLilaWeiss.gif");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Glass)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrundglass05.gif");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Lava)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrundlava01.gif");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Limba)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrundlimba.gif");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Old)
    ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrundoldpnt01.gif");
    img_bg = ii_bg.getImage();
    b.drawImage(img_bg, w, w, this);
    // #elif (Ov_Paper)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrundov_paper.gif");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Paper)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrundpaper05.gif");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Univ)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrunduniv01.jpg");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Water)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrundwater01.jpg");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Water_2)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrundwater05.jpg");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #endif

    b.setColor(Color.gray);
    b.fillRect(0, 0, w, 25); // oben
    b.fillRect(0, h - 50, w, 25); // unten
    b.fillRect(0, 0, 25, h); // links
    b.fillRect(w - 35, 0, 30, h); // rechts
    b.setColor(Color.WHITE);

    // rocket
    // #if (tar)
    // #if (Rectangle)
    // @               if (current_Player.isRocket()){
    // @                   rkt_aff.rotate(current_Player.getDegree(), sch.getX(), sch.getY());
    // @                   rkt.setTransform(rkt_aff);
    // @                   System.out.println("Rok X:"+sch.getX()+" Rok Y:"+sch.getY());
    // @                   rkt.drawRect(sch.getX()+ current_Player.getWidth()/2, sch.getY() +
    // current_Player.getHeight()/2, kaliber, kaliber);} // Rocket 4Eck
    // #endif
    // #if (Oval)
    // @               if (current_Player.isRocket()){
    // @                   b.drawOval(sch.getX()+ current_Player.getWidth()/2, sch.getY() +
    // current_Player.getHeight()/2, kaliber, kaliber);} // Rocket Oval
    // #endif
    // #if (aa31)
    // @                 if (current_Player.isRocket()){
    // @                     try {
    // @                        rocketFire = ImageIO.read(new File("imgs/aa31.gif"));
    // @                        rkt_aff.rotate(current_Player.getDegree(), sch.getX(), sch.getY());
    // @                        rkt.setTransform(rkt_aff);
    // @                        rkt.drawImage(rocketFire, null, (int)sch.getX(), (int)sch.getY());
    // @                        //rkt.drawImage(rocketFire, null, (int)current_Player.getX(),
    // (int)current_Player.getY());
    // @                    } catch (IOException e) {
    // @                    }
    // @                 }
    // #endif
    // #if (Portal)
    // @                 if (current_Player.isRocket()){
    // @                     try {
    // @                        rocketFire = ImageIO.read(new File("imgs/portal.gif"));
    // @                        rkt_aff.rotate(current_Player.getDegree(), sch.getX(), sch.getY());
    // @                        rkt.setTransform(rkt_aff);
    // @                        rkt.drawImage(rocketFire, null,
    // sch.getX()+current_Player.getWidth()/2, sch.getY()+current_Player.getHeight()/2);
    // @                     } catch (IOException e) {
    // @                     }
    // @                 }
    // #endif
    // #if (Nino)
    // @                 if (current_Player.isRocket()){
    // @                     try {
    // @                        rocketFire = ImageIO.read(new File("imgs/nino.gif"));
    // @                        rkt_aff.rotate(current_Player.getDegree(), sch.getX(), sch.getY());
    // @                        rkt.setTransform(rkt_aff);
    // @                        rkt.drawImage(rocketFire, null,
    // sch.getX()+current_Player.getWidth()/2, sch.getY()+current_Player.getHeight()/2);
    // @                     } catch (IOException e) {
    // @                     }
    // @                 }
    // #endif
    // #endif

    for (int i = 0; i <= amountEnv - 1; i++) {
      envi[i] = buffer.createGraphics();
      enviTrans[i] = new AffineTransform();
      envi[i].setTransform(enviTrans[i]);
      envi[i].drawImage(env[i].getImg(), env[i].getX(), env[i].getY(), this);
    }

    for (int i = 0; i < 8; i++) {
      if (powerUps[i].isAktiv()) {
        b.setColor(powerUps[i].getCol());
        b.drawImage(powerUps[i].getImg(), powerUps[i].getX(), powerUps[i].getY(), this);
      }
    }

    b.setColor(Color.WHITE);
    b.drawString("BP: " + current_Player.getBp(), 10, 20);
    b.drawString("TP P1/P2: " + player_1.getTp() + " / " + player_2.getTp(), 100, 20);

    if (current_Player.getSch().getEnd_X() != 0 && current_Player.getSch().getEnd_Y() != 0) {
      b.setColor(Color.YELLOW);
      b.drawLine(
          (int) current_Player.getSch().getStart_X(),
          (int) current_Player.getSch().getStart_Y(),
          (int) current_Player.getSch().getEnd_X(),
          (int) current_Player.getSch().getEnd_Y());
      b.setColor(Color.WHITE);
      for (int i = 0; i < current_Player.getSch().getArImg().length; i++) {
        if (current_Player.getSch().getArImg()[i] != null && current_Player.getSch().isIsActive()) {
          b.drawImage(
              current_Player.getSch().getArImg()[i],
              (int) current_Player.getSch().getEnd_X()
                  - current_Player.getSch().getArImg()[i].getWidth(this) / 2,
              (int) current_Player.getSch().getEnd_Y()
                  - current_Player.getSch().getArImg()[i].getHeight(this) / 2,
              (int)
                  (current_Player.getSch().getArImg()[i].getWidth(this)
                      * (current_Player.getSch().getSpeed() / 150)),
              (int)
                  (current_Player.getSch().getArImg()[i].getHeight(this)
                      * (current_Player.getSch().getSpeed() / 150)),
              this);
          if (timeCounter == 75) {
            System.out.println("----------------------><---------------------");
            if (player_1
                .getBounds()
                .intersects(
                    (int) current_Player.getSch().getEnd_X()
                        - current_Player.getSch().getArImg()[i].getWidth(this) / 2,
                    (int) current_Player.getSch().getEnd_Y()
                        - current_Player.getSch().getArImg()[i].getHeight(this) / 2,
                    (int)
                        (current_Player.getSch().getArImg()[i].getWidth(this)
                            * (current_Player.getSch().getSpeed() / 150)),
                    (int)
                        (current_Player.getSch().getArImg()[i].getHeight(this)
                            * (current_Player.getSch().getSpeed() / 150)))) {
              player_1.setTp(player_1.getTp() - (int) current_Player.getSch().getSpeed() / 4);
              System.out.println("----------------------> P1 <---------------------");
            }
            if (player_2
                .getBounds()
                .intersects(
                    (int) current_Player.getSch().getEnd_X()
                        - current_Player.getSch().getArImg()[i].getWidth(this) / 2,
                    (int) current_Player.getSch().getEnd_Y()
                        - current_Player.getSch().getArImg()[i].getHeight(this) / 2,
                    (int)
                        (current_Player.getSch().getArImg()[i].getWidth(this)
                            * (current_Player.getSch().getSpeed() / 150)),
                    (int)
                        (current_Player.getSch().getArImg()[i].getHeight(this)
                            * (current_Player.getSch().getSpeed() / 150)))) {
              player_2.setTp(player_2.getTp() - (int) current_Player.getSch().getSpeed() / 4);
              System.out.println("----------------------> P2 <---------------------");
            }
          }
        }
        if (timeCounter >= 150) {
          timeCounter = 0;
          current_Player.getSch().setIsActive(false);
          current_Player.getSch().setEnd_X(0);
          current_Player.getSch().setEnd_Y(0);
        }
        if (current_Player.getSch().isIsActive()) timeCounter += 1;
        System.out.println("timecounter: " + timeCounter);
      }
    }

    if (player_1.getTp() <= 0) b.drawString("SPIELER 2 HAT GEWONNEN !", w / 2, h / 2);
    if (player_2.getTp() <= 0) b.drawString("SPIELER 1 HAT GEWONNEN !", w / 2, h / 2);

    current_Player.setStop(false);
    b.setColor(Color.red);

    AffineTransform a = new AffineTransform();
    a.rotate(
        current_Player.getDegree(),
        current_Player.getX() + current_Player.getWidth() / 2,
        current_Player.getY() + current_Player.getHeight() / 2);
    ((Graphics2D) pl_b).setTransform(a);
    pl_b.drawImage(
        current_Player.getImg(), (int) current_Player.getX(), (int) current_Player.getY(), this);
    System.out.println(
        "P1 X:" + (int) current_Player.getX() + " P1 Y:" + (int) current_Player.getY());
    System.out.println("P1 W:" + current_Player.getWidth() + " P1 H:" + current_Player.getHeight());
    AffineTransform a2 = new AffineTransform();
    a2.rotate(
        other_Player.getDegree(),
        other_Player.getX() + other_Player.getWidth() / 2,
        other_Player.getY() + other_Player.getHeight() / 2);
    ((Graphics2D) pl_c).setTransform(a2);
    pl_c.drawImage(
        other_Player.getImg(), (int) other_Player.getX(), (int) other_Player.getY(), this);

    if (current_Player.isCollision() == true) {
      current_Player.setStop(true);
      if (timecount > 10) {
        b.setColor(Color.WHITE);
        b.drawString("C O L L I S I O N !", (int) w / 2 - 50, (int) h / 2);
        timecount--;
      } else {
        timecount = 0;
        current_Player.setBp(0);
        current_Player.setX(300);
        current_Player.setY(100);
        current_Player.getSch().setEnd_X(1);
        current_Player.getSch().setEnd_Y(1);
        current_Player.getSch().setStart_X(1);
        current_Player.getSch().setStart_Y(1);
      }
      b.dispose();
    }
  }