Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-04-2009, 08:11 PM
Member
 
Join Date: Jul 2009
Posts: 10
Rep Power: 0
nishant.4545 is on a distinguished road
Default problem with applet execution
I have made an applet that opens notepad. The code is:
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.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 07-04-2009, 11:33 PM
OrangeDog's Avatar
Senior Member
 
Join Date: Jan 2009
Location: Cambridge, UK
Posts: 838
Rep Power: 2
OrangeDog is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-04-2009, 11:41 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,384
Rep Power: 8
Fubarable is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regarding Applet Execution makpandian Java Applets 1 03-13-2009 01:49 PM
Problem with Applet tomjrmkay Java Applets 1 12-19-2008 11:35 AM
Serious applet problem willemjav Java Applets 1 03-25-2008 06:01 PM
applet problem plz HELP shibajisanyal Java Applets 1 01-09-2008 02:47 AM
Applet problem Ed Java Applets 2 07-02-2007 04:35 PM


All times are GMT +2. The time now is 03:40 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org