getText();
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
public class TextDemo extends JFrame
{
private JPanel jPanel;
private JTextField txtTextField;
private JLabel lbl;
private JButton btn;
public TextDemo()
{
jPanel = new JPanel();
txtTextField = new JTextField(10);
lbl = new JLabel();
btn = new JButton("按钮");
jPanel.add(txtTextField);
jPanel.add(btn);
jPanel.add(lbl);
btn.addActionListener(new actionListener());
Container contentPane = getContentPane();
contentPane.add(jPanel);
contentPane.setLayout(new FlowLayout());
this.setTitle("获取文本框中的内容");
setSize(300,300);
show();
}
class actionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
lbl.setText(txtTextField.getText());
}
}
public static void main(String args[])
{
new TextDemo();
}
}
这是我才做的一个你看看是不是符合你的要求