Re: [問題] JButton getGraphics

看板java作者 (Willie Liao)時間17年前 (2008/04/24 05:32), 編輯推噓0(003)
留言3則, 1人參與, 最新討論串2/7 (看更多)
※ 引述《lovesneakers (sneakers)》之銘言: : public class NewBtn extends JFrame { : public NewBtn() { : setSize(100, 100); class myButton extends JButton { public void paint(Graphics g) { super.paint(g); g.setColor(Color.BLUE); g.fillOval(0, 0, 100, 100); } public myButton(String label) { super(label); } } myButton btn = new MyButton("Whatever"); getContentPane().add(btn); : setVisible(true); : } : public static void main(String[] args) : { : new NewBtn(); : } : } : 請問我要像上面的方法, 在生出 JButton 後改變其 Graphics : 能辦到嗎? 不用繼承的方法 : 我試的結果似乎都會被它的 text 蓋在底下 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 208.238.98.1

04/24 05:33, , 1F
喔沒看到你說不用繼承的方法..
04/24 05:33, 1F

04/24 05:35, , 2F
你原來的code 那個oval只會劃一次,就算放在上層下次
04/24 05:35, 2F

04/24 05:39, , 3F
paint的時候也會不見,用overwrite paint最方便
04/24 05:39, 3F
文章代碼(AID): #183wiA86 (java)
討論串 (同標題文章)
文章代碼(AID): #183wiA86 (java)