All pastes #84634 Raw Edit

goldphish

public java v1 · immutable
·published 2006-07-11 04:23 UTC
rendered paste body
import java.applet.*;import java.awt.*;import java.awt.event.*;public class CardApplet extends Applet implements ActionListener {	private Button sortButton, shuffleButton, showButton;	private Deck deck;	private boolean faceUp = true;		public void init() {		Deck deck = new Deck(this);		// pass the Deck class a reference to this applet.				// Instantiate the buttons		sortButton = new Button("Sort");		sortButton.addActionListener(this);		shuffleButton = new Button("Shuffle");		shuffleButton.addActionListener(this);		showButton = new Button("Hide Deck");		showButton.addActionListener(this);				// Create the GUI		add(sortButton);		add(shuffleButton);		add(showButton);	}		public Image cardImage(String s) {		if (s == "back")			return getImage(getDocumentBase(), "back.gif");		else			return getImage(getDocumentBase(), s + ".gif");	}		public void paint(Graphics g) {		Card tmpCard = deck.dealOneCard(faceUp);		for (int i = 1; i < Deck.NCARDS; i++)			g.drawString(tmpCard.toString(), (20 * i),(20 * i));	}		public void actionPerformed(ActionEvent e) {		if (e.getSource() == sortButton)			// no idea what to do here.			deck.sortDeck(this.deck);		else if (e.getSource() == shuffleButton)			deck.shuffleDeck();		else {			if (faceUp) {				showButton.setLabel("Show Deck");				faceUp = false;			}			else {				showButton.setLabel("Hide Deck");				faceUp = true;			}		}	}}