Re: [問題] swing的button問題
※ 引述《saegusa ( )》之銘言:
: 黄色的部分我想用「frame.」 但是怎麼弄都不成功
: 我現在是這樣弄
: frame.getContentPane().setLayout(new FlowLayout());
: JButton b1 = new JButton("OK");
: b1.addActionListener(frame);
: frame.getContentPane().add(b1);
: 但是不行 要怎麼改才好?
因為你JButuonTest本身就是繼承了JFrame,所以在建構子應該使用this來指向frame,
而不需要再宣告一個JFrame變數來做操作。如果你想在裡面使用另一個像frame的來管
理,應該使用JPanel,而不是JFrame,因為JFrame已經是最上層物件。
--
歡迎來我的網誌看看
@ http://doublekai.org/blog
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.240.37.127
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):