import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class TextFieldDemo
{
public static void main(String[] args)
{
Frame frame = new Frame("文本组件的制作");
frame.setBounds(400,300,300,300);
TextField tf = new TextField();
tf.text = "fgdfdfsd"; // 错误:text在TextComponent中不是公共的; 无法从外部程序包中 对其进行访问
frame.add(tf);
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
frame.setVisible(true);
}
}
请问应该怎么修改?谢谢
------解决方案--------------------
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class TextFieldDemo
{
public static void main(String[] args)
{
Frame frame = new Frame("文本组件的制作");
frame.setBounds(400, 300, 300, 300);
TextField tf = new TextField();
//tf.text = "fgdfdfsd"; // 错误:text在TextComponent中不是公共的; 无法从外部程序包中 对其进行访问
tf.setText("fgdfdfsd");
frame.add(tf);
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
frame.setVisible(true);
}
}
是这样不?
怎么不用JtextField?