河南成教 / Java程序设计
[简答题] 阅读下列程序,请用简述程序运行时呈现的界面。
import java.applet.*;
import java.awt *;
import javax.swing.*;
class MyPanel extends JPanel {
JButton button; JLabel label;
MyPanel(String s1, String s2) {
this.setLayout(new GridLayout(2, 2));
button = new JButton(s1);
label = new JLabel(s2, JLabel.CENTER);
add(button); add(label); add(new JLabel());
}
}
public class Class1 {
public static void main(String args[]) {
JFrame mw = new JFrame("一个示意窗口");
mw.setSize(400, 250);
Container con = mw.getContentPane();
con.setLayout(new BorderLayout());
MyPanel panel1, panel2;
panel1 = new MyPanel("按钮1" ,"标签1");
panel2 = new MyPanel("按钮2", "标签2");
JButton button = new JButton("开始按钮");
con.add(panel1, "North");con.add(panel2, "South");
con.add(button, "Center");
mw.setVisible(true);
}
}
import java.applet.*;
import java.awt *;
import javax.swing.*;
class MyPanel extends JPanel {
JButton button; JLabel label;
MyPanel(String s1, String s2) {
this.setLayout(new GridLayout(2, 2));
button = new JButton(s1);
label = new JLabel(s2, JLabel.CENTER);
add(button); add(label); add(new JLabel());
}
}
public class Class1 {
public static void main(String args[]) {
JFrame mw = new JFrame("一个示意窗口");
mw.setSize(400, 250);
Container con = mw.getContentPane();
con.setLayout(new BorderLayout());
MyPanel panel1, panel2;
panel1 = new MyPanel("按钮1" ,"标签1");
panel2 = new MyPanel("按钮2", "标签2");
JButton button = new JButton("开始按钮");
con.add(panel1, "North");con.add(panel2, "South");
con.add(button, "Center");
mw.setVisible(true);
}
}
参考答案: