Back to Applets page
Click in the boxes below, select all and copy to grab the applet
HTML listing:
<HTML> <HEAD> <TITLE>Listing 5.6</TITLE> </HEAD> <BODY BGCOLOR=WHITE> <APPLET CODEBASE="classes" CODE="Applet6.class" WIDTH=500 HEIGHT=500> </APPLET> </BODY> </HTML>
Applet listing:
/* This applet demonstrates how to convert numbers to strings and back again */ import java.awt.*; import java.applet.Applet; public class Applet6 extends Applet{ Integer myInt = new Integer(Integer.MAX_VALUE); String myString; 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 maximum value of an integer is: "+this.myInt, 10 , 40); g.drawString("And it can be displayed as a string like this: ", 10, 60); this.myString = this.myInt.toString(); g.drawString(this.myString, 10, 80); g.drawString("And converted back like this: "+Integer.valueOf(this.myString), 10, 100); } }