Back to Applets page
Click in the boxes below, select all and copy to grab the applet
HTML listing:
<HTML> <HEAD> <TITLE>Listing 5.8</TITLE> </HEAD> <BODY BGCOLOR=WHITE> <APPLET CODEBASE="classes" CODE="Applet8.class" WIDTH=500 HEIGHT=500> </APPLET> </BODY> </HTML>
Applet listing:
/* Simple applet to demonstrate casting */ import java.awt.*; import java.applet.Applet; public class Applet8 extends Applet{ double myDouble = Math.PI; Font f = new Font("TimesRoman",Font.BOLD,16); public void init() { setBackground(Color.white); } public void paint(Graphics g) { g.setFont(f); g.drawString("The value of pi as a byte is: "+(byte)this.myDouble, 10 , 20); g.drawString("The value of pi as a short is: "+(short)this.myDouble, 10 , 40); g.drawString("The value of pi as an integer is: "+(int)this.myDouble, 10 , 60); g.drawString("The value of pi as a long is: "+(long)this.myDouble, 10 , 80); g.drawString("The value of pi as a float is: "+(float)this.myDouble, 10 , 100); g.drawString("The value of pi as a double is: "+this.myDouble, 10 , 120); } }