Results 1 to 3 of 3
  1. #1
    nishant.4545 is offline Member
    Join Date
    Jul 2009
    Posts
    10
    Rep Power
    0

    Default problem with applet execution

    I have made an applet that opens notepad. The code is:
    Java Code:
    import java.applet.*;
    import java.awt.*;
    
    
    public class Note extends Applet{
     public void paint(Graphics g) {
    
    g.drawString("Open a notepad",50,10);
    try
    {
     Runtime r=Runtime.getRuntime();
        	 Process p=null;
        	 	p=r.exec("notepad");
    }catch(Exception e){
    	g.drawString(e.toString(),50,50);
    }
        
    }}
    Then I have created its jar file using the command

    jar cvf Note.jar Note.class

    Then I signed this jar file using keytool to give it necessary permisiions using following commands:

    keytool -genkey -alias Note -validity 365
    jarsigner Note.jar Note

    Then I created an html to operate the applet from within the jar file.

    My problem is that as the applet starts it opens several (165) instances of notepad. When I clase all those instances, all the instances appear again.
    plz help me to understand the problem.

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Your code is called every single time the applet redraws, as you put it in the paint() method. Try somewhere else. Maybe when the applet starts, or when you press a button?
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Never do that sort of thing from within a paint method. You have very little control of when or even if the paint method will be called. Instead do this in a non-paint method or constructor.

Similar Threads

  1. Regarding Applet Execution
    By makpandian in forum Java Applets
    Replies: 1
    Last Post: 03-13-2009, 01:49 PM
  2. Problem with Applet
    By tomjrmkay in forum Java Applets
    Replies: 1
    Last Post: 12-19-2008, 11:35 AM
  3. Serious applet problem
    By willemjav in forum Java Applets
    Replies: 1
    Last Post: 03-25-2008, 06:01 PM
  4. applet problem plz HELP
    By shibajisanyal in forum Java Applets
    Replies: 1
    Last Post: 01-09-2008, 02:47 AM
  5. Applet problem
    By Ed in forum Java Applets
    Replies: 2
    Last Post: 07-02-2007, 04:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •