关于java中 Swing 里的paintComponents(Graphics g)方法的问题!
代码是这样滴:packagetankWarV0_2;importjava.awt.*;importjavax.swing.*;publicclassTankCliente...
代码是这样滴:
package tankWarV0_2;
import java.awt.*;
import javax.swing.*;
public class TankClient extends JFrame{
public static void main(String[] args) {
TankClient tank = new TankClient();
tank.lanchFrame();
}
//=========================================================================================
public void lanchFrame(){
this.setTitle("TankWar");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocation(400, 300);
this.setSize(800, 600);
this.setResizable(false);
JPanel pane = new JPanel();
this.setContentPane(pane);
pane.setBackground(Color.green);
this.setVisible(true);
}
//=========================================================================================
public void paintComponents(Graphics g){
super.paintComponents(g);
Color c = g.getColor();
g.setColor(Color.red);
g.fillRect(40, 40, 25, 25);
g.setColor(c);
}
}
但运行以后本应该出现的矩形没有了,求教应该如何修改TAT 展开
package tankWarV0_2;
import java.awt.*;
import javax.swing.*;
public class TankClient extends JFrame{
public static void main(String[] args) {
TankClient tank = new TankClient();
tank.lanchFrame();
}
//=========================================================================================
public void lanchFrame(){
this.setTitle("TankWar");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocation(400, 300);
this.setSize(800, 600);
this.setResizable(false);
JPanel pane = new JPanel();
this.setContentPane(pane);
pane.setBackground(Color.green);
this.setVisible(true);
}
//=========================================================================================
public void paintComponents(Graphics g){
super.paintComponents(g);
Color c = g.getColor();
g.setColor(Color.red);
g.fillRect(40, 40, 25, 25);
g.setColor(c);
}
}
但运行以后本应该出现的矩形没有了,求教应该如何修改TAT 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询