package java01;import java.awt.*;import java.awt.geom.*;import javax.swing.*;public class java4{public void paintComponent(Graphics g){super.painComponent(g);Graphics2D g2 = (Graphics2D) g;float width = getSize().width-10;float Height= getsize().height/3-10;g2.setPaint(Color.red);g2.draw(new Line2D.Float(5,5,5+Width,5+Height));g2.draw(new Line2D.Float(5,5+Height,5+Width,5));g2.setPaint(new Color(192,128,64));g2.fill(new Rectangle2D.Float(5,10+Height,Width,Height));g2.fill(new Gradientpaint(5,5,Color.blue,5+Width,5,Color.yellow));g2.fill(new Ellipse2D.Float(5,20+2*Height,Width,Height));}public static void main(String [] argv){ JFrame f=new JFrame("色彩应用"); ColorShape p=new ColorShape(); p.setBackground(color.white); f.getContentPane().add(p); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(640,480); f.setVisible(true);} }
这是我按照书上一点一点敲出来的,但是还是出现了以上的错误,我将我写的代码复制粘贴下来,大家帮我看看怎么修改,谢谢了! |