Type following in the command line while running the application:
java -Xmx512m
*Note - here i have set 512MB as memory capacity. It could take other values like 256, 1024 etc. Further we can set the minimum size by following command.
java -Xmsm
/*
* Author Akila Nonis
* /
setImgUrlValues();
//Setting corresponding values to be appended to URL
//URL url = new URL("ftp://"+user+":"+password+"@"+server+file+".jpg;type=i");
//Setting URL
URL url = new URL("ftp://"+imgUserName+":"+imgPassword+"@"+imgUrl+imgName+";type=i");
//Setting URL connection
URLConnection con = url.openConnection();
//Reading image file data from and generating a local copy
BufferedInputStream in = new BufferedInputStream(con.getInputStream());
FileOutputStream out = new FileOutputStream("C:\\Sign\\"+imgName);
int i = 0;
byte[] bytesIn = new byte[1024];
while ((i = in.read(bytesIn)) >= 0)
{
out.write(bytesIn, 0, i);
}
out.close();
in.close();
//-------------------------------------------------------------
//File remoteFile = new File(url.toString());
//if (remoteFile.exists())
// System.out.println("Remote file size = " + remoteFile.length() +" " + url.toURI());
//-------------------------------------------------------------
System.out.println("Local file size = " + localFile.length());
System.out.println("this is Image Name " + imgName);
//Setting the downloaded local image copy as the icon image
lblSignature.setIcon(new ImageIcon("C:\\Sign\\"+imgName));
/* ---------- Splasher.java -------------*/
import javax.swing.ImageIcon;
/*
* Author : Akila Nonis
* Desc : This thread displayes the splash screen and progress bar
* Date : 13.02.2007
*/
public class Splasher extends Thread{
public void run(){
//Image for splash is set here
String iconPath = "/images/Splash.gif";
ImageIcon splashImage = new ImageIcon(iconPath);
//SplashScreen scr = new SplashScreen(splashImage);
SplashScreen scr = new SplashScreen(new ImageIcon(getClass().getResource("/images/Splash.gif")));
scr.setLocationRelativeTo(null);
scr.setProgressMax(100);
scr.setScreenVisible(true);
//Initailizing main MDI form
MainMDI mmdi = new MainMDI();
//Delaying
for (int i = 0; i <= 100; i++)
{
for (long j=0; j<100000; ++j)
{
String poop = " " + (j + i);
}
scr.setProgress("Loading.. " + i, i);
}
scr.setScreenVisible(false);
//Displaying main MDI form
mmdi.setVisible(true);
scr = null;
//Removing unusable objects form memory
System.gc();
}
}
/* ---------- End of Splasher.java -------------*/
/* ---------- SplashScreen.java -------------*/
import java.awt.BorderLayout;
import javax.swing.*;
import java.awt.*;
/*
* Author : Akila Nonis
* Desc : This class constructs the spalsh image
* Date : 13.02.2007
*/
public class SplashScreen extends JWindow {
BorderLayout borderLayout1 = new BorderLayout();
JLabel imageLabel = new JLabel();
JPanel southPanel = new JPanel();
FlowLayout southPanelFlowLayout = new FlowLayout();
JProgressBar progressBar = new JProgressBar();
ImageIcon imageIcon;
public SplashScreen(ImageIcon imageIcon) {
this.imageIcon = imageIcon;
try {
init();
}
catch(Exception ex) {
System.out.println(ex.toString());
}
}
/*
* Initializes splash screen
*/
void init() throws Exception {
imageLabel.setIcon(imageIcon);
imageLabel.setSize(new java.awt.Dimension(365,206));
this.getContentPane().setLayout(borderLayout1);
southPanel.setLayout(southPanelFlowLayout);
southPanel.setBackground(Color.BLACK);
this.getContentPane().add(imageLabel, BorderLayout.CENTER);
this.getContentPane().add(southPanel, BorderLayout.SOUTH);
southPanel.add(progressBar, null);
this.pack();
}
/*
* Sets maximum limit of the progres bar
*/
public void setProgressMax(int maxProgress)
{
progressBar.setMaximum(maxProgress);
}
/*
* Sets and updates values of the progress bar
*/
public void setProgress(int progress)
{
final int theProgress = progress;
SwingUtilities.invokeLater(new Runnable() {
public void run() {
progressBar.setValue(theProgress);
}
});
}
/*
* Sets and updates values of the progress bar
*/
public void setProgress(String message, int progress)
{
final int theProgress = progress;
final String theMessage = message;
setProgress(progress);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
progressBar.setValue(theProgress);
setMessage(theMessage);
}
});
}
/*
* Makes splash screen visible
*/
public void setScreenVisible(boolean b)
{
final boolean boo = b;
SwingUtilities.invokeLater(new Runnable() {
public void run() {
setVisible(boo);
}
});
}
/*
* Sets string messsage in the progress bar
*/
private void setMessage(String message)
{
if (message==null)
{
message = "";
progressBar.setStringPainted(false);
}
else
{
progressBar.setStringPainted(true);
}
progressBar.setString(message);
}
/* ---------- End of SplashScreen.java -------------*/
Have a nice day!
Thanks for visiting my blog :)