java中用Graphics怎么画一个实心圆啊!高手帮我一下啊
1个回答
展开全部
import java.awt.*;
import javax.swing.*;
public class TankWar extends JFrame {
public TankWar (String title) {
super(title);
this.setSize(600,500);
this.setLocationRelativeTo(null); //设置窗口的位置屏幕中间
this.setResizable(false); //设置为不可改变大小
this.setDefaultCloseOperation(EXIT_ON_CLOSE); //设置关闭事件
MyJPanel myJPanel = new MyJPanel(); //创建一个MyJPanel实例对象myJPanel
myJPanel.setBackground(Color.blue);//设置myJPanel的背景颜色
this.add(myJPanel);
this.setVisible(true);
}
/*内部继承JPanel类*/
class MyJPanel extends JPanel {
protected void paintComponent(Graphics g) {
Color c = g.getColor();
g.setColor(Color.red);
g.fillOval(200, 100, 300, 300);
g.setColor(c);
}
}
public static void main(String args[]){
new TankWar ("坦克大战");
}
}
import javax.swing.*;
public class TankWar extends JFrame {
public TankWar (String title) {
super(title);
this.setSize(600,500);
this.setLocationRelativeTo(null); //设置窗口的位置屏幕中间
this.setResizable(false); //设置为不可改变大小
this.setDefaultCloseOperation(EXIT_ON_CLOSE); //设置关闭事件
MyJPanel myJPanel = new MyJPanel(); //创建一个MyJPanel实例对象myJPanel
myJPanel.setBackground(Color.blue);//设置myJPanel的背景颜色
this.add(myJPanel);
this.setVisible(true);
}
/*内部继承JPanel类*/
class MyJPanel extends JPanel {
protected void paintComponent(Graphics g) {
Color c = g.getColor();
g.setColor(Color.red);
g.fillOval(200, 100, 300, 300);
g.setColor(c);
}
}
public static void main(String args[]){
new TankWar ("坦克大战");
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询