Back to Applets page
Click in the boxes below, select all and copy to grab the applet
HTML listing:
<HTML> <HEAD> <TITLE>Listing 10.2</TITLE> </HEAD> <BODY BGCOLOR=WHITE> <APPLET CODEBASE="classes" CODE="Applet2.class" WIDTH=47 HEIGHT=65> </APPLET> </BODY> </HTML>
Applet listing:
import java.awt.*; import java.applet.*; import java.awt.image.*; public class Applet2 extends Applet { Image thisCard; public void init() { int randomCard,cardPos,cardWidth,cardHeight; Image playingCards; ImageFilter cardFilter; ImageProducer cardProducer; setBackground(Color.black); playingCards = getImage(getCodeBase(),"cards.gif"); randomCard = (int)(java.lang.Math.random() * 52); cardHeight = 61; cardWidth = 43; cardPos = (randomCard*cardWidth)+1; cardFilter = new CropImageFilter(cardPos,1,cardWidth,cardHeight); cardProducer = new FilteredImageSource(playingCards.getSource(),cardFilter); thisCard = createImage(cardProducer); } public void paint(Graphics g) { g.drawImage(thisCard,2,2,this); } }