コード例 #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
ファイル: IPToolKit.java プロジェクト: Teena/iptoolkit
  /** ****************** Display Gray Scale version of image opened *************** */
  void grayImageDisplay(int width, int height, int pix[]) {

    img_temp = createImage(new MemoryImageSource(width, height, pix, 0, width));
    ImageIcon imgI = new ImageIcon();
    imgI.setImage(img_temp);
    lbl_gray.setIcon(imgI);
  }
コード例 #3
0
ファイル: THA.java プロジェクト: tlulu/Tetris-Platformer
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   setBackground(Color.black);
   add(l);
   add(s);
   drawSpecialLines(g);
   g.setColor(Color.white);
   g.fillOval(30, 100, 75, 75);
   g.setColor(Color.blue);
   g.fillRect(getWidth() / 2, getHeight() / 2, (int) bl, 10);
   g.fillRect(getWidth() / 2, getHeight() / 2 + 40, (int) gl, 10);
   g.fillRect(getWidth() / 2, getHeight() / 2 + 80, (int) ll, 10);
   g.fillRect(getWidth() / 2, getHeight() / 2 + 120, (int) sl, 10);
   g.drawImage(bullet.getImage(), 30, getHeight() / 2 - 10, 20, 20, null);
   g.drawImage(grenade.getImage(), 30, getHeight() / 2 + 40 - 10, 20, 20, null);
   g.drawImage(laser.getImage(), 30, getHeight() / 2 + 80 - 10, 20, 20, null);
   g.drawImage(shotgun.getImage(), 30, getHeight() / 2 + 120 - 10, 20, 20, null);
   g.setColor(Color.yellow);
   if (gunTrack == 0) {
     g.drawRect(30, getHeight() / 2 - 10, 20, 20);
   } else if (gunTrack == 1) {
     g.drawRect(30, getHeight() / 2 + 40 - 10, 20, 20);
   } else if (gunTrack == 2) {
     g.drawRect(30, getHeight() / 2 + 80 - 10, 20, 20);
   } else {
     g.drawRect(30, getHeight() / 2 + 120 - 10, 20, 20);
   }
 }
コード例 #4
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();
 }
コード例 #5
0
ファイル: IPToolKit.java プロジェクト: Teena/iptoolkit
  /** ************** Display result of processed Image *********** */
  void imageResultDisplay(int width, int height, int pix[]) {

    img_temp = createImage(new MemoryImageSource(width, height, pix, 0, width));
    ImageIcon imgIcon = new ImageIcon();
    imgIcon.setImage(img_temp);
    lbl_res.setIcon(imgIcon);
  }
コード例 #6
0
ファイル: Resource.java プロジェクト: bozhink/Code-Chunks
 /**
  * Gets an Image.
  *
  * @return the image
  */
 public Image getImage() {
   ImageIcon icon = getIcon();
   if (icon != null) {
     return icon.getImage();
   }
   return null;
 }
コード例 #7
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);
   }
 }
コード例 #8
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;
 }
コード例 #9
0
 public void loadImage(File f) {
   if (f == null) {
     thumbnail = null;
   } else {
     ImageIcon tmpIcon = new ImageIcon(f.getPath());
     if (tmpIcon.getIconWidth() > 90) {
       thumbnail =
           new ImageIcon(tmpIcon.getImage().getScaledInstance(90, -1, Image.SCALE_DEFAULT));
     } else {
       thumbnail = tmpIcon;
     }
   }
 }
コード例 #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);
    }
  }
コード例 #11
0
  /**
   * Returns an object which represents the data to be transferred. The class of the object returned
   * is defined by the representation class of the flavor.
   *
   * @param flavor the requested flavor for the data
   * @throws IOException if the data is no longer available in the requested flavor.
   * @throws UnsupportedFlavorException if the requested data flavor is not supported.
   * @see DataFlavor#getRepresentationClass
   */
  public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
    if (isRicherFlavor(flavor)) {
      return getRicherData(flavor);
    } else if (isImageFlavor(flavor)) {
      if (image != null && image.getImage() instanceof RenderedImage) {
        if (flavor.equals(DataFlavor.imageFlavor)) {
          return image.getImage();
        } else {
          ByteArrayOutputStream stream = new ByteArrayOutputStream();
          ImageIO.write((RenderedImage) image.getImage(), "bmp", stream);

          return new ByteArrayInputStream(stream.toByteArray());
        }
      }
    } else if (isHtmlFlavor(flavor)) {
      String data = getHtmlData();
      data = (data == null) ? "" : data;

      if (String.class.equals(flavor.getRepresentationClass())) {
        return data;
      } else if (Reader.class.equals(flavor.getRepresentationClass())) {
        return new StringReader(data);
      } else if (InputStream.class.equals(flavor.getRepresentationClass())) {
        return new ByteArrayInputStream(data.getBytes());
      }
      // fall through to unsupported
    } else if (isPlainFlavor(flavor)) {
      String data = getPlainData();
      data = (data == null) ? "" : data;

      if (String.class.equals(flavor.getRepresentationClass())) {
        return data;
      } else if (Reader.class.equals(flavor.getRepresentationClass())) {
        return new StringReader(data);
      } else if (InputStream.class.equals(flavor.getRepresentationClass())) {
        return new ByteArrayInputStream(data.getBytes());
      }
      // fall through to unsupported

    } else if (isStringFlavor(flavor)) {
      String data = getPlainData();
      data = (data == null) ? "" : data;

      return data;
    }

    throw new UnsupportedFlavorException(flavor);
  }
コード例 #12
0
  /**
   * Sets the icon for the given file.
   *
   * @param file the file to set an icon for
   * @return the byte array containing the thumbnail
   */
  private byte[] getFileThumbnail(File file) {
    byte[] bytes = null;
    if (FileUtils.isImage(file.getName())) {
      try {
        ImageIcon image = new ImageIcon(file.toURI().toURL());
        int width = image.getIconWidth();
        int height = image.getIconHeight();

        if (width > THUMBNAIL_WIDTH) width = THUMBNAIL_WIDTH;
        if (height > THUMBNAIL_HEIGHT) height = THUMBNAIL_HEIGHT;

        bytes = ImageUtils.getScaledInstanceInBytes(image.getImage(), width, height);
      } catch (MalformedURLException e) {
        if (logger.isDebugEnabled()) logger.debug("Could not locate image.", e);
      }
    }
    return bytes;
  }
コード例 #13
0
  public ClientMainForm() {

    super("Halli Galli"); // 타이틀 제목
    im = new ImageIcon("img/imicon.jpg"); // 타이틀바 왼쪽에 넣을 작은 이미지 아이콘 생성
    this.setIconImage(im.getImage()); // 타이틀바에 이미지 넣기
    setLayout(card); // BorderLayout
    add("LOAD", ld);
    new Thread(ld).start(); // 로딩쓰레드 실행
    add("LOG", login); // 2.login창
    add("WR", wr); // 3.WaitRoom창
    add("GW", gw); // 4.GAME Window창
    setSize(800, 600); // window창 크기 설정
    setLocation(270, 170); // window창 위치 설정
    setVisible(true); // 보여지게 함11
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    setResizable(false); // window창 고정(늘어나지 않음)
    setLocationRelativeTo(null); // 게임 프레임을 화면 정중앙에 위치시킴

    ld.st.addActionListener(this); // 로딩의 enter버튼
    login.bt1.addActionListener(this); // 회원가입 버튼 누르면
    login.bt2.addActionListener(this); // 로그인 버튼 누르면
    wr.b1.addActionListener(this); // 로그인 버튼 누르면

    wr.b2.addActionListener(this); // 방만들기 버튼 누르면
    wr.b3.addActionListener(this); // 방들어가기 버튼 누르면
    wr.b8.addActionListener(this); // 도움말 버튼 누르면
    wr.b9.addActionListener(this); // 게임종료 버튼 누르면
    wr.tf.addActionListener(this);

    mr.b1.addActionListener(this); // 방만들기창에서 확인버튼 누르면
    gw.b1.addActionListener(this); // 게임창에서 전송버튼 누르면
    gw.b4.addActionListener(this); // 게임창에서 준비버튼 누르면
    gw.b5.addActionListener(this); // 게임창에서 시작버튼 누르면
    gw.b6.addActionListener(this); // 게임창에서 나가기 누르면
    gw.tf.addActionListener(this); // 게임창에서 채팅하면
    gw.cardOpen.addActionListener(this);
    gw.bell.addActionListener(this);

    mID.b1.addActionListener(this);
    mID.b2.addActionListener(this);
    mID.b3.addActionListener(this);

    wr.table1
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              @Override
              public void valueChanged(ListSelectionEvent e) {
                if (wr.table1.getSelectedRow() > -1) // 방번호가 0 이상이면
                {
                  rowNum = wr.table1.getSelectedRow();
                  System.out.println(rowNum);
                }
              }
            });
  }
コード例 #14
0
ファイル: Resource.java プロジェクト: bozhink/Code-Chunks
 /**
  * Gets an ImageIcon.
  *
  * @return the icon
  */
 public ImageIcon getIcon() {
   if (icon == null && isAnImage) {
     icon = new ImageIcon(getURL());
     if (icon.getIconWidth() < 1) {
       icon = null;
       isAnImage = false;
     }
   }
   return icon;
 }
コード例 #15
0
ファイル: GMap.java プロジェクト: joshuasm/gmap-viewer
  /**
   * 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();
  }
コード例 #16
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();
  }
コード例 #17
0
ファイル: THA.java プロジェクト: tlulu/Tetris-Platformer
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   g.drawImage(intro.getImage(), 0, 0, this.getWidth(), this.getHeight(), null);
   g.drawImage(
       tetris.getImage(), 90, 100, this.getWidth() - 90 * 2, this.getHeight() / 2 - 100, null);
 }
コード例 #18
0
ファイル: THA.java プロジェクト: tlulu/Tetris-Platformer
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   setBackground(Color.black);
   g.drawImage(gameOver.getImage(), 80, 100, 300, 300, null);
 }
コード例 #19
0
ファイル: THA.java プロジェクト: tlulu/Tetris-Platformer
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   g.drawImage(intro.getImage(), 0, 0, this.getWidth(), this.getHeight(), null);
 }
コード例 #20
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.
コード例 #21
0
ファイル: Ssys3.java プロジェクト: scyptnex/computing
  public Ssys3() {
    store = new Storage();
    tableSorter = new TableRowSorter<Storage>(store);
    jobs = new LinkedList<String>();

    makeGUI();
    frm.setSize(800, 600);
    frm.addWindowListener(
        new WindowListener() {
          public void windowActivated(WindowEvent evt) {}

          public void windowClosed(WindowEvent evt) {
            try {
              System.out.println("joining EDT's");
              for (EDT edt : encryptDecryptThreads) {
                edt.weakStop();
                try {
                  edt.join();
                  System.out.println("  - joined");
                } catch (InterruptedException e) {
                  System.out.println("  - Not joined");
                }
              }
              System.out.println("saving storage");
              store.saveAll(tempLoc);
            } catch (IOException e) {
              e.printStackTrace();
              System.err.println(
                  "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nFailed to save properly\n\n!!!!!!!!!!!!!!!!!!!!!!!!!");
              System.exit(1);
            }
            clean();
            System.exit(0);
          }

          public void windowClosing(WindowEvent evt) {
            windowClosed(evt);
          }

          public void windowDeactivated(WindowEvent evt) {}

          public void windowDeiconified(WindowEvent evt) {}

          public void windowIconified(WindowEvent evt) {}

          public void windowOpened(WindowEvent evt) {}
        });
    ImageIcon ico = new ImageIcon(ICON_NAME);
    frm.setIconImage(ico.getImage());
    frm.setLocationRelativeTo(null);
    frm.setVisible(true);

    // load config
    storeLocs = new ArrayList<File>();
    String ossl = "openssl";
    int numThreadTemp = 2;
    boolean priorityDecryptTemp = true;
    boolean allowExportTemp = false;
    boolean checkImportTemp = true;
    try {
      Scanner sca = new Scanner(CONF_FILE);
      while (sca.hasNextLine()) {
        String ln = sca.nextLine();
        if (ln.startsWith(CONF_SSL)) {
          ossl = ln.substring(CONF_SSL.length());
        } else if (ln.startsWith(CONF_THREAD)) {
          try {
            numThreadTemp = Integer.parseInt(ln.substring(CONF_THREAD.length()));
          } catch (Exception exc) {
            // do Nothing
          }
        } else if (ln.equals(CONF_STORE)) {
          while (sca.hasNextLine()) storeLocs.add(new File(sca.nextLine()));
        } else if (ln.startsWith(CONF_PRIORITY)) {
          try {
            priorityDecryptTemp = Boolean.parseBoolean(ln.substring(CONF_PRIORITY.length()));
          } catch (Exception exc) {
            // do Nothing
          }
        } else if (ln.startsWith(CONF_EXPORT)) {
          try {
            allowExportTemp = Boolean.parseBoolean(ln.substring(CONF_EXPORT.length()));
          } catch (Exception exc) {
            // do Nothing
          }
        } else if (ln.startsWith(CONF_CONFIRM)) {
          try {
            checkImportTemp = Boolean.parseBoolean(ln.substring(CONF_CONFIRM.length()));
          } catch (Exception exc) {
            // do Nothing
          }
        }
      }
      sca.close();
    } catch (IOException e) {

    }
    String osslWorks = OpenSSLCommander.test(ossl);
    while (osslWorks == null) {
      ossl =
          JOptionPane.showInputDialog(
              frm,
              "Please input the command used to run open ssl\n  We will run \"<command> version\" to confirm\n  Previous command: "
                  + ossl,
              "Find open ssl",
              JOptionPane.OK_CANCEL_OPTION);
      if (ossl == null) {
        System.err.println("Refused to provide openssl executable location");
        System.exit(1);
      }
      osslWorks = OpenSSLCommander.test(ossl);
      if (osslWorks == null)
        JOptionPane.showMessageDialog(
            frm, "Command " + ossl + " unsuccessful", "Unsuccessful", JOptionPane.ERROR_MESSAGE);
    }
    if (storeLocs.size() < 1)
      JOptionPane.showMessageDialog(
          frm,
          "Please select an initial sotrage location\nIf one already exists, or there are more than one, please select it");
    while (storeLocs.size() < 1) {
      JFileChooser jfc = new JFileChooser();
      jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
      if (jfc.showOpenDialog(frm) != JFileChooser.APPROVE_OPTION) {
        System.err.println("Refused to provide an initial store folder");
        System.exit(1);
      }
      File sel = jfc.getSelectedFile();
      if (sel.isDirectory()) storeLocs.add(sel);
    }
    numThreads = numThreadTemp;
    priorityExport = priorityDecryptTemp;
    allowExport = allowExportTemp;
    checkImports = checkImportTemp;

    try {
      PrintWriter pw = new PrintWriter(CONF_FILE);
      pw.println(CONF_SSL + ossl);
      pw.println(CONF_THREAD + numThreads);
      pw.println(CONF_PRIORITY + priorityExport);
      pw.println(CONF_EXPORT + allowExport);
      pw.println(CONF_CONFIRM + checkImports);
      pw.println(CONF_STORE);
      for (File fi : storeLocs) {
        pw.println(fi.getAbsolutePath());
      }
      pw.close();
    } catch (IOException e) {
      System.err.println("Failed to save config");
    }

    File chk = null;
    for (File fi : storeLocs) {
      File lib = new File(fi, LIBRARY_NAME);
      if (lib.exists()) {
        chk = lib;
        // break;
      }
    }

    char[] pass = null;
    if (chk == null) {
      JOptionPane.showMessageDialog(
          frm,
          "First time run\n  Create your password",
          "Create Password",
          JOptionPane.INFORMATION_MESSAGE);
      char[] p1 = askPassword();
      char[] p2 = askPassword();
      boolean same = p1.length == p2.length;
      for (int i = 0; i < Math.min(p1.length, p2.length); i++) {
        if (p1[i] != p2[i]) same = false;
      }
      if (same) {
        JOptionPane.showMessageDialog(
            frm, "Password created", "Create Password", JOptionPane.INFORMATION_MESSAGE);
        pass = p1;
      } else {
        JOptionPane.showMessageDialog(
            frm, "Passwords dont match", "Create Password", JOptionPane.ERROR_MESSAGE);
        System.exit(1);
      }
    } else {
      pass = askPassword();
    }
    sec = OpenSSLCommander.getCommander(chk, pass, ossl);
    if (sec == null) {
      System.err.println("Wrong Password");
      System.exit(1);
    }
    store.useSecurity(sec);
    store.useStorage(storeLocs);

    tempLoc = new File("temp");
    if (!tempLoc.exists()) tempLoc.mkdirs();
    // load stores
    try {
      store.loadAll(tempLoc);
      store.fireTableDataChanged();
    } catch (IOException e) {
      System.err.println("Storage loading failure");
      System.exit(1);
    }

    needsSave = false;
    encryptDecryptThreads = new EDT[numThreads];
    for (int i = 0; i < encryptDecryptThreads.length; i++) {
      encryptDecryptThreads[i] = new EDT(i);
      encryptDecryptThreads[i].start();
    }

    updateStatus();
    txaSearch.grabFocus();
  }
コード例 #22
0
ファイル: DrawPanel.java プロジェクト: bungaca/abstools
  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();
    }
  }