public class SinTh extends Frame {
/**
 * 
 */
private static final long serialVersionUID = 1L;
int x, y;
SinTh() {
super("欢迎窗口");
setSize(400, 200);
super.setBackground(Color.pink);
setVisible(true);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}

public void paint(Graphics g) {
g.drawString("信息一", x, 100); //X的值为什么可以不用初始化?????默认值又是多少呢???
g.drawString("信息二", y, 120); //Y的值为什么可以不用初始化?????默认值又是多少呢??? }
分比较少,谢谢解答

解决方案 »

  1.   

    x,y 是实例变量且是数值类型,不需要显式初始化,默认值为0,如果是对象类型默认值为null。
      

  2.   

    x,y 初始值是0。假设你认为是负值是因为看到了文字被遮挡了,出现这种现象的原因是:x,y都是相对Frame的左上坐标的值,Frame的border占据了一定的空间,挡住了文字。