[填空题] 下面Buttonframe类创建了一个容器,包含有3个按键。 import javax.swing.*; public class Buttonframe extends Jframe { JButton Button1= new JButton("Button1"); JButton Button2= new JButton("Button2"); JButton Button3= new JButton("Button3"); public Buttonframe() {super("Buttonframe");setSize (100,150);setDefaultCloseOperation(Jframe. EXIT ON CLOSE);JPanel pane = new JPanel();pane.add(Buttonl);pane. add(Button2);pane. add (Button3); 【12】 ; } public static void main(String args[]) {Buttonframe bf= new Buttonframe();bf. show(}; } } 请在程序代码中的画线处添上正确的语句,使程序完整。
参考答案:
setContentPane(pane)问题解析:
本题考查向swing容器添加组件的基本知识。往容器添加组件,可将容器分解为窗格,这是容器内的容器,再将组件添加到容器的内容窗格中。可以使用下列步骤在容器的内容窗格中添加组件。 ①创建一个窗格。 ②使用它的add(Component)方法在窗格中添加组件。 ③以窗格为参数调用setContentpane(Container)。

![[填空题] 下面ButtonFrame类创建了一个容器,包含有3个按键。 import javax.swing.*; public class ButtonFrame extends JFrame [填空题] 下面ButtonFrame类创建了一个容器,包含有3个按键。 import javax.swing.*; public class ButtonFrame extends JFrame](http://www.mshxw.com/aiimages/31/254482.png)
