Update applet text runtime
Hello,
I am new bee in Java. First I'm sorry if posting at wrong place.
I am developing 1 applet program which download the file from server to user system then install it and run it.
My issue is I want applet text to change according to process going on. If it is downloading file from server then it should display "downloading...", if it is installing then text should "Installing...", and at last "successfully installed..."
How can I do that? Please help me out.
Re: Update applet text runtime
I recommend you try to make something and post what you've done as an SSCCE, and ask a specific question. Given your question can be boiled down to several phases of where you are stuck, it makes it that much harder for anyone to point you in the right direction. Are you stuck at making a user interface? Downloading a file? Concurrency issues? Writing an applet in general? Is the issue with your current code and compilation/runtime errors?
Re: Update applet text runtime
below is my applet code. Can you help me out with my code.
I have one more issue in my code for mac os that I will let you know later on.
Code :
import java.applet.*;
import java.awt.Graphics;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class exeLoader extends Applet {
public String userId;
public String vuerId;
public String text = "VuerCast";
public void start()
{
userId = getParameter("userId");
vuerId = getParameter("vuerId");
try {
exeLoad(userId, vuerId);
} catch (IOException ex) {
Logger.getLogger(exeLoader.class.getName()).log(Level.SEVERE, null, ex);
} catch (InterruptedException ex) {
Logger.getLogger(exeLoader.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void exeLoad(String userId, String vuerId) throws IOException, InterruptedException
{
String urlPath = "http://localhost:8080/VuerCastWebLoader/";
String OSName = System.getProperty("os.name").toLowerCase();
int WinOS = OSName.indexOf("windows");
int MacOS = OSName.indexOf("mac");
Runtime run = Runtime.getRuntime();
//Code if Windows OS detected//
if (WinOS != -1) {
String filePath = System.getenv("ProgramFiles") + "\\VuerCast\\VuerCast.exe";
String copyPath = System.getProperty("java.io.tmpdir");
String fileName = "VuerCast.exe";
File exeFile = new File(filePath);
if (!exeFile.exists()) {
text = "Downloading...";
repaint();
java.io.BufferedInputStream in = new java.io.BufferedInputStream(new java.net.URL(urlPath + fileName).openStream());
java.io.FileOutputStream fos = new java.io.FileOutputStream(copyPath + fileName);
java.io.BufferedOutputStream bout = new BufferedOutputStream(fos, 1024);
byte[] data = new byte[1024];
int x = 0;
while ((x = in.read(data, 0, 1024)) >= 0) {
bout.write(data, 0, x);
}
bout.close();
in.close();
text = "Installing...";
repaint();
Process p = run.exec(copyPath + fileName);
p.waitFor();
text = "Deleting temporary files...";
repaint();
boolean f = new File(copyPath + fileName).delete();
try{
run.exec(filePath + " " + userId + " " + vuerId);
}
catch(Exception e)
{
text = "Oops!! Installation failed.";
repaint();
System.out.println("Can not initialize application."
+ "\nUnable to open "+filePath);
System.exit(0);
}
text = "Succesfully Installed.";
repaint();
} else {
text = "Initializing VuerCast...";
repaint();
run.exec(filePath + " " + userId + " " + vuerId);
}
}
//Code if Macintosh OS detected//
if(MacOS != -1){
String filePath = System.getProperty("user.home") + "/Applications/VuerCast.app/Contents/MacOS/VuerCast";
String copyPath = System.getProperty("user.home") + "/";
String fileName = "VuerCast.dmg";
File exeFile = new File(filePath);
if (!exeFile.exists()) {
text="Downloading...";
repaint();
java.io.BufferedInputStream in = new java.io.BufferedInputStream(new java.net.URL(urlPath + fileName).openStream());
java.io.FileOutputStream fos = new java.io.FileOutputStream(copyPath + fileName);
java.io.BufferedOutputStream bout = new BufferedOutputStream(fos, 1024);
byte[] data = new byte[1024];
int x = 0;
while ((x = in.read(data, 0, 1024)) >= 0) {
bout.write(data, 0, x);
}
bout.close();
in.close();
text="Installing....";
repaint();
run.exec("chmod 777 " + copyPath + fileName);
run.exec("hdiutil mount " + copyPath + fileName);
run.exec("open " + copyPath + fileName);
System.out.println("open \"/Volumes/Install VuerCast/Install VuerCast.app\"");
run.exec("chmod 777 /Volumes/Install\\ VuerCast/Install\\ VuerCast.app");
Process p = run.exec("open Install\\ VuerCast.app",null,new File("/Volumes/Install\\ VuerCast"));
p.waitFor();
System.out.println(p.getErrorStream());
System.out.println(p.exitValue());
text="Succesfully Installed";
repaint();
File dmgFile = new File(filePath);
while(true){
if(dmgFile.exists()){
run.exec(filePath+" " + userId + " " + vuerId);
break;
}
}
boolean f = new File(filePath).delete();
} else {
text="Initializing VuerCast...";
repaint();
run.exec("/Applications/VuerCast.app/Contents/MacOS/VuerCast " + userId + " " + vuerId);
}
}
}
public void paint(Graphics g)
{
g.drawString(text, 20, 20);
}
}
My applet code does everything what I need (it download, install and run the application). Now I just want to display static text whatever going on in my applet.
I have set a 'text' variable then repaint() the applet but it's not working.
Please suggest me...
Re: Update applet text runtime