看板 java 關於我們 聯絡資訊
※ 引述《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
willieliao:喔沒看到你說不用繼承的方法.. 04/24 05:33
willieliao:你原來的code 那個oval只會劃一次,就算放在上層下次 04/24 05:35
willieliao:paint的時候也會不見,用overwrite paint最方便 04/24 05:39