Back to Applets page
Click in the boxes below, select all and copy to grab the applet
HTML listing:
<HTML> <HEAD> <TITLE>Listing 10.3</TITLE> </HEAD> <BODY BGCOLOR=WHITE> <APPLET CODEBASE="classes" CODE="Applet3.class" WIDTH=300 HEIGHT=100> </APPLET> </BODY> </HTML>
Applet listing:
import java.awt.*; import java.applet.*; import java.awt.image.*; public class Applet3 extends Applet { Image thisCard; int cardWidth=43,cardHeight=61; public void init() { int randomCard,cardPos; Image playingCards; ImageFilter cardFilter; ImageProducer cardProducer; setBackground(Color.white); playingCards = getImage(getCodeBase(),"cards.gif"); randomCard = (int)(java.lang.Math.random() * 52); 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,3,3,this); g.drawRoundRect(1,1,cardWidth+2,cardHeight+2,5,5); } }