日期:2014-05-20  浏览次数:20830 次

如何将键入JTextField里的URL地址的内容在JTextArea里显示
分别各自创建JButton、JTextField和JTextArea对象,在JTextField中输入一个指定的URL地址,然后单击一个按钮读出其连接到的资源内容并显示在JTextArea中。但是,在JTextField中输入字符时,却无法显示出来。
代码如下:
              import   java.awt.*;
import   javax.swing.*;
import   java.awt.event.*;
import   javax.swing.event.*;

public   class   Shiyan15A   extends   JFrame   implements   ActionListener{
        JTextField   Tf   =new   JTextField(10);
        JTextArea   Area=new   JTextArea(10,20);
        JLabel   Lable=new   JLabel( "URL ");
        JButton   Button=new   JButton();
        static   String   str=new   String();
public   Shiyan15A(){
Container   contentPane   =getContentPane();
contentPane.add(Lable);
contentPane.add(Tf);
contentPane.add(Area);
contentPane.add(Button);
contentPane.setLayout(new   FlowLayout(FlowLayout.LEFT));
pack();
setVisible(true);
setBounds(70,80,260,270);
        Button.addActionListener(new   ActionListener(){
        public   void   actionPerformed(ActionEvent   e){
        str=Tf.getText();
                                Area.setText(str);
        }
        });
        }
public   static   void   main(String[]   args)   {
    new   Shiyan15A();
 
        }

}


------解决方案--------------------
顶了