예제 #1
0
 public Stars() {
   setPreferredSize(new Dimension(150, 150));
   setBackground(new Color(0, 86, 141));
   appDisplay = new JFrame("Stars");
   appDisplay.getContentPane().add(this);
   appDisplay.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   appDisplay.pack();
   appDisplay.setVisible(true);
   timer = new Timer(DELAY, null);
   timer.addActionListener(new StarListener());
   timer.start();
 }
예제 #2
0
 public GamePanel() {
   bird = new Bird();
   bottomWall = new Wall(600);
   topWall = new Wall(1000);
   score = 0;
   isDead = false;
   moverTimer = new Timer(30, new GameMotion());
   moverTimer.start();
   scoreTimer = new Timer(2400, new ScoreCounter());
   scoreTimer.start();
   addKeyListener(new KeyAdapter());
   setFocusable(true);
 }
예제 #3
0
    public void initializeGameObjects() {
      // instantiate ball, paddle, and brick configuration
      ball = new Ball();
      paddle = new Paddle();
      bconfig = new BrickConfiguration();

      // set up timer to run GameMotion() every 10ms
      timer = new Timer(10, new GameMotion());
      timer.start();
    }
예제 #4
0
 @Override
 public void paintComponent(Graphics g) {
   g.setColor(Color.WHITE);
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D) g;
   if (isDead) {
     g2.setColor(Color.BLACK);
     g2.setFont(new Font("Serif", Font.PLAIN, 30));
     g2.drawString("Game Over!", 300, 300);
     g2.drawString("Your final score was " + score, 250, 330);
     moverTimer.stop();
     scoreTimer.stop();
   } else {
     topWall.paint(g2);
     bottomWall.paint(g2);
     bird.paint(g2);
     g2.setColor(Color.BLACK);
     g2.setFont(new Font("Serif", Font.PLAIN, 20));
     g2.drawString("Score: " + score, 50, 50);
   }
 }
예제 #5
0
  public BlackHole() {

    Container window = getContentPane();
    window.setLayout(new BorderLayout());

    panel = new JPanel(null);

    label = new JLabel("Planet Health: " + healthStr, JLabel.CENTER);
    label.setBounds(0, 500, 1000, 50);

    panel.add(label);
    window.add(panel, BorderLayout.CENTER);

    addKeyListener(this);
    addMouseListener(this);
    setSize(1000, 600);
    setFocusable(true);
    setTitle("Black Hole");
    setVisible(true);

    player = new Player();
    player.xc = centerx;
    player.yc = centery;
    player.t = -Math.PI / 2;
    player.r = 950;
    player.convert();

    ball = new Ball[10];

    ballCount++;
    ball[1] = new Ball();
    ball[1].r = centery;
    ball[1].t = -Math.PI / 2;
    ball[1].xc = centerx;
    ball[1].yc = centery;

    timer = new Timer(20, this);
    timer.start();

    repaint();
  }
예제 #6
0
    @Override
    public void paintComponent(Graphics g) {
      super.paintComponent(g);
      Graphics2D g2 = (Graphics2D) g;

      // paint ball, paddle, and brick configuration
      g2.drawImage(background.getImage(), 0, 0, null);
      bconfig.paint(g2);
      paddle.paint(g2);
      ball.paint(g2);
      g2.setColor(Color.WHITE);
      g2.setFont(new Font("Serif", Font.PLAIN, 20));
      g2.drawString("Score: " + score, 15, 20);
      if (ball.getY() > 500) {
        g2.setColor(Color.WHITE);
        g2.setFont(new Font("Serif", Font.PLAIN, 30));
        g2.drawString("Game Over!", 200, 300);
        g2.drawString("Your final score was " + score, 150, 330);
        timer.stop();
      }
    }
예제 #7
0
파일: LJ3MDApp.java 프로젝트: eskilj/mvp
  public LJ3MDApp() {
    tNum.setHorizontalAlignment(JTextField.CENTER);
    tTemp.setHorizontalAlignment(JTextField.CENTER);
    tRho.setHorizontalAlignment(JTextField.CENTER);
    tSpeed.setHorizontalAlignment(JTextField.CENTER);

    tAvK.setHorizontalAlignment(JTextField.RIGHT);
    tAvU.setHorizontalAlignment(JTextField.RIGHT);
    tAvp.setHorizontalAlignment(JTextField.RIGHT);

    float[] aveKing = new float[501];
    float[] avePot = new float[501];
    float[] aveEn = new float[501];

    JFrame box = new JFrame();
    box.setLayout(new BorderLayout());
    box.setSize(1000, 1000);
    box.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    cpnl = new JPanel(); // create a panel for controls
    cpnl.setLayout(new GridLayout(18, 2));
    box.add(cpnl, BorderLayout.EAST);

    // add controls
    cpnl.add(bStart);
    bStart.addActionListener(this);

    cpnl.add(bReset);
    bReset.addActionListener(this);

    cpnl.add(new JLabel(" N:"));
    tNum.addActionListener(this);
    cpnl.add(tNum);

    cpnl.add(new JLabel(" Density (\u03c1):"));
    tRho.addActionListener(this);
    cpnl.add(tRho);

    cpnl.add(new JLabel(" Steps/frame:"));
    tSpeed.addActionListener(this);
    cpnl.add(tSpeed);

    cpnl.add(bTstat);
    bTstat.addActionListener(this);

    cpnl.add(bPot);
    bPot.addActionListener(this);

    cpnl.add(new JLabel(" < K/N > :"));
    tAvK.setEditable(false);
    cpnl.add(tAvK);

    cpnl.add(new JLabel(" Temperature:"));
    tTemp.setEditable(false);
    cpnl.add(tTemp);

    cpnl.add(new JLabel(" < U/N > :"));
    tAvU.setEditable(false);
    cpnl.add(tAvU);

    cpnl.add(new JLabel(" < pressure > :"));
    tAvp.setEditable(false);
    cpnl.add(tAvp);

    cpnl.add(bRetime);
    bRetime.addActionListener(this);

    spnl = new JPanel(); // create a panel for status
    box.add(spnl, BorderLayout.SOUTH);
    lStatus.setFont(new Font("Courier", 0, 12));
    spnl.add(lStatus);

    canvas = new XYZCanvas();
    box.add(canvas, BorderLayout.CENTER);

    timer = new Timer(delay, this);
    timer.start();
    //        timer.stop();
    box.setVisible(true);
  }
예제 #8
0
파일: LJ3MDApp.java 프로젝트: eskilj/mvp
  public void actionPerformed(ActionEvent e) {
    Object src = e.getSource();
    if (src == timer) {
      for (int i = 0; i < speed; i++) // integrate a few steps
      md.vv();
      repaint();
      return;
    }

    boolean adjCanvasScale = false;

    if (src == bTstat) md.thermostat = !md.thermostat;

    if (src == bPot) {
      md.ljPotential = !md.ljPotential;
      md.clearData();

      if (timer.isRunning()) timer.stop();
      bStart.setSelected(false);
      bStart.setText("Start");
      md.init(md.rho);
    }

    if (src == tTemp || src == bReset) {
      double kT = Double.parseDouble(tTemp.getText().trim());
      if (kT < 1e-8) {
        kT = 1e-8;
        tTemp.setText("  " + kT);
      }
      md.kT = kT;
      md.clearData();
    }

    if (src == tRho || src == bReset) {
      double rho = Double.parseDouble(tRho.getText().trim());
      if (rho < 1e-3) {
        rho = 1e-3;
        tRho.setText("   " + rho);
      }
      if (rho > 1.2) {
        rho = 1.2;
        tRho.setText("   " + rho);
      }
      md.setDensity(rho);
      md.clearData();
      adjCanvasScale = true;
    }

    if (src == tSpeed || src == bReset) {
      speed = Integer.parseInt(tSpeed.getText().trim());
      if (speed < 1) {
        speed = 1;
        tSpeed.setText("   " + speed);
      }
    }

    if (src == bRetime) md.clearData();

    if (src == bStart) {
      boolean on = bStart.isSelected();
      if (on) {
        timer.restart();
        bStart.setText("Pause");
      } else {
        timer.stop();
        bStart.setText("Resume");
      }
    }

    if (src == tNum) {
      int n = Integer.parseInt(tNum.getText().trim());
      if (n < 2) {
        n = 2;
        tNum.setText(" " + n);
      }
      md.N = n;
      md.init(md.rho);
      adjCanvasScale = true;
    }

    if (src == bReset) {
      if (timer.isRunning()) timer.stop();
      bStart.setSelected(false);
      bStart.setText("Start");
      md.init(md.rho);
    }

    canvas.refresh(md.getXWrap(), md.N, true, adjCanvasScale);

    repaint();
  }