SMF For Free Support Forum
Signup For Free Forum
July 05, 2008, 03:46:41 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Welcome to SMF For Free. The best free SMF Host
 
   Home   Help Search Arcade Gallery Login Register  

Pages: [1]
  Print  
Author Topic: Wana Update Whole GUI  (Read 492 times)
0 Members and 1 Guest are viewing this topic.
zilchuary
SMF For Free Newbie
*
Offline Offline

Posts: 11


View Profile
« on: January 04, 2008, 01:28:46 pm »

Code:
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
« Last Edit: January 04, 2008, 01:37:14 pm by zilchuary » Logged
LaundryLady
Global Moderator
*
Offline Offline

Posts: 2772


Keep Smiling, Let'em Wonder!


View Profile WWW
« Reply #1 on: January 04, 2008, 01:34:05 pm »

I don't see the support portion of this post.  What is this supposed to do?
Logged

zilchuary
SMF For Free Newbie
*
Offline Offline

Posts: 11


View Profile
« Reply #2 on: January 04, 2008, 01:35:24 pm »

Updates the GUI
Logged
LaundryLady
Global Moderator
*
Offline Offline

Posts: 2772


Keep Smiling, Let'em Wonder!


View Profile WWW
« Reply #3 on: January 04, 2008, 01:36:11 pm »

and why would I want to update the graphical user interface?
Logged

zilchuary
SMF For Free Newbie
*
Offline Offline

Posts: 11


View Profile
« Reply #4 on: January 04, 2008, 01:38:45 pm »

Some People Need it For Some Servers/Games Ect
actually i have been asked alot for this
Logged


Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.5 | SMF © 2006-2008, Simple Machines LLC
ServerBeach Coupon
Page created in 0.357 seconds with 17 queries.