package cgi;import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.net.*;
import java.io.*;
import javax.swing.*;public class Applet1 extends Applet {  private JButton jButton1 = new JButton();
  private JLabel jLabel1 = new JLabel();
  //Construct the applet
  public Applet1() {
  }
  //Initialize the applet
  public void init() {
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  //Component initialization
  private void jbInit() throws Exception
  {
    jButton1.setText("刷新");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButton1_actionPerformed(e);
      }
    });
    
    try{
     URL url=new URL("http://192.168.4.36/icons/pic/1.gif");
     Toolkit tk=Toolkit.getDefaultToolkit();
     Image  image=tk.getImage(url);
     ImageIcon imgIcon = new ImageIcon(image);
     jLabel1.setIcon(imgIcon);
     }
     catch(Exception e1)
      {}
    this.add(jButton1, null);
    this.add(jLabel1, null);
   }
   //鼠标时间处理
   void jButton1_actionPerformed(ActionEvent e) {
      try{      URL url=new URL("http://192.168.4.36/icons/pic/1.gif");
      Toolkit tk=Toolkit.getDefaultToolkit();
      Image  image=tk.getImage(url);
      ImageIcon imgIcon = new ImageIcon(image);
      jLabel1.setIcon(imgIcon);
      }
      catch(Exception e1)
      {}  }}

解决方案 »

  1.   

    Yes you  are right!
      

  2.   

    但是当服务器图片内容改变,文件名不变,通过按纽刷新,但是label显示的图片内容还是没变化
    请问为什么?怎么解决啊????
      

  3.   

    一点建议(或许你已经解决了)
    处理按钮的时候,不用:
    URL url=new URL("http://192.168.4.36/icons/pic/1.gif");
    而是String  new_url=new...   ,URL url=new URL(new_url)
    如果没用别笑