大家帮我看看哪错了呀~椭圆和矩形画不出~颜色也填不进
import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;
import java.awt.Color.*;public class FillTest {/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
FillFrame fill = new FillFrame();
fill.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fill.setVisible(true);
}}
class FillFrame extends JFrame{
public static final int DEFAULT_WIDTH=400;
public static final int DEFAULT_HEIGHT=400;
public FillFrame(){
setTitle("朱雪珂的世界");
setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
FillPanel f = new FillPanel();
add(f);
}
}
class FillPanel extends JPanel{
public void paintComonent(Graphics g){
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;double leftX = 100;
double topY = 100;
double width = 200;
double height = 150;Rectangle2D rect = new Rectangle2D.Double(leftX,topY,width,height);
g2.setPaint(Color.RED);//为 Graphics2D 上下文设置 Paint 属性
g2.fill(rect);//使用 Graphics2D 上下文的设置,填充 Shape 的内部区域Ellipse2D ellipse = new Ellipse2D.Double();
ellipse.setFrame(rect);
g2.setPaint(Color.BLACK);
g2.fill(ellipse);
}
}