import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class getHtmlForm implements MouseListener{
    JFrame  frame=new JFrame("欢迎光临");
    Container cp=frame.getContentPane();
    JLabel  label1=new JLabel("请输入您要抓取网页的内容的网址:");
    JTextField  txt1=new JTextField();
    JButton  b=new JButton( "输出:");
   public getHtmlForm(){
       cp.setLayout(new FlowLayout());
       cp.add(label1);
       cp.add(txt1);
       cp.setBackground(Color.BLUE);
       txt1.setColumns(10);
       b.addMouseListener(this);
       cp.add(b);
       frame.setVisible(true);
       frame.setSize(500,500);
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   }
  public static void main(String args[]){
    new getHtmlForm();
  }
 public void mouseClicked(MouseEvent e){
    System.out.println(txt1.getText());
   }
 public void mouseEntered(MouseEvent e){}
 public void mouseExited(MouseEvent e){}
 public void mousePressed(MouseEvent e){}
 public void mouseReleased(MouseEvent e){}}
这个我想最后把文本框中的内容在窗口上输出而不是输出在控制台  该怎么修改啊?

解决方案 »

  1.   

    在窗口中加一个jpanal,在mouseClicked方法中jpanal的setText,方法加jpanal中就可以了
      

  2.   

    public class getHtmlForm extends MouseAdapter {
    JFrame frame = new JFrame("欢迎光临");
    Container cp = frame.getContentPane();
    JLabel label1 = new JLabel("请输入您要抓取网页的内容的网址:");
    JTextField txt1 = new JTextField();
    JButton b = new JButton("输出:");
    JLabel label = new JLabel(); public getHtmlForm() {
    cp.setLayout(new FlowLayout());
    cp.add(label1);
    cp.add(txt1);
    cp.setBackground(Color.BLUE);
    txt1.setColumns(10);
    b.addMouseListener(this);
    cp.add(b);
    cp.add(label);
    frame.setVisible(true);
    frame.setSize(500, 500);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    } public static void main(String args[]) {
    new getHtmlForm();
    } public void mouseClicked(MouseEvent e) {
    System.out.println(txt1.getText());
    label.setText(txt1.getText());
    }
    }