private void scaleImage() {
   Image img =
       back.getScaledInstance(scx(back.getWidth()), scy(back.getHeight()), Image.SCALE_SMOOTH);
   back =
       new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
   Graphics g = back.getGraphics();
   g.drawImage(img, 0, 0, null);
   g.dispose();
 }
  private void Timer(ActionEvent evt) {
    // TODO Auto-generated method stub
    try {
      int minBus = 110;
      int maxBus = 120;
      double minAfkLat = 42.302;
      double maxAfkLat = 42.304;
      System.out.println("Timer");
      timer.stop();
      MapMarker init = new MapMarker(theLatitude, theLongitude);
      String theMapURIAsString =
          (String) MapLookup.getMap(theLatitude, theLongitude, init).substring(0, 87);
      int testint2 = 0;
      for (Listener l : theListeners) {
        // if(l.Latitude != 9999 && Float.parseFloat(l.BusID.split("#")[1]) < maxBus &&
        // Float.parseFloat(l.BusID.split("#")[1]) > minBus)    //Bussar beroende på buss nummer
        // if(l.Latitude != 9999 && l.Latitude > minAfkLat && l.Latitude < maxAfkLat)
        // //Possible afk busses
        // if(l.Latitude != 9999 && ( l.Latitude < minAfkLat || l.Latitude > maxAfkLat))
        // //Exclude afk busses
        if (l.Latitude != 9999.0) // All busses
        {
          theMapURIAsString += "|";
          theMapURIAsString += Float.toString(l.Latitude) + "," + Float.toString(l.Longitude);
        }
      }
      theMapURIAsString += "&sensor=false&key=AIzaSyBR_wUAQ3iPM2e8WeoQIUw9c3xLJPRGZL8";
      // System.out.println("HEIR COWMES F****R\n" + theMapURIAsString + "\nFUCKER IS COMMEN");

      String[] GetRidOfinitMarker = theMapURIAsString.split("42.358543,-71.096178\\|");
      // String[] GetRidOfinitMarker = theMapURIAsString.split("42.303113,-71.109925\\|"); //afk
      // bussar
      String GottenRidOfinitMarker = GetRidOfinitMarker[0] + GetRidOfinitMarker[1];

      String test = theMapURIAsString.split("&markers=")[1];
      String[] testa = test.split("\\|");
      // for(String v : testa)System.out.println(v);  //alla inkomna positioner
      // Retrieve map from Google Maps.
      // URL theMapURI = new URL(theMapURIAsString);
      URL theMapURI = new URL(GottenRidOfinitMarker); // URL Utan init marker
      theMap = ImageIO.read(theMapURI.openStream());

      // Create map image scaled to size of the application window size.
      imagePanel1.setImage(
          theMap.getScaledInstance(
              imagePanel1.getWidth(), imagePanel1.getHeight(), Image.SCALE_AREA_AVERAGING));

      // Display map image.
      imagePanel1.repaint();
    } catch (Exception ex) {
      timer.start();
    }
    timer.start();
  }
Пример #3
0
  static Icon reescala(Icon ic, int maxW, int maxH) {
    if (ic == null) {
      return null;
    }
    if (ic.getIconHeight() == maxH && ic.getIconWidth() == maxW) {
      return ic;
    }

    BufferedImage bi =
        new BufferedImage(ic.getIconHeight(), ic.getIconWidth(), BufferedImage.TYPE_INT_ARGB);

    Graphics g = bi.createGraphics();
    ic.paintIcon(null, g, 0, 0);
    g.dispose();

    Image bf = bi.getScaledInstance(maxW, maxH, Image.SCALE_SMOOTH);

    return new ImageIcon(bf);
  }
Пример #4
0
 public Image toImage(int width, int height) {
   return _i.getScaledInstance(width, height, Image.SCALE_SMOOTH);
   // return _i.getScaledInstance(width, height, Image.SCALE_FAST);
 }
Пример #5
0
 public Image toScaledImage() {
   return _i.getScaledInstance(
       (int) (getWidth() * _scale), (int) (getHeight() * _scale), Image.SCALE_SMOOTH);
 }
Пример #6
0
  private void makeMenuScreen() {
    menu = new JPanel();
    menu.setBackground(Color.BLACK);
    menu.setLayout(null);
    menu.setBounds(0, 0, width, height);

    try {
      BufferedImage menuIMG =
          ImageIO.read(this.getClass().getResource("/Resources/MenuBackground.png"));
      // BufferedImage menuIMG = ImageIO.read(new
      // File("M:/ComputerProgrammingJava/InsaneMouse_03/src/Resources/MenuBackground.png"));
      menuIMGL =
          new JLabel(
              new ImageIcon(
                  menuIMG.getScaledInstance(
                      (int) (width * 0.8), (int) (height * 0.8), Image.SCALE_SMOOTH)));
      menuIMGL.setBounds(0, 0, width, height);
    } catch (Exception e) {
    }

    highscoreL = new JLabel(String.valueOf(highscore));
    highscoreL.setBackground(Color.darkGray);
    highscoreL.setBounds((width / 2) + 100, (height / 2) + 70, 500, 100);
    highscoreL.setForeground(Color.white);

    easy = new JButton("Easy");
    hard = new JButton("Hard");

    easy.addActionListener(this);
    hard.addActionListener(this);

    easy.setBounds((width / 2) - 60, (height / 2) - 50, 120, 20);
    hard.setBounds((width / 2) - 60, height / 2 - 10, 120, 20);

    onePlayerRB = new JRadioButton("One Player");
    twoPlayerRB = new JRadioButton("Two Player");
    mouseRB = new JRadioButton("Mouse (Player 1)");
    keyboardRB = new JRadioButton("Keyboard (Player 1)");
    keyboardSpeedS1 = new JSlider(JSlider.HORIZONTAL, 10, 300, 50);
    keyboardSpeedS2 = new JSlider(JSlider.HORIZONTAL, 10, 300, 50);
    musicCB = new JCheckBox("Music");

    onePlayerRB.setBackground(null);
    twoPlayerRB.setBackground(null);
    mouseRB.setBackground(null);
    keyboardRB.setBackground(null);
    keyboardSpeedS1.setBackground(null);
    keyboardSpeedS2.setBackground(null);
    musicCB.setBackground(null);

    onePlayerRB.setForeground(Color.WHITE);
    twoPlayerRB.setForeground(Color.WHITE);
    mouseRB.setForeground(Color.WHITE);
    keyboardRB.setForeground(Color.WHITE);
    keyboardSpeedS1.setForeground(Color.WHITE);
    keyboardSpeedS2.setForeground(Color.WHITE);
    musicCB.setForeground(Color.WHITE);

    ButtonGroup playerChoice = new ButtonGroup();
    playerChoice.add(onePlayerRB);
    playerChoice.add(twoPlayerRB);
    onePlayerRB.setSelected(true);

    ButtonGroup peripheralChoice = new ButtonGroup();
    peripheralChoice.add(mouseRB);
    peripheralChoice.add(keyboardRB);
    mouseRB.setSelected(true);

    musicCB.setSelected(true);

    onePlayerRB.setBounds((width / 2) + 100, (height / 2) - 50, 100, 20);
    twoPlayerRB.setBounds((width / 2) + 100, (height / 2) - 30, 100, 20);
    mouseRB.setBounds((width / 2) + 100, (height / 2), 200, 20);
    keyboardRB.setBounds((width / 2) + 100, (height / 2) + 20, 200, 20);
    keyboardSpeedS1.setBounds(width / 2 - 120, height / 2 + 100, 200, 50);
    keyboardSpeedS2.setBounds(width / 2 - 120, height / 2 + 183, 200, 50);
    musicCB.setBounds((width / 2) + 100, (height / 2) + 50, 100, 20);

    keyboardSpeedL1 = new JLabel("Keyboard Speed (Player One)");
    keyboardSpeedL1.setForeground(Color.WHITE);
    keyboardSpeedL1.setBounds(width / 2 - 113, height / 2 + 67, 200, 50);

    keyboardSpeedL2 = new JLabel("Keyboard Speed (Player Two)");
    keyboardSpeedL2.setForeground(Color.WHITE);
    keyboardSpeedL2.setBounds(width / 2 - 113, height / 2 + 150, 200, 50);

    howTo = new JButton("How To Play");
    howTo.addActionListener(this);
    howTo.setBounds((width / 2) - 60, height / 2 + 30, 120, 20);

    try {
      BufferedImage howToIMG = ImageIO.read(this.getClass().getResource("/Resources/HowTo.png"));
      // BufferedImage howToIMG = ImageIO.read(new
      // File("M:/ComputerProgrammingJava/InsaneMouse_03/src/Resources/HowTo.png"));
      howToIMGL = new JLabel(new ImageIcon(howToIMG));
      howToIMGL.setBounds(
          width / 2 - howToIMG.getWidth() / 2,
          height / 2 - howToIMG.getHeight() / 2,
          howToIMG.getWidth(),
          howToIMG.getHeight());
    } catch (Exception e) {
    }

    howToBack = new JButton("X");
    howToBack.setBounds(
        (int) (width / 2 + width * 0.25) - 50, (int) (height / 2 - height * 0.25), 50, 50);
    howToBack.setBackground(Color.BLACK);
    howToBack.setForeground(Color.WHITE);
    howToBack.addActionListener(this);

    menu.add(easy);
    menu.add(hard);
    menu.add(howTo);
    menu.add(highscoreL);
    menu.add(onePlayerRB);
    menu.add(twoPlayerRB);
    menu.add(mouseRB);
    menu.add(keyboardRB);
    menu.add(keyboardSpeedL1);
    menu.add(keyboardSpeedL2);
    menu.add(keyboardSpeedS1);
    menu.add(keyboardSpeedS2);
    menu.add(musicCB);
    menu.add(menuIMGL);

    back = new JButton("Back");
    back.setBounds(width / 2 - 40, height / 2, 100, 20);
    back.addActionListener(this);
    back.setVisible(false);
    this.add(back);
  }