import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;public class FillTest
{
public static void main(String[] args)
{
FillFrame frame = new FillFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}class FillFrame extends JFrame
{
public FillFrame()
{
setTitle("FillTest");
setSize(400,400);
FillPanel panel = new FillPanel();
Container contentPane = getContentPane();
contentPane.add(panel);
}}class FillPanel extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g; Rectangle2D rect = new Rectangle2D.Double(100,100,200,150); g2.setPaint(Color.red);
g2.fill(rect);
}
}
看不出我的程序跟你的有什么差别,但在我机上运行我的行,而我考你的运行则不行。
g2.setPaint(Color.RED);red我的自动提示是小写,但把你的改成小写还是不行。
你拷我的运行一下试试,看能不能找到问题所在。
import java.awt.geom.*;
import javax.swing.*;public class FillTest
{
public static void main(String[] args)
{
FillFrame frame = new FillFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}class FillFrame extends JFrame
{
public FillFrame()
{
setTitle("FillTest");
setSize(400,400);
FillPanel panel = new FillPanel();
Container contentPane = getContentPane();
contentPane.add(panel);
}}class FillPanel extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g; Rectangle2D rect = new Rectangle2D.Double(100,100,200,150); g2.setPaint(Color.red);
g2.fill(rect);
}
}
看不出我的程序跟你的有什么差别,但在我机上运行我的行,而我考你的运行则不行。
g2.setPaint(Color.RED);red我的自动提示是小写,但把你的改成小写还是不行。
你拷我的运行一下试试,看能不能找到问题所在。
^
楼主程序中多了个t,变成了一个新的方法,没有覆写
看仔细一点