⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frame1.java~15~

📁 关于internet的程序源码
💻 JAVA~15~
字号:
package urlconnection;import java.awt.*;import java.awt.event.*;import javax.swing.*;import com.borland.jbcl.layout.*;import java.net.*;import java.io.*;public class Frame1 extends JFrame {  JPanel contentPane;  XYLayout xYLayout1 = new XYLayout();  JButton jButton1 = new JButton();  JTextField jTextField1 = new JTextField();  JScrollPane jScrollPane1 = new JScrollPane();  JTextArea jTextArea1 = new JTextArea();  JLabel jLabel1 = new JLabel();  //Construct the frame  public Frame1() {    enableEvents(AWTEvent.WINDOW_EVENT_MASK);    try {      jbInit();    }    catch(Exception e) {      e.printStackTrace();    }  }  //Component initialization  private void jbInit() throws Exception  {    contentPane = (JPanel) this.getContentPane();    jButton1.setText("查询网页信息");    jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));    contentPane.setLayout(xYLayout1);    this.setSize(new Dimension(400, 300));    this.setTitle("Frame Title");    jTextField1.setText("http://news.sina.com.cn:80/index.html");    jTextArea1.setText("jTextArea1");    contentPane.add(jButton1,new XYConstraints(276, 33, 104, 29));    contentPane.add(jTextField1, new XYConstraints(15, 25, 238, 46));    contentPane.add(jScrollPane1,new XYConstraints(22, 74, 357, 182));    contentPane.add(jLabel1, new XYConstraints(24, 261, 305, 26));    jScrollPane1.getViewport().add(jTextArea1, null);  }  //Overridden so we can exit when window is closed  protected void processWindowEvent(WindowEvent e) {    super.processWindowEvent(e);    if (e.getID() == WindowEvent.WINDOW_CLOSING) {      System.exit(0);    }  }  void jButton1_actionPerformed(ActionEvent e) {    try{      StringBuffer buf = new StringBuffer();      //打开URLConnection 类读取      URL myurl = new URL("http://news.sina.com.cn:80/index.html");      URLConnection uc = myurl.openConnection();      InputStream raw = uc.getInputStream();      InputStream buffer = new BufferedInputStream(raw);      //将InputStream与一个Reader链接      Reader r = new InputStreamReader(buffer);      int c;      while((c = r.read()) != -1){        buf.append((char)c);      }      jTextArea1.append(buf.toString());      jLabel1.setText("访问的host是:"+myurl.getHost()+"\n");    }    catch(IOException ex){      ex.printStackTrace();    }  }}class Frame1_jButton1_actionAdapter implements java.awt.event.ActionListener {  Frame1 adaptee;  Frame1_jButton1_actionAdapter(Frame1 adaptee) {    this.adaptee = adaptee;  }  public void actionPerformed(ActionEvent e) {    adaptee.jButton1_actionPerformed(e);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -