Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Update applet text runtime

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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?

  3. #3
    Junior Member
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

    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...

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Update applet text runtime

    Suggested reading:
    Lesson: Concurrency in Swing (The Java™ Tutorials > Creating a GUI With JFC/Swing)

Similar Threads

  1. passign value at the runtime in the program
    By Shantanu Gontia in forum Java Theory & Questions
    Replies: 1
    Last Post: October 25th, 2011, 06:19 AM
  2. Runtime.Exec() not waiting
    By PrinceSendai in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: June 9th, 2011, 02:12 PM
  3. Runtime Error
    By SyntheticD in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 10th, 2011, 04:09 PM
  4. Runtime Error running in UVA
    By mathfxr in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 17th, 2010, 02:06 PM
  5. Create buttons at runtime
    By rtumatt in forum AWT / Java Swing
    Replies: 2
    Last Post: May 24th, 2010, 06:42 AM