日期:2014-05-20 浏览次数:21065 次
import java.awt.Graphics;
import java.applet.Applet;
public class FriendlyDataTest extends Applet {
private FriendlyData d;
public void init(){
d = new FriendlyData();
}
public void paint(Graphics g){
g.drawString("After instantiation: ",25,25);
g.drawString(d.toString(), 40, 40);
d.x = 77;
d.s = new String("Good bye");
g.drawString("After changing values: ", 25, 55);
g.drawString(d.toString(), 40, 70);
}
}
class FriendlyData{
int x;
String s;
public FriendlyData(){
x = 0;
s = new String("Hello");
}
public String toString(){
return "x: "+x+" s: "+s;
}
}