请问为什么paint执行两次 20
继承了Frame类重写了paint()方法,执行结果为什么会打印两行“???”importjava.awt.Color;importjava.awt.Frame;impo...
继承了Frame类重写了paint()方法,执行结果为什么会打印两行“???”
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class TestPaint extends Frame {
public void paint(Graphics g) {
g.setColor(Color.red);
g.fillOval(30, 30, 20, 20);
System.out.println("?????????????????");
}
public static void main(String[] args) {
new TestPaint().launch();
}
public void launch(){
this.setBounds(5, 5, 150, 160);
this.setVisible(true);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
经过我自己测试setBounds()大小设成(5,5,150,150)就只会打印一次“???”
实在不懂什么原理 展开
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class TestPaint extends Frame {
public void paint(Graphics g) {
g.setColor(Color.red);
g.fillOval(30, 30, 20, 20);
System.out.println("?????????????????");
}
public static void main(String[] args) {
new TestPaint().launch();
}
public void launch(){
this.setBounds(5, 5, 150, 160);
this.setVisible(true);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
经过我自己测试setBounds()大小设成(5,5,150,150)就只会打印一次“???”
实在不懂什么原理 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询