编译下面的代码后,我Could not find symbol
在包含String str = getText(jtf)
. 我检查了 java 文档,但我无法理解语法。请帮助我,因为我是一个完整的初学者。谢谢!
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Frame implements ActionListener
{
Frame()
{
JFrame jf = new JFrame("Welcome");
Container c = jf.getContentPane();
JPanel jp = new JPanel();
c.add(jp);
JLabel jl = new JLabel("Please enter your name");
jp.add(jl);
JTextField jtf = new JTextField(30);
jp.add(jtf);
String str = getText(jtf);
JButton jb = new JButton("Submit");
jp.add(jb);
jb.addActionListener(this);
jl.setForeground(Color.black);
jf.setBounds(200,200,400,400);
jf.setVisible(true);
jf.setDefaultCloseOperation(jf.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent ae)
{
JOptionPane.showMessageDialog(null,"Welcome"+str);
}
public static void main (String[] args)
{
Frame f = new Frame();
}
}