作者willieliao (Willie Liao)
看板java
標題Re: [問題] JButton getGraphics
時間Thu Apr 24 05:32:57 2008
※ 引述《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