编写程序包括一个标签、一个文本框和一个按钮,当用户单击按钮时,程序把文本框中的内容复制到标签中

来源:互联网 发布:测试fps的软件 编辑:程序博客网 时间:2024/05/22 02:21
import java.awt.*;
import java.awt.event.*;


public class CopyStringToLabel extends Frame implements ActionListener
{
private Label label = new Label();
private TextField output = new TextField();
private Button copy = new Button("Copy");

private class WindowCloser extends WindowAdapter
{
public void windowClosing(WindowEvent we)
{ System.exit(0);}
}
public CopyStringToLabel ()
{
super("Copy a String To Label");
setup();
copy.addActionListener(this);
addWindowListener(new WindowCloser());

}


public void actionPerformed(ActionEvent e)
{
if(e.getSource() == copy)
       label.setText(output.getText());

}


private void setup()
{
Panel textGrid = new Panel();
textGrid.setLayout(new GridLayout(2,1));
textGrid.add(label);
textGrid.add(output);
setLayout(new BorderLayout());
add("Center",textGrid);
add("South",copy);
pack();
setVisible(true);
}
public static void main(String[] args) {
CopyStringToLabel cop = new CopyStringToLabel();
}
}
0 0
原创粉丝点击