您的位置:首页 > 其它

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

2012-03-06 17:22 1611 查看
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();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐