[填空题] 下面ButtonFrame类创建了一个容器,包含有3个按键。 import javax.swing.*; public class ButtonFrame extends JFrame

8 查阅

[填空题] 下面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)。

计算机考试