示例#1
0
  /**
   * This method creates the content pane that will be a part of the frame, including the JLabels,
   * JPanels and the JButtons INPUT (parameters): none OUTOUT (return): the main JPanel object that
   * includes everything
   */
  public JPanel createContentPane() {

    JPanel totalGUI = new JPanel(); // the main panel
    totalGUI.setBackground(Color.BLACK);
    totalGUI.setLayout(null);

    printInstructions();
    startNum = In.getInt();
    if (startNum == 1) startGame = true;
    else startGame = false;
    while (!startGame) {
      System.out.println("Please enter 1 to start the game");
      startNum = In.getInt();
      if (startNum == 1) startGame = true;
      else startGame = false;
    }
    if (startGame) {
      titlePanel = new JPanel(); // a panel where the title will be displayed
      titlePanel.setLayout(null);
      titlePanel.setLocation(0, 0);
      titlePanel.setSize(1600, 150);
      Color titlePanelColor = new Color(238, 130, 238);
      titlePanel.setBackground(titlePanelColor);
      totalGUI.add(titlePanel); // this panel is added to the main panel

      gamePanel = new JPanel(); // game panel (where the cards will be displayed)
      gamePanel.setLayout(null);
      gamePanel.setLocation(0, 150);
      gamePanel.setSize(950, 650);
      gamePanel.setBackground(Color.BLACK);
      totalGUI.add(gamePanel);

      newGameButton = new JButton("Start"); // a button to start the game
      newGameButton.setLocation(800, 155);
      newGameButton.setSize(120, 30);
      newGameButton.addActionListener(this);
      gamePanel.add(newGameButton); // this button is added to the game panel

      endGameButton = new JButton("End Game"); // a button to end the game
      endGameButton.setLocation(800, 195);
      endGameButton.setSize(120, 30);
      endGameButton.addActionListener(this);
      gamePanel.add(endGameButton);

      hitButton = new JButton("Hit! (Player)"); // a hit button for the player
      hitButton.setLocation(800, 235);
      hitButton.setSize(120, 30);
      hitButton.addActionListener(this);
      gamePanel.add(hitButton);

      hitButton2 = new JButton("Hit! (Dealer)"); // a hit button for the dealer
      hitButton2.setLocation(800, 275);
      hitButton2.setSize(120, 30);
      hitButton2.addActionListener(this);
      gamePanel.add(hitButton2);

      standButton = new JButton("Stand (Player)"); // a stand button for the player
      standButton.setLocation(800, 315);
      standButton.setSize(120, 30);
      standButton.addActionListener(this);
      gamePanel.add(standButton);

      standButton2 = new JButton("Stand (Dealer)"); // a stand button for the dealer
      standButton2.setLocation(800, 355);
      standButton2.setSize(120, 30);
      standButton2.addActionListener(this);
      gamePanel.add(standButton2);

      playerTitle =
          new JLabel(
              "Player"); // label that displays the word "Player" on the screen
      playerTitle.setFont(new Font("Comic Sans MS", Font.BOLD, 20));
      Color playerTitleColor = new Color(0, 250, 154);
      playerTitle.setForeground(playerTitleColor);
      playerTitle.setLocation(550, 150);
      playerTitle.setSize(100, 30);
      gamePanel.add(playerTitle);

      dealerTitle = new JLabel("Dealer"); // label that displays the word "Dealer" on the screen
      dealerTitle.setFont(new Font("Comic Sans MS", Font.BOLD, 20));
      Color dealerTitleColor = new Color(0, 250, 154);
      dealerTitle.setForeground(dealerTitleColor);
      dealerTitle.setLocation(550, 350);
      dealerTitle.setSize(100, 30);
      gamePanel.add(dealerTitle);

      scoreLabel = new JLabel(""); // label that displays the score
      scoreLabel.setFont(new Font("Comic Sans MS", Font.BOLD, 30));
      Color scoreLabelColor = new Color(255, 20, 147);
      scoreLabel.setForeground(scoreLabelColor);
      scoreLabel.setLocation(200, 130);
      scoreLabel.setSize(400, 300);
      gamePanel.add(scoreLabel);

      turnLabel = new JLabel(""); // label that informs the users whose turn it is
      turnLabel.setFont(new Font("Comic Sans MS", Font.BOLD, 20));
      Color turnLabelColor = new Color(255, 127, 80);
      turnLabel.setForeground(turnLabelColor);
      turnLabel.setLocation(250, 200);
      turnLabel.setSize(300, 100);
      gamePanel.add(turnLabel);

      score1 = new JLabel("");
      score1.setFont(new Font("Comic Sans MS", Font.BOLD, 20));
      Color score1Color = new Color(255, 127, 80);
      score1.setForeground(score1Color);
      score1.setLocation(660, 135);
      score1.setSize(100, 60);
      gamePanel.add(score1);

      score2 = new JLabel("");
      score2.setFont(new Font("Comic Sans MS", Font.BOLD, 20));
      Color score2Color = new Color(255, 127, 80);
      score2.setForeground(score2Color);
      score2.setLocation(660, 335);
      score2.setSize(100, 60);
      gamePanel.add(score2);

      ImageIcon titleIcon1 = new ImageIcon("BlackJack.jpg");
      titlePics = new JLabel(titleIcon1); // an image for decor
      titlePics.setLocation(0, 0);
      titlePics.setSize(150, 150);
      titlePanel.add(titlePics); // image added to title label

      welcomeLabel = new JLabel("Welcome To Casino Royale!");
      welcomeLabel.setFont(new Font("Monotype Corsiva", Font.BOLD, 40));
      Color titleColor = new Color(0, 255, 255); // title
      welcomeLabel.setForeground(titleColor);
      welcomeLabel.setLocation(245, 0);
      welcomeLabel.setSize(700, 100);
      titlePanel.add(welcomeLabel);

      commandLabel = new JLabel("Please press \"Start\" to start a game of Black Jack!");
      commandLabel.setFont(new Font("Comic Sans MS", Font.BOLD, 16));
      Color commandColor = new Color(0, 0, 0);
      commandLabel.setForeground(commandColor); // instruction to user on how to start the game
      commandLabel.setLocation(250, 101);
      commandLabel.setSize(700, 44);
      titlePanel.add(commandLabel);

      ImageIcon titleIcon3 = new ImageIcon("Swirl.jpg");
      titlePics = new JLabel(titleIcon3); // an image for decor
      titlePics.setLocation(783, 0);
      titlePics.setSize(150, 150);
      titlePanel.add(titlePics);

      totalGUI.setOpaque(true);
      return totalGUI; // return the final JPanel
    }
    return totalGUI;
  }
示例#2
0
  public Senso() {
    super("Senso");
    this.setSize(640, 480);
    this.setLocation(100, 100);
    this.getContentPane().setBackground(Color.black);
    this.setUndecorated(true);
    this.setBackground(Color.white);
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.setResizable(false);
    this.setLayout(null);
    this.setAlwaysOnTop(true);

    klicks = new JLabel();
    klicks.setSize(150, 25);
    klicks.setLocation(20, 300);
    klicks.setFont(new Font("Impact", 5, 25));
    klicks.setForeground(Color.lightGray);
    this.add(klicks);

    start = new JLabel();
    start.setSize(350, 50);
    start.setLocation(350, 200);
    start.setFont(new Font("Impact", 5, 50));
    start.setForeground(Color.lightGray);
    this.add(start);

    lblVerloren = new JLabel();
    lblVerloren.setSize(350, 30);
    lblVerloren.setLocation(200, 215);
    lblVerloren.setFont(new Font("Impact", 5, 30));
    lblVerloren.setForeground(Color.lightGray);
    this.add(lblVerloren);

    neustart = new JLabel("Neustart");
    neustart.setSize(100, 30);
    neustart.setLocation(20, 200);
    neustart.setFont(new Font("Impact", 5, 25));
    neustart.setForeground(Color.darkGray);
    neustart.addMouseListener(this);
    this.add(neustart);

    beenden = new JLabel("Beenden");
    beenden.setSize(100, 30);
    beenden.setLocation(20, 390);
    beenden.setFont(new Font("Impact", 5, 25));
    beenden.setForeground(Color.gray);
    beenden.addMouseListener(this);
    this.add(beenden);

    us = new JLabel("Senso");
    us.setSize(150, 35);
    us.setLocation(10, 30);
    us.setFont(new Font("Impact", 1, 35));
    us.setForeground(Color.white);
    this.add(us);

    punkte = new JLabel("Score: " + String.valueOf(points));
    punkte.setSize(200, 20);
    punkte.setLocation(400, 400);
    punkte.setFont(new Font("Impact", 0, 20));
    punkte.setForeground(Color.white);
    this.add(punkte);

    rot = new JLabel(new ImageIcon("files/Minigames/Senso/red_0.png"));
    rot.setSize(216, 207);
    rot.setLocation(150, 25);
    rot.setBackground(Color.darkGray);
    rot.addMouseListener(this);
    this.add(rot);

    gruen = new JLabel(new ImageIcon("files/Minigames/Senso/green_0.png"));
    gruen.setSize(216, 207);
    gruen.setLocation(366, 25);
    gruen.setBackground(Color.darkGray);
    gruen.addMouseListener(this);
    this.add(gruen);

    gelb = new JLabel(new ImageIcon("files/Minigames/Senso/yellow_0.png"));
    gelb.setSize(216, 207);
    gelb.setLocation(366, 232);
    gelb.setBackground(Color.darkGray);
    gelb.addMouseListener(this);
    this.add(gelb);

    blau = new JLabel(new ImageIcon("files/Minigames/Senso/blue_0.png"));
    blau.setSize(216, 207);
    blau.setLocation(150, 232);
    blau.setBackground(Color.darkGray);
    blau.addMouseListener(this);
    this.add(blau);

    this.addMouseListener(this);

    // spiel = new Thread(this);
    zufall = new Random();

    läuft = false;

    zahl = zufall.nextInt(4);
    // this.setVisible(true);
    soundR = new File("files/Minigames/Senso/rot.wav");
    soundG = new File("files/Minigames/Senso/gruen.wav");
    soundB = new File("files/Minigames/Senso/blau.wav");
    soundY = new File("files/Minigames/Senso/gelb.wav");
    soundF = new File("files/Minigames/Senso/falsch.wav");
  }
示例#3
0
 /**
  * This method displays a card on the screen for the dealer INPUT (parameters): int location (for
  * the location of the image) int String suits (for the card) OUTOUT (return): returns a Jlabel
  * (an image of the card)
  */
 public JLabel cards1(int location, String suits) {
   int xValue = (80 * location) + 5;
   if (suits == "spades1") {
     ImageIcon Image = new ImageIcon("Ace.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "hearts1") {
     ImageIcon Image = new ImageIcon("Aceh.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "clubs1") {
     ImageIcon Image = new ImageIcon("Acec.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "diamonds1") {
     ImageIcon Image = new ImageIcon("Aced.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "spades2") {
     ImageIcon Image = new ImageIcon("two.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "hearts2") {
     ImageIcon Image = new ImageIcon("twoh.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "clubs2") {
     ImageIcon Image = new ImageIcon("twoc.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "diamonds2") {
     ImageIcon Image = new ImageIcon("twod.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "spades3") {
     ImageIcon Image = new ImageIcon("three.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "hearts3") {
     ImageIcon Image = new ImageIcon("threeh.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "clubs3") {
     ImageIcon Image = new ImageIcon("threec.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "diamonds3") {
     ImageIcon Image = new ImageIcon("threed.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "spades4") {
     ImageIcon Image = new ImageIcon("four.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "hearts4") {
     ImageIcon Image = new ImageIcon("fourh.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "clubs4") {
     ImageIcon Image = new ImageIcon("fourc.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "diamonds4") {
     ImageIcon Image = new ImageIcon("fourd.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "spades5") {
     ImageIcon Image = new ImageIcon("five.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "hearts5") {
     ImageIcon Image = new ImageIcon("fiveh.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "clubs5") {
     ImageIcon Image = new ImageIcon("fivec.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "diamonds5") {
     ImageIcon Image = new ImageIcon("fived.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "spades6") {
     ImageIcon Image = new ImageIcon("six.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "hearts6") {
     ImageIcon Image = new ImageIcon("sixh.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "clubs6") {
     ImageIcon Image = new ImageIcon("sixc.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "diamonds6") {
     ImageIcon Image = new ImageIcon("sixd.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "spades7") {
     ImageIcon Image = new ImageIcon("seven.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "hearts7") {
     ImageIcon Image = new ImageIcon("sevenh.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "clubs7") {
     ImageIcon Image = new ImageIcon("sevenc.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "diamonds7") {
     ImageIcon Image = new ImageIcon("sevend.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "spades8") {
     ImageIcon Image = new ImageIcon("eight.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "hearts8") {
     ImageIcon Image = new ImageIcon("eighth.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "clubs8") {
     ImageIcon Image = new ImageIcon("eightc.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "diamonds8") {
     ImageIcon Image = new ImageIcon("eightd.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "spades9") {
     ImageIcon Image = new ImageIcon("nine.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "hearts9") {
     ImageIcon Image = new ImageIcon("nineh.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "clubs9") {
     ImageIcon Image = new ImageIcon("ninec.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "diamonds9") {
     ImageIcon Image = new ImageIcon("nined.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "spades10") {
     ImageIcon Image = new ImageIcon("ten.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "hearts10") {
     ImageIcon Image = new ImageIcon("tenh.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "clubs10") {
     ImageIcon Image = new ImageIcon("tenc.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "diamonds10") {
     ImageIcon Image = new ImageIcon("tend.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "spades11") {
     ImageIcon Image = new ImageIcon("jack.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "hearts11") {
     ImageIcon Image = new ImageIcon("jackh.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "clubs11") {
     ImageIcon Image = new ImageIcon("jackc.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "diamonds11") {
     ImageIcon Image = new ImageIcon("jackd.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   }
   if (suits == "spades12") {
     ImageIcon Image = new ImageIcon("queen.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "hearts12") {
     ImageIcon Image = new ImageIcon("queenh.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "clubs12") {
     ImageIcon Image = new ImageIcon("queenc.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "diamonds12") {
     ImageIcon Image = new ImageIcon("queend.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "spades13") {
     ImageIcon Image = new ImageIcon("king.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "hearts13") {
     ImageIcon Image = new ImageIcon("kingh.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "clubs13") {
     ImageIcon Image = new ImageIcon("kingc.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   } else if (suits == "diamonds13") {
     ImageIcon Image = new ImageIcon("kingd.jpg");
     JLabel player1Card = new JLabel(Image);
     player1Card.setLocation(xValue, 400);
     player1Card.setSize(100, 150);
     return player1Card;
   }
   return player1Card;
 }