BlackjackGUI - /* In this applet, the user plays a game of...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
/* In this applet, the user plays a game of Blackjack. The computer acts as the dealer. The user plays by clicking "Hit!" and "Stand!" buttons. The programming of this applet assumes that the applet is set up to be about 466 pixels wide and about 346 pixels high. That width is just big enough to show 2 rows of 5 cards. The height is probably a little bigger than necessary, to allow for variations in the size of buttons from one platform to another. This file defines two classes, the applet class BlackJackGUI and a class BlackJackCanvas which is used in the applet. (This is slightly bad style, but is OK since the BlackJackCanvas class is not public and is not used outside this file.) */ * import java.awt.*; import java.awt.event.*; import java.applet.*; i public class BlackjackGUI extends Applet { p public void init() { // The init() method lays out the applet using a BorderLayout. // A BlackJackCanvas occupies the CENTER position of the layout. // On the bottom is a panel that holds three buttons. The // HighLowCanvas object listens for ActionEvents from the buttons // and does all the real work of the program. setBackground( new Color(130,50,40) ); setLayout( new BorderLayout(3,3) ); BlackjackCanvas board = new BlackjackCanvas(); add(board, BorderLayout.CENTER); Panel buttonPanel = new Panel(); buttonPanel.setBackground( new Color(220,200,180) ); add(buttonPanel, BorderLayout.SOUTH); Button higher = new Button( "Hit!" ); higher.addActionListener(board); higher.setBackground(Color.lightGray); buttonPanel.add(higher); Button lower = new Button( "Stand!" ); lower.addActionListener(board); lower.setBackground(Color.lightGray); buttonPanel.add(lower); Button newGame = new Button( "New Game" ); newGame.addActionListener(board); newGame.setBackground(Color.lightGray); buttonPanel.add(newGame); } // end init()
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
public Insets getInsets() { // Specify how much space to leave between the edges of // the applet and the components it contains. The background // color shows through in this border. return new Insets(3,3,3,3);
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

BlackjackGUI - /* In this applet, the user plays a game of...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online