How to get the changed picture?


2003-07-29 09:24:44 AM
jbuilder1
I write a program to get a pictrue in a web server,after the picture was changed,I found my program can not get the new pictrue if i do not restart my program.
I used JDK 1.4.1_02.
Can you help me?
Following is my code:
package test;
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.io.*;
import java.net.*;
public class Frame1 extends JFrame
{
Image imageLogo = null;
String strWelcomeInfo = "";
String strHomePage = "";
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JLabel lblLogo = new JLabel();
JButton jButton3 = new JButton();
//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();
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
jButton1.setText("close");
jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
jButton2.setText("Refresh");
jButton2.addActionListener(new Frame1_jButton2_actionAdapter(this));
jButton3.setText("clear");
jButton3.addActionListener(new Frame1_jButton3_actionAdapter(this));
contentPane.add(jPanel1, BorderLayout.CENTER);
jPanel1.add(lblLogo, null);
contentPane.add(jPanel2, BorderLayout.SOUTH);
jPanel2.add(jButton3, null);
jPanel2.add(jButton2, null);
jPanel2.add(jButton1, 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)
{
System.exit(0);
}
void jButton2_actionPerformed(ActionEvent e)
{
try
{
URL url = new URL("127.0.0.1/image/logo.gif");
this.imageLogo = Toolkit.getDefaultToolkit().getImage(url);
this.lblLogo.setIcon(new ImageIcon(this.imageLogo));
Toolkit.getDefaultToolkit().sync();
}
catch (Exception ex)
{
System.out.println("error : " + ex);
}
}
void jButton3_actionPerformed(ActionEvent e)
{
this.lblLogo.setIcon(null);
}
public static void main(String[] args)
{
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e)
{
e.printStackTrace();
}
(new Frame1()).show();
}
}
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);
}
}
class Frame1_jButton2_actionAdapter implements java.awt.event.ActionListener
{
Frame1 adaptee;
Frame1_jButton2_actionAdapter(Frame1 adaptee)
{
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.jButton2_actionPerformed(e);
}
}
class Frame1_jButton3_actionAdapter implements java.awt.event.ActionListener
{
Frame1 adaptee;
Frame1_jButton3_actionAdapter(Frame1 adaptee)
{
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.jButton3_actionPerformed(e);
}
}