Java 我建的一个paint方法在main方法里没调用,为什么还会执行它?
importjava.awt.Color;importjava.awt.Graphics;importjavax.swing.JFrame;publicclassmain...
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
public class mainTank extends JFrame {
private static final int TANK_WIDTH = 40;
private static final int TANK_HEIGHT= 40;
public static void main(String[] args) {
mainTank mk = new mainTank();
mk.drawwindow();
}
public void drawwindow(){
this.setSize(800,600);
this.setLocation(240,100);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
/**
* 为什么paint方法在main方法里不调用,也会执行?
*/
public void paint(Graphics graphics){
Color c = graphics.getColor();
graphics.setColor(Color.black);
graphics.fillOval(390, 100, TANK_WIDTH, TANK_HEIGHT);
graphics.setColor(c);
}
} 展开
import java.awt.Graphics;
import javax.swing.JFrame;
public class mainTank extends JFrame {
private static final int TANK_WIDTH = 40;
private static final int TANK_HEIGHT= 40;
public static void main(String[] args) {
mainTank mk = new mainTank();
mk.drawwindow();
}
public void drawwindow(){
this.setSize(800,600);
this.setLocation(240,100);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
/**
* 为什么paint方法在main方法里不调用,也会执行?
*/
public void paint(Graphics graphics){
Color c = graphics.getColor();
graphics.setColor(Color.black);
graphics.fillOval(390, 100, TANK_WIDTH, TANK_HEIGHT);
graphics.setColor(c);
}
} 展开
2个回答
2015-10-19
展开全部
paint 是可视组件的一个事件,就是在需要刷新的时候,JAVA自动调用的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询