作者TonyQ (骨头)
看板java
标题Re: [问题] java 2D
时间Mon Jun 23 11:05:08 2008
※ 引述《TNC (code)》之铭言:
: 实在是不懂java 2D的图到底是如何画到画布上的
: 例如:
: public void paintComponent(Graphics2D g){
: Graphics2D g2 = (Graphics2D)g;
: Arc2D pie = new Arc2D.Float(0,50,150,150,-30,90,Arc2D.PIE);
: g2.setPaint(Color.blue);
: g2.fill(pie);
: }
: 在这里把要画的图设定好之後
: 到底该如何让它显示到指定的画布上呢?
: (画布为JComponent或 canvas)
method不会独立存在,所以你应该要有个装这个method的元件,
既然你是paintComponent,常理上可以推论,
你这个method应该放在一个JComponent的子类别的成员里面,
这不是画匠->画布的模式,而是元素->画自己的模式。
paint(Grahpics g) 才比较像是画匠->画布的模式。
(很少用,不过通常有需要时我会比较喜欢把它用在Frame上。)
另外你的方法宣告有问题,以paintComponent而言,
要复写 JComponent的方法要用 paintComponent(Graphics g) 。
--
I am a person, and I am always thinking .
Thinking in love , Thinking in life ,
Thinking in why , Thinking in worth.
I can't believe any of what ,
I am just thinking then thinking ,
but worst of all , most of mine is thinking not actioning...
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.134.27.68