import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import javax.swing.JButton
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
public class Updater implements ActionListener
{
public JFrame updateFrame;
public JPanel updatePanel;
public JButton updateButton;
public JProgressBar updateProgress;
public Updater()
{
updateFrame = new JFrame("Updater");
updatePanel = new JPanel(new BorderLayout());
updateButton = new JButton("Update");
updateButton.setActionCommand("Update");
updateButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
updateButton.addActionListener(this);
updateButton.setPreferredSize(new Dimension(150, 50));
updateProgress = new JProgressBar();
updateProgress.setStringPainted(true);
updateProgress.setString("Click update to update");
updateProgress.setPreferredSize(new Dimension(150, 50));
updateProgress.setMaximum(100);
updateProgress.setValue(0);
updatePanel.add(updateButton, BorderLayout.CENTER);
updatePanel.add(updateProgress, BorderLayout.SOUTH);
updateFrame.add(updatePanel);
updateFrame.pack();
updateFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
updateFrame.setVisible(true);
}
public static void main(String[] arg)
{
new Updater();
}
public void deleteFile(File aFile)
{
if(aFile.exists())
{
updateProgress.setString("Deleting jar");
aFile.delete();
}
}
public void actionPerformed(ActionEvent evt)
{
String c = evt.getActionCommand();
if(c.equals("Update"))
{
File jar = new File("runescape.jar");
deleteFile(jar);
try
{
updateProgress.setString("Connecting");
URLConnection jarUC;
jarUC = new URL("http://sl5.runescape.com/runescape.jar").openConnection();
DataInputStream down = new DataInputStream(jarUC.getInputStream());
updateProgress.setString("Creating data stream");
PrintStream out = new PrintStream(jar);
int length = jarUC.getContentLength();
updateProgress.setString("Downloading jar");
while(jar.length() < length)
{
out.write(down.read());
updateProgress.setValue((int)(jar.length()/length*100));
}
updateProgress.setString("Runescpe jar downloaded");
updateButton.setEnabled(false);
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}
For the Java Gurus on this forums
they will all now whats this does
... for other people who dont understand
.. it actually says it Update GUI
Thats all it does
There