java设置一个文本框和按钮,点击按钮获取文本框的值并输出出来,请大神帮看看哪里不对啊。。。。。。
importjava.awt.*;importjava.applet.*;importjava.applet.Applet;importjava.awt.event.Ac...
import java.awt.*;
import java.applet.*;
import java.applet.Applet;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
public class test extends Applet
{
String str=new String();
TextField tf;
Button f;
public void init()
{
tf=new TextField(5);
f=new Button("确定");
add(tf);
this.add(f);
}
public void start()
{
f.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e){methodA();}});
}
public void methodA(){str=tf.getText();}
public void paint(Graphics g)
{g.drawString(str,20,40);}
} 展开
import java.applet.*;
import java.applet.Applet;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
public class test extends Applet
{
String str=new String();
TextField tf;
Button f;
public void init()
{
tf=new TextField(5);
f=new Button("确定");
add(tf);
this.add(f);
}
public void start()
{
f.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e){methodA();}});
}
public void methodA(){str=tf.getText();}
public void paint(Graphics g)
{g.drawString(str,20,40);}
} 展开
1个回答
2017-04-21
展开全部
在 methodA 里面加上一个
repaint();
repaint();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询