Ejemplo n.º 1
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();
    }
  }
 /**
  * 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;
   }
 }
Ejemplo n.º 3
0
  public void initialize(Stage stage, Scene scene) {
    this.stage = stage;
    this.scene = scene;

    try {
      ClientCommunicationManager.getInstance().subscribeAll();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    btn_refresh.setOnAction(
        event -> {
          try {
            ClientCommunicationManager.getInstance().subscribeAll();
            updateRobotList();
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        });

    list_robots
        .getSelectionModel()
        .selectedIndexProperty()
        .addListener((obervable, oldValue, newValue) -> loadSelected());

    ClientCommunicationManager clientCommunicationManager =
        ClientCommunicationManager.getInstance();
    updateRobotList();
    Timeline updateTimer =
        new Timeline(
            new KeyFrame(
                Duration.millis(50),
                new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent event) {
                    Collection<String> oldRobots =
                        RobotRepository.getInstance().getRobots().keySet();
                    clientCommunicationManager.processIncomingObjects();
                    Collection<String> newRobots =
                        RobotRepository.getInstance().getRobots().keySet();
                    if (!oldRobots.equals(newRobots)) {
                      updateRobotList();
                    }
                  }
                }));
    updateTimer.setCycleCount(Timeline.INDEFINITE);
    updateTimer.play();
  }
Ejemplo n.º 4
0
  public void appear(final CardGui card) {
    moving = card;
    player1.animations.add(moving);
    Thread t =
        new Thread(
            () -> {
              moving.setBounds(925 - 62, 609 - 93, 0, 0);
              int i = 0, j = 0;
              while (i <= 124 || j <= 186) {
                try {
                  if (i <= 124) {
                    i++;
                    moving.setBounds(925 - 62, 609 - 93, i, j);
                    Thread.sleep(1);
                  }
                  if (j <= 186) {
                    j++;
                    moving.setBounds(925 - 62, 609 - 93, i, j);

                    Thread.sleep(1);
                  }
                } catch (InterruptedException e) {
                  e.printStackTrace();
                }
              }
              i = 925 - 62;

              while (i >= 652) {
                i--;
                try {
                  Thread.sleep(1);
                } catch (InterruptedException e) {
                  e.printStackTrace();
                }
                moving.setLocation(i, 609 - 93);
              }

              player1.animations.remove(moving);
              player1.repairListeners(false);
              PlayGui.player.pdeck.textField.setText(
                  "cards left " + PlayGui.player.pdeck.Deck.cardsLeft());
              player1.cardDrawn = 1;
              PlayGui.player.pdeck.textField.repaint();
              setVisible(true);
              repaint();
            });
    t.start();
  }
Ejemplo n.º 5
0
 public void sleep(long timeToSleep) {
   try {
     Thread.sleep(timeToSleep);
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 6
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();
     }
   }
 }
Ejemplo n.º 7
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();
    }
  }
Ejemplo n.º 8
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);
  }
Ejemplo n.º 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();
    }
  }
Ejemplo n.º 10
0
  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();
  }
 public void run() {
   try {
     performIntersection(this.gridPosition);
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 12
0
  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();
    }
  }
Ejemplo n.º 13
0
    /*
     * 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");
    }
Ejemplo n.º 14
0
 // Fecha o jogo; M�todo join() espera a thread morrer.
 public synchronized void stop() {
   running = false;
   try {
     thread.join();
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 15
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();
    }
  }
Ejemplo n.º 16
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();
      }
    }
  }
Ejemplo n.º 17
0
 public synchronized void stop() {
   if (!running) return;
   running = false;
   try {
     gameThread.join();
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 18
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.");
   // }
 }
Ejemplo n.º 19
0
 public void run() {
   while (true) {
     repaint();
     try {
       Thread.sleep(FLASH_TIME);
     } catch (InterruptedException e) {
       e.printStackTrace();
     }
   }
 }
 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;
  }
Ejemplo n.º 22
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();
 }
Ejemplo n.º 23
0
 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 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();
   }
 }
Ejemplo n.º 25
0
 @Override
 protected void paintComponent(Graphics g) {
   if (deltaY == deltaY0 && Klahvikuular.isUpDown) {
     deltaY = deltaY0 + 1;
   }
   if (deltaY == (deltaY0 + 1) && Klahvikuular.isUpDown == false) {
     deltaY = deltaY0;
   }
   super.paintComponent(g);
   if (y >= 0 && y < 270) {
     g.drawImage(space, x, y1, null);
     y1 = y1 + deltaY;
   }
   if (y > 269) {
     y = y1;
     y1 = -1090;
   }
   y = y + deltaY;
   g.drawImage(space, x, y, null);
   g.drawImage(mutebutton, 560, 10, null);
   g.setColor(Color.WHITE);
   g.setFont(StartWindow.font);
   if (KosmoseOdysseia.katseid == KosmoseOdysseia.lubatudKatseteArv) {
     if (!explosionEnded) {
       playExplosion(g, explosionFrames);
       try {
         Thread.sleep(50);
       } catch (InterruptedException e) {
         e.printStackTrace();
       }
     }
   } else g.drawImage(rocket, 250, 110, null);
   g.drawString("Skoor: " + Integer.toString(skoor), 10, 20);
   try {
     Thread.sleep(100);
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
   repaint();
 }
 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();
     }
   }
 }
Ejemplo n.º 27
0
  public void run() {
    long lastTime = System.nanoTime();
    double nsPerTick = 1000000000D / 60D;

    int ticks = 0;
    int frames = 0;

    long lastTimer = System.currentTimeMillis();
    double delta = 0;

    init();

    while (Game.isRunning()) {
      long now = System.nanoTime();
      delta += (now - lastTime) / nsPerTick;
      lastTime = now;
      boolean shouldRender = false;

      while (delta >= 1) {
        ticks++;
        tick();
        delta -= 1;
        shouldRender = true;
      }

      try {
        Thread.sleep(2);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }

      if (shouldRender) {
        frames++;
        render();
      }

      if (System.currentTimeMillis() - lastTimer >= 1000) {
        lastTimer += 1000;
        getFrame()
            .setTitle(
                "JavaGame - Version "
                    + WordUtils.capitalize(game_Version).substring(1, game_Version.length()));
        fps = frames;
        tps = ticks;
        frames = 0;
        ticks = 0;
      }
    }
  }
Ejemplo n.º 28
0
 public void go() {
   // TODO Pause the game after several blocks
   do {
     try {
       Thread.sleep(1000L);
     } catch (InterruptedException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
     movedown();
     rowcheck();
   } while (bottom == false);
   bottom = false;
   blockgen();
 }
Ejemplo n.º 29
0
 public static void ensureLoaded(Image img) throws Exception {
   // System.err.println("In ensureloaded");
   mediatracker.addImage(img, 0);
   try {
     mediatracker.waitForAll();
     if (mediatracker.getErrorsAny() != null) {
       mediatracker.removeImage(img);
       throw new Exception("Error loading image");
     }
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
   mediatracker.removeImage(img);
   // System.err.println("Out ensureloaded");
 }
Ejemplo n.º 30
0
  /**
   * イメージをロードする。
   *
   * @param panel パネルへの参照。
   */
  private void loadImage(MainPanel panel) {
    MediaTracker tracker = new MediaTracker(panel);

    // 台車のイメージを読み込む
    cartImage = Toolkit.getDefaultToolkit().getImage(getClass().getResource("cart.gif"));
    tracker.addImage(cartImage, 0);

    try {
      tracker.waitForAll();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    // 台車の大きさ
    cartWidth = cartImage.getWidth(panel);
    cartHeight = cartImage.getHeight(panel);
  }