求????按一个按钮把文本框的内容复制到标签中,

gxl123 2006-04-06 08:16:25
目的是:按一个按钮把文本框的内容复制到标签中,
import java.awt.*;
import Java.awt.event.*;
public class TestFrame implements ActionListener{
public static void main(String args[]){
Frame fr=new Frame("基本GUI");
fr.setLayout(new FlowLayout());
fr.setSize(400,200);
fr.pack();
fr.setVisible(true);

Label la=new Label("label");
fr.add(la);

TextField te=new TextField("textfield");
fr.add(te);

Button bu=new Button("button");
fr.add(bu);
bu.addActionListener(this);


}
public void actionPerformed(ActionEvent e){
te.setText=la.getText; /////////////////////此地方不知怎么做??????????
}

}
...全文
329 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
gxl123 2006-04-09
  • 打赏
  • 举报
回复
多谢
RedrainX 2006-04-07
  • 打赏
  • 举报
回复
以后不要在静态方法中访问实例变量
这是你要实现的功能
import java.awt.*;
import java.awt.event.*;
public class TestFrame extends Frame implements ActionListener{

Button bu=new Button("button");
TextField te=new TextField("textfield");
Label la=new Label("label");

public TestFrame(){
this.setLayout(new FlowLayout());
this.setTitle("把文本框的内容复制到标签中");
bu.addActionListener(this);
this.add(la);
this.add(te);
this.add(bu);
this.pack();
this.setSize(400,200);
this.setVisible(true);
}
public static void main(String args[]){
TestFrame fr=new TestFrame();
}
public void actionPerformed(ActionEvent e){
String str=te.getText();
la.setText(str);
}
}
gxl123 2006-04-07
  • 打赏
  • 举报
回复
再顶
gxl123 2006-04-06
  • 打赏
  • 举报
回复
自己顶一下

62,625

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧