编写一个小应用程序,在其中有一个按钮和一个文本框。单击按钮时,文本框中显示按钮上显示的字
编写一个小应用程序,在其中有一个按钮和一个文本框。单击按钮时,文本框中显示按钮上显示的字
----------------解决方案--------------------------------------------------------
好像不难
----------------解决方案--------------------------------------------------------
恩恩。。。。。路过。。。
----------------解决方案--------------------------------------------------------
程序代码:
public class Activity {
public static void main(String args[])
{
new yxf();
}
}
class yxf extends Frame implements ActionListener
{
private Button button = null;//按钮句柄
private TextArea textarea = null;//文本句柄
yxf()
{
super("测试...");
setBounds(100, 100, 300, 200);
setBackground(Color.gray);
initComponent();
setVisible(true);
validate();
}
private void initComponent()
{
button = new Button("嘿嘿...");
button.addActionListener(this);
add(button, BorderLayout.SOUTH);
textarea = new TextArea();
add(textarea, BorderLayout.CENTER);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent event)
{
System.exit(0);
}
});
}
@Override
public void actionPerformed(ActionEvent event) {
// TODO Auto-generated method stub
if (event.getSource() == button)
{
textarea.append(button.getLabel().toString() + "\n");
}
}
}
public static void main(String args[])
{
new yxf();
}
}
class yxf extends Frame implements ActionListener
{
private Button button = null;//按钮句柄
private TextArea textarea = null;//文本句柄
yxf()
{
super("测试...");
setBounds(100, 100, 300, 200);
setBackground(Color.gray);
initComponent();
setVisible(true);
validate();
}
private void initComponent()
{
button = new Button("嘿嘿...");
button.addActionListener(this);
add(button, BorderLayout.SOUTH);
textarea = new TextArea();
add(textarea, BorderLayout.CENTER);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent event)
{
System.exit(0);
}
});
}
@Override
public void actionPerformed(ActionEvent event) {
// TODO Auto-generated method stub
if (event.getSource() == button)
{
textarea.append(button.getLabel().toString() + "\n");
}
}
}
----------------解决方案--------------------------------------------------------
回复 4楼 诸葛修勤
真棒。。。。。。 ----------------解决方案--------------------------------------------------------