以下程序中,使用适当的布局管理器,在Frame框的“North”位置添加一句提示信息,在“South”位置添加一个单行文本框,在这个文本框中输入的内容将会显示在“Center”位置。运行结果如下图所示。注意:请勿改动main()主方法和其他已有语句内容,仅在横线处填入适当语句。import java.awt.*;import java.awt.event.*;public class Example2_6 extends Frame{public static void main(String [] argv){Example2_6 frame. = new Example2_6("Example2_6");frame, init ();frame.setSize(300, 300);frame, show ();}public Example2_6(String name){super (name);addWindowListener (new WindowAdapter (){ public void windowClosing(WindowEvent e){ __________;}} );}public void init(){setLayout (new ___________);Label labelTitle = new Label("在文本框中输入字符串,可以在Frame. 中间显示");Label showTextLabel = new Label();TextField textField = new TextField("请在这里输入字符串");textField.addActionListener (new AddStringListener(showTextLabel, textField) );add("North", labelTitte);add("Center", showTextLabel);add("South", textField);}}class AddStringListener implements ActionListener{Label label;TextField textField;public AddStringListener(Label label, TextField textField){this. label = label;this.textField = textField;}public void actionPerformed(ActionEvent e){label, setText (textField. getText ());}}
以下程序中,使用适当的布局管理器,在Frame框的“North”位置添加一句提示信息,在“South”位置添加一个单行文本框,在这个文本框中输入的内容将会显示在“Center”位置。运行结果如下图所示。
注意:请勿改动main()主方法和其他已有语句内容,仅在横线处填入适当语句。
import java.awt.*;
import java.awt.event.*;
public class Example2_6 extends Frame
{
public static void main(String [] argv)
{
Example2_6 frame. = new Example2_6("Example2_6");
frame, init ();
frame.setSize(300, 300);
frame, show ();
}
public Example2_6(String name)
{
super (name);
addWindowListener (new WindowAdapter ()
{ public void windowClosing(WindowEvent e)
{ __________;
}
} );
}
public void init()
{
setLayout (new ___________);
Label labelTitle = new Label("在文本框中输入字符串,可以在Frame. 中间显示");
Label showTextLabel = new Label();
TextField textField = new TextField("请在这里输入字符串");
textField.addActionListener (new AddStringListener(showTextLabel, textField) );
add("North", labelTitte);
add("Center", showTextLabel);
add("South", textField);
}
}
class AddStringListener implements ActionListener
{
Label label;
TextField textField;
public AddStringListener(Label label, TextField textField)
{
this. label = label;
this.textField = textField;
}
public void actionPerformed(ActionEvent e)
{
label, setText (textField. getText ());
}
}