Re: [問題] java 2D
※ 引述《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
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 3 篇):