Beispiel #1
0
 public static void main(String[] args) {
   int radius = 500;
   SmileyModel test = new SmileyModel(radius, true);
   FirstSmileyPanel view = new FirstSmileyPanel(test);
   AAPCEventPrinter ep = new AAPCEventPrinter();
   test.addPropertyChangeListener(ep);
   JFrame frame = new JFrame("Smiley of DOOM!!!");
   Container container = frame.getContentPane();
   container.add(view);
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setSize(600, 600);
   frame.setVisible(true);
   int i = 0;
   while (true) {
     test.rotateEye(i);
     i += 10;
     if (i % 90 == 0) {
       test.changeSmile();
       test.setSmile(true);
       // test.setSize(radius+=20);
     }
     try {
       TimeUnit.MILLISECONDS.sleep(100);
     } catch (InterruptedException e) {
       e.printStackTrace();
     }
   }
 }
Beispiel #2
0
  /** Reads the view from the specified uri. */
  @Override
  public void read(URI f, URIChooser chooser) throws IOException {
    try {
      final Drawing drawing = createDrawing();
      InputFormat inputFormat = drawing.getInputFormats().get(0);
      inputFormat.read(f, drawing, true);
      SwingUtilities.invokeAndWait(
          new Runnable() {

            @Override
            public void run() {
              view.getDrawing().removeUndoableEditListener(undo);
              view.setDrawing(drawing);
              view.getDrawing().addUndoableEditListener(undo);
              undo.discardAllEdits();
            }
          });
    } catch (InterruptedException e) {
      InternalError error = new InternalError();
      e.initCause(e);
      throw error;
    } catch (InvocationTargetException e) {
      InternalError error = new InternalError();
      e.initCause(e);
      throw error;
    }
  }
 /**
  * Renders the image at the proper size into <code>bgImage</code>. This method assumes that <code>
  * bgImage</code> is not <code>null</code>.
  *
  * @param width The width of the volatile image to render into.
  * @param height The height of the volatile image to render into.
  * @param hint The scaling hint to use.
  */
 protected void renderImage(int width, int height, int hint) {
   Image master = getMasterImage();
   if (master != null) {
     do {
       Image i = master.getScaledInstance(width, height, hint);
       tracker.addImage(i, 1);
       try {
         tracker.waitForID(1);
       } catch (InterruptedException e) {
         e.printStackTrace();
         bgImage = null;
         return;
       } finally {
         tracker.removeImage(i, 1);
       }
       bgImage.getGraphics().drawImage(i, 0, 0, null);
       tracker.addImage(bgImage, 0);
       try {
         tracker.waitForID(0);
       } catch (InterruptedException e) {
         e.printStackTrace();
         bgImage = null;
         return;
       } finally {
         tracker.removeImage(bgImage, 0);
       }
     } while (bgImage.contentsLost());
   } // End of if (master!=null).
   else {
     bgImage = null;
   }
 }
    private void decompressTile(final File outputFile, int jp2TileX, int jp2TileY)
        throws IOException {
      final int tileIndex = bandInfo.imageLayout.numXTiles * jp2TileY + jp2TileX;
      final Process process =
          new ProcessBuilder(
                  EXE,
                  "-i",
                  imageFile.getPath(),
                  "-o",
                  outputFile.getPath(),
                  "-r",
                  getLevel() + "",
                  "-t",
                  tileIndex + "")
              .directory(cacheDir)
              .start();

      try {
        final int exitCode = process.waitFor();
        if (exitCode != 0) {
          System.err.println("Failed to uncompress tile: exitCode = " + exitCode);
        }
      } catch (InterruptedException e) {
        System.err.println("InterruptedException: " + e.getMessage());
      }
    }
    /*
     * Executed in event dispatching thread
     */
    @Override
    public void done() {

      try {

        String value = get();
        myMessage.messageChanged(value);

      } catch (InterruptedException e) {
        e.printStackTrace();
      } catch (ExecutionException e) {
        e.printStackTrace();
      } catch (CancellationException e) {
        myMessage.messageChanged("Operation Cancelled");
      } catch (Exception e) {
        e.printStackTrace();
      }

      Toolkit.getDefaultToolkit().beep();
      // startButton.setEnabled(true);
      // cancelButton.setEnabled(false);
      setCursor(null); // turn off the wait cursor
      StartButton.setEnabled(true);
      cancelButton.setEnabled(false);
      taskOutput.append("Done!\n");
    }
  public void testEmptyHeader() {
    fFrame = new JFrame("Test Window");

    // Create a panel to hold all other components
    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BorderLayout());

    // Create a new table instance
    MyTableModel myModel = new MyTableModel();
    fTable = new JTable(myModel);

    // Add the table to a scrolling pane
    JScrollPane scrollPane = new JScrollPane(fTable);
    topPanel.add(scrollPane, BorderLayout.CENTER);

    fFrame.getContentPane().setLayout(new BorderLayout());
    fFrame.getContentPane().add(BorderLayout.CENTER, topPanel);

    fFrame.setSize(400, 450);
    fFrame.setLocation(20, 20);
    fFrame.setVisible(true);
    try {
      Thread.sleep(500);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    JTableHeader header = fTable.getTableHeader();
    assertTrue(
        "JTableHeader greater than 5 pixels tall with empty string first element.",
        header.getSize().height > 5);
    fFrame.setVisible(false);
    fFrame.dispose();
  }
Beispiel #7
0
  public void actionPerformed(ActionEvent evt) {

    if (evt.getSource() == Rubric) {
      Rubric.setLabel("Loading...");
      try {
        Thread.sleep((1000));

      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      removeAll();

      @SuppressWarnings("unused")
      RubricEditor_GUI RE = new RubricEditor_GUI();

    } else if (evt.getSource() == GradeSheet) {

      // Change the text on the button for fun
      GradeSheet.setLabel("Loading...");
      try {
        Thread.sleep((1000));
      } catch (InterruptedException e) {

        e.printStackTrace();
      }
      removeAll();

      @SuppressWarnings("unused")
      GradeSheetEditor_GUI GSE = new GradeSheetEditor_GUI();
    }
  }
 public void sleep(long timeToSleep) {
   try {
     Thread.sleep(timeToSleep);
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
Beispiel #9
0
  public void run() {
    MOVE_PREV = MOVE_DOWN;

    System.out.println("INIT!");
    map = new int[mapX][mapY];

    for (int i = 0; i < map.length; i++) {
      for (int j = 0; j < map[i].length; j++) {
        map[i][j] = 0;
      }
    }
    map[blockP.x][blockP.y] = 1;
    //    	map[0][20] = 1;

    StdDraw.setXscale(-1.0, 1.0);
    StdDraw.setYscale(-1.0, 1.0);

    // initial values

    // double vx = 0.015, vy = 0.023;     // velocity

    // main animation loop
    while (true) {

      drawGame();
      try {
        Thread.sleep(100);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      movePrev();
    }
  }
  /** Initialise. */
  public synchronized void initialise() {

    // wait until application is properly initialised
    while (applicationService == null) {
      // idle in this thread
      try {
        this.wait(6000);
      } catch (InterruptedException e) {
        logger.warn("e.getMessage() = " + e.getMessage());
      }

      if (applicationService != null && applicationService.getErrorLoggerService() != null) {
        this.applicationService.getErrorLoggerService().registerListener(this);
      }
    }

    // set LNF first to avoid component UI errors
    LookAndFeelUtils.setDefaultLNF();

    errorPane = new JXErrorPane();
    errorPane.setPreferredSize(new Dimension(400, 300));
    errorPane.setIcon(ImageUtils.getIcon(ImageUtils.IconName.WARNING_ICON_48));
    errorPane.setErrorReporter(this);
    errorDialog = JXErrorPane.createDialog(null, errorPane);
    errorDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
    errorDialog.pack();
  }
    public void run() {
      try {
        while (scriptRunning) {
          if (!parent.isPaused() && parent.game.isLoggedIn() && status != "Logging back in") {
            int rand = randomGenerator.nextInt(30);
            switch (rand) {
              case 1:
                parent.camera.setAngle(Methods.random(0, 360));
                break;
              case 2:
                parent.camera.setPitch(Methods.random(40, 100));
                break;
              case 3:
                parent.mouse.setSpeed(Methods.random(5, 9));
                break;
              case 5:
                parent.camera.setPitch(Methods.random(40, 100));
                parent.camera.setAngle(Methods.random(0, 360));
                break;
              default:
                break;
            }
          }

          sleep(Methods.random(2000, 5000));
        }
      } catch (InterruptedException e) {
        log(e.getMessage());
      }
    }
Beispiel #12
0
  private static void exec(String command) {
    try {
      System.out.println("Invoking: " + command);
      Process p = Runtime.getRuntime().exec(command);

      // get standard output
      BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
      String line;
      while ((line = input.readLine()) != null) {
        System.out.println(line);
      }
      input.close();

      // get error output
      input = new BufferedReader(new InputStreamReader(p.getErrorStream()));
      while ((line = input.readLine()) != null) {
        System.out.println(line);
      }
      input.close();

      p.waitFor();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
 public void run() {
   try {
     performIntersection(this.gridPosition);
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
Beispiel #14
0
  @Override
  public void run() {

    try {
      if (Fecs.getApplicationContext() == null) return;

      Long currentTime = System.currentTimeMillis();
      double deltaTime = (currentTime - lastUpdateTime) * 0.001;

      if (getEngineState() == STATE_START) { // last bit is 1 = started
        int s = getCircumstanceState() - 1; // 0 is null state(error)
        if (s >= CircumstanceType.values().length || s < 0)
          throw new Exception("unstable state value with " + String.valueOf(s));
        Circumstance.get(CircumstanceType.values()[s])
            .setParameter("currentTime", currentTime)
            .setParameter("deltaTime", deltaTime)
            .trigger();
        for (Cabin cabin : cabins.values()) updateCabin(cabin, deltaTime);
      }

      lastUpdateTime = currentTime;

      draw();
    } catch (Exception e) {
      logger.error(e.getMessage(), e);
    } finally {
      try {
        Thread.sleep(1);
      } catch (InterruptedException e) {
        logger.error(e.getMessage(), e);
      }
      SwingUtilities.invokeLater(this);
    }
  }
  public static void main(String[] args) {
    JFrame frame = new JFrame("options");

    frame.setSize(new Dimension(500, 300));
    frame.getContentPane().add(new PackagerOptionsPanel(null));

    frame.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
            e.getWindow().dispose();
          }

          @Override
          public void windowClosed(WindowEvent e) {
            System.exit(0);
          }
        });

    try {
      SwingUtilities.invokeAndWait(new PackAndShowFrameWorker(frame));
    } catch (InterruptedException e) {
      // Immediately reasserts the exception by interrupting the caller thread itself
      Thread.currentThread().interrupt();

      e.printStackTrace();
    } catch (InvocationTargetException e) {
      e.printStackTrace();
    }
  }
Beispiel #16
0
  /**
   * Construct a GIFEncoder. The constructor will convert the image to an indexed color array.
   * <B>This may take some time.</B>
   *
   * <p>
   *
   * @param image The image to encode. The image <B>must</B> be completely loaded.
   * @exception AWTException Will be thrown if the pixel grab fails. This can happen if Java runs
   *     out of memory. It may also indicate that the image contains more than 256 colors.
   */
  public GIFEncoder(Image image) throws AWTException {
    width_ = (short) image.getWidth(null);
    height_ = (short) image.getHeight(null);

    int values[] = new int[width_ * height_];
    PixelGrabber grabber = new PixelGrabber(image, 0, 0, width_, height_, values, 0, width_);

    try {
      if (grabber.grabPixels() != true)
        throw new AWTException("Grabber returned false: " + grabber.status()); // $NON-NLS-1$
    } catch (InterruptedException ex) {
      ex.printStackTrace();
    }

    byte r[][] = new byte[width_][height_];
    byte g[][] = new byte[width_][height_];
    byte b[][] = new byte[width_][height_];
    int index = 0;
    for (int y = 0; y < height_; ++y)
      for (int x = 0; x < width_; ++x) {
        r[x][y] = (byte) ((values[index] >> 16) & 0xFF);
        g[x][y] = (byte) ((values[index] >> 8) & 0xFF);
        b[x][y] = (byte) ((values[index]) & 0xFF);
        ++index;
      }
    ToIndexedColor(r, g, b);
  }
 // Fecha o jogo; M�todo join() espera a thread morrer.
 public synchronized void stop() {
   running = false;
   try {
     thread.join();
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
Beispiel #18
0
  public game() {
    this.setBounds(0, 0, 1000, 1000); // position,, size,,
    this.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent arg0) {
            if (gaming) {
              switch (arg0.getKeyCode()) {
                case KeyEvent.VK_LEFT:
                  shift(-1);
                  break;
                case KeyEvent.VK_RIGHT:
                  shift(1);
                  break;
                case KeyEvent.VK_UP:
                  {
                    int[] temp = new int[9];
                    for (int i = 0; i < 9; i++) {
                      temp[i] = pos[i];
                    }
                    changeShape(temp);
                    if (!crash(temp)) {
                      changeShape(pos);
                    }
                    break;
                  }
                case KeyEvent.VK_DOWN:
                  SLEEPTIME = 100;
                  break;
                case KeyEvent.VK_ENTER:
                  pause = !pause;
                  break;
              }
            }
          }

          public void keyReleased(KeyEvent arg0) {
            if (arg0.getKeyCode() == KeyEvent.VK_DOWN) {
              SLEEPTIME = 500;
            }
          }
        });
    this.setTitle("Tetris");
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.setVisible(true);
    while (!gameover) {
      try {

        Thread.sleep(SLEEPTIME);
        if (!pause) {
          moveDown();
          repaint();
        }
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
  }
Beispiel #19
0
 public synchronized void stop() {
   if (!running) return;
   running = false;
   try {
     gameThread.join();
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
Beispiel #20
0
  // 为了随时判断,把hitTank函数摆在这里(随时刷新)
  @Override
  public void run() {
    // 每隔50ms 重绘制
    while (true) {
      try {
        Thread.sleep(10);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      // 判断击中敌人坦克
      this.hitEnemyTank();
      // 判断敌人子弹是否击中我方坦克的函数
      this.hitMe();

      //            //判断是否需要给坦克加入新的子弹
      //            for(int i=0;i<enemyTanks.size();i++)
      //            {
      //                EnemyTank et=enemyTanks.get(i);
      //                if (et.alive)
      //                {
      //                    if(et.bb.size()<5){
      //                        //没有子弹
      //                        //添加
      //                        System.out.println("et.bb.size()<5="+et.bb.size());
      //                        Bullet b=null;
      //                        switch (et.direct)
      //                        {
      //                            case 0:
      //                                //创建一颗子弹,把子弹加入到向量
      //                                b=new Bullet(et.x+10,et.y,0);
      //                                et.bb.add(b);
      //                                break;
      //                            case 1:
      //                                b=new Bullet(et.x+30,et.y+10,1);
      //                                et.bb.add(b);
      //                                break;
      //                            case 2:
      //                                b=new Bullet(et.x+10,et.y+30,2);
      //                                et.bb.add(b);
      //                                break;
      //                            case 3:
      //                                b=new Bullet(et.x,et.y+10,3);
      //                                et.bb.add(b);
      //                                break;
      //
      //                        }
      //
      //                        //启动子弹线程
      //                        Thread t =new Thread(b);
      //                        t.start();
      //                    }
      //                }
      //            }

      this.repaint();
    }
  }
Beispiel #21
0
 private void grabPixels(PixelGrabber grabber) {
   try {
     grabber.grabPixels();
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
   // if (grabber.getColorModel() != ColorModel.getRGBdefault()) {
   //	System.err.println("Warning: found other colormodel than default.");
   // }
 }
Beispiel #22
0
 public void run() {
   while (true) {
     repaint();
     try {
       Thread.sleep(FLASH_TIME);
     } catch (InterruptedException e) {
       e.printStackTrace();
     }
   }
 }
Beispiel #23
0
 // Other public methods
 @Override
 public void run() {
   while (clockThread != null) {
     repaint();
     try {
       clockThread.sleep(1000);
     } catch (InterruptedException e) {
       System.out.println(e.getMessage());
     }
   }
 }
 public void run() {
   while (run) {
     try {
       sleep(DOTS_DELAY);
     } catch (InterruptedException e) {
       logger.warn("InterruptedException,  " + e.getMessage());
     }
     messageLabel.setText(DOTS[dotIndex] + message + DOTS[dotIndex]);
     dotIndex = (dotIndex + 1) % DOTS.length;
   }
 }
 public void run() {
   Thread t = Thread.currentThread();
   while (t == gameloop) {
     try {
       Thread.sleep(20);
     } catch (InterruptedException e) {
       e.printStackTrace();
     }
     repaint();
   }
 }
  private synchronized void waitForDraw() {
    while (!_isDrawOK) {
      try {
        wait();

      } catch (InterruptedException ex) {
        /** TODO: remove */
        ex.printStackTrace();
      }
    }
    _isDrawOK = false;
  }
 public void run() {
   try {
     while (isRunning() && listenerButton.isSelected()) {
       for (int i = 0; i < OldInterfaces.size(); i++) {
         compare(OldInterfaces.get(i));
       }
       Thread.sleep(100);
     }
   } catch (final InterruptedException e) {
     e.printStackTrace();
   }
 }
Beispiel #28
0
 public void run() {
   long beginTime = Zoeos.getZoeosTime();
   while (Zoeos.getZoeosTime() < beginTime + displayTime) {
     try {
       Thread.sleep(flashInterval);
     } catch (InterruptedException e) {
       e.printStackTrace();
     }
     switchState();
   }
   FlashMsg.this.dispose();
 }
 public void progress() {
   int i = 1;
   int j = 0;
   for (i = 1; i <= 100; i++) {
     progressbar1.setValue(i);
     try {
       Thread.sleep(25);
     } catch (InterruptedException e1) {
       e1.printStackTrace();
     }
   }
 }
 public void start() {
   int i = 0;
   while (true) {
     lbl_rollNo.setFont(fonts.get(i));
     i = (i + 1) % fonts.size();
     // Code to sleep for 3 seconds
     try {
       Thread.currentThread().sleep(3000);
     } catch (InterruptedException iex) {
       iex.printStackTrace();
     }
   }
 }