protected void createAndShowGUI() {
   GamePanel gamePanel = new GamePanel();
   gamePanel.setBackground(Color.WHITE);
   gamePanel.setPreferredSize(new Dimension(320, 240));
   getContentPane().add(gamePanel);
   setDefaultCloseOperation(EXIT_ON_CLOSE);
   setTitle("Hello World!");
   pack();
   frameRate.initialize();
   setVisible(true);
 }
  public GameFrame(int height, int width) {
    super("--- Tempo Game ---");

    this.height = height;
    this.width = width;

    card = new CardLayout();

    mainPanel = new JPanel();

    mainPanel.setLayout(card);

    memory[0] = new Memory();

    menuPanel = new MenuPanel(memory[count]);
    secondPanel = new SecondPanel(memory[count]);
    gamePanel = new GamePanel(memory[count]);
    rankPanel = new RankPanel(memory, count);

    mainPanel.add(menuPanel, "one");
    mainPanel.add(secondPanel, "two");
    mainPanel.add(gamePanel, "three");
    mainPanel.add(rankPanel, "four");

    buttonPanel = new JPanel();

    ctl = new JButton("- Play -");
    ctl.addActionListener(this);

    exit = new JButton("- Exit -");
    exit.addActionListener(this);

    rank = new JButton("- Rank -");
    rank.addActionListener(this);

    back = new JButton("- Back -");
    back.addActionListener(this);

    buttonPanel.add(ctl);
    buttonPanel.add(rank);
    buttonPanel.add(exit);
    buttonPanel.setOpaque(false);
    buttonPanel.setBounds(width / 2 - 50, height / 2 - 50, 80, 100);

    gamePanel.setFocusable(true);
    gamePanel.addKeyListener(this);

    add(buttonPanel);
    add(mainPanel);

    System.out.println(count);
  }
  private void gotoStoppedPanel() {
    if (GamePanel.isMoving) {
      GamePanel.isMoving = false;
      GamePanel.totalmiles += GamePanel.miles;
      GamePanel.overWorldVisible = false;
      GamePanel.stoppedVisible = true;

      Stopped st = new Stopped(gp);
      gp.add(st);
    }
    gp.revalidate();
    gp.repaint();
  }
 public void changePanel() {
   card.next(mainPanel);
   buttonPanel.removeAll();
   ctl.setText("- Play -");
   buttonPanel.add(ctl);
   buttonPanel.add(rank);
   buttonPanel.add(exit);
   buttonPanel.setOpaque(false);
   buttonPanel.setBounds(width / 2 - 50, height / 2 - 50, 80, 100);
   count++;
   memory[count] = new Memory();
   menuPanel.setMemory(memory[count]);
   secondPanel.setMemory(memory[count]);
   gamePanel.setMemory(memory[count]);
   rankPanel.setMemory(memory, count);
   check = 0;
   System.out.println(
       count
           + " "
           + memory[count - 1].name
           + " "
           + memory[count - 1].song
           + " "
           + memory[count - 1].score);
 }
Example #5
0
  public void paint(Graphics g) {
    // set the background color to white.
    this.setBackground(new Color(0xFFFFFF));

    // clear the panel with the background color.
    super.paint(g);

    // cast our Graphics as a Graphics2D, since it has more features and g is actually a Graphics2D
    // anyways.
    Graphics2D g2D = (Graphics2D) g;

    // render the blittered Strings.
    monoSprite.render(g2D);
    fittedSprite.render(g2D);
    dimsSprite.render(g2D);

    // Draw borders around the text sprites to demonstrate that they
    // are obeying their line-wrapping.
    Dimension monoDim = monoSprite.getDimensions();
    Dimension fittedDim = fittedSprite.getDimensions();

    g2D.drawRect((int) monoSprite.x, (int) monoSprite.y, monoSprite.maxWidth, monoDim.height);
    g2D.drawRect(
        (int) fittedSprite.x, (int) fittedSprite.y, fittedSprite.maxWidth, fittedDim.height);

    // Set our drawing color to black
    g2D.setColor(new Color(0x000000));

    // display the current frame rate.
    g2D.drawString("" + timer.fpsCounter, 400, 32);
  }
  public void menu() {
    if (check == 0) {
      buttonPanel.removeAll();
      buttonPanel.setBounds(width - 200, height - 80, 200, 50);
      card.next(mainPanel);
      ctl.setText("- Play -");
      buttonPanel.add(back);
      buttonPanel.add(ctl);
      menuPanel.savename();
      check = 1;
      secondPanel.musiclist.clearSelection();
      gamePanel.setSecond(0);
    } else if (check == 1) {
      if (memory[count].getSong() == null) {
        Container con = getContentPane();

        String title = "--Warning--";
        String message = "Please Choice a Music Before Playing!";
        int type = JOptionPane.WARNING_MESSAGE;

        JOptionPane.showMessageDialog(con, message, title, type);
      } else {
        card.next(mainPanel);
        secondPanel.clip.stop();
        buttonPanel.removeAll();
        buttonPanel.setBounds(width - 200, height - 80, 190, 50);
        ctl.setText("- Stop -");
        buttonPanel.add(ctl);
        buttonPanel.add(exit);
        check = 2;
        gamePanel.playmusic();
        gamePanel.setRun(true);
      }
    } else if (check == 2) {
      ctl.setText("- Resume -");
      gamePanel.clip.stop();
      gamePanel.setRun(false);
      check = 3;
    } else if (check == 3) {
      ctl.setText("- Stop -");
      gamePanel.clip.start();
      gamePanel.setRun(true);
      check = 2;
    }
  }
Example #7
0
  public Player(Registerable parent, GamePanel panel) {
    super(parent);
    Body body =
        new RectangularBody(
            this, new Vector(0f, 0f), new Vector(0f, 0f), new Rectangle2D.Double(0, 0, 30, 30));
    body.setColor(Color.BLUE);
    addComponent(body);
    Controller controller = new Controller(this, panel);
    addComponent(controller);

    panel.addMouseListener(controller);
  }
 public void exitPerform() {
   if (check == 4) {
     this.changePanel();
   } else if (check == 0) {
     this.dispose();
   } else {
     card.next(mainPanel);
     rankPanel.updateUI();
     buttonPanel.removeAll();
     buttonPanel.add(exit);
     gamePanel.clip.stop();
     gamePanel.setRun(false);
     check = 4;
   }
 }
 public void keyReleased(KeyEvent e) {
   switch (e.getKeyCode()) {
     case KeyEvent.VK_LEFT:
       System.out.println("left");
       gamePanel.keyctl(5);
       break;
     case KeyEvent.VK_DOWN:
       System.out.println("down");
       gamePanel.keyctl(6);
       break;
     case KeyEvent.VK_UP:
       System.out.println("UP");
       gamePanel.keyctl(7);
       break;
     case KeyEvent.VK_RIGHT:
       System.out.println("right");
       gamePanel.keyctl(8);
       break;
     case KeyEvent.VK_A:
       System.out.println("left");
       gamePanel.keyctl(5);
       break;
     case KeyEvent.VK_S:
       System.out.println("down");
       gamePanel.keyctl(6);
       break;
     case KeyEvent.VK_W:
       System.out.println("UP");
       gamePanel.keyctl(7);
       break;
     case KeyEvent.VK_D:
       System.out.println("right");
       gamePanel.keyctl(8);
       break;
   }
 }