Applet.getImage() but so sloooooowly...

I've seen a couple of questions posted about this issue, but no resolution. Essentially, performance of Applet().getImage() is unacceptably slow. It happens on my machine, and others.
I'm using PlugIn 1.3.1 in WinIE 5.5, and have the following simple JApplet:
public class GoofyApplet extends JApplet
public void init()
Image img = getImage(getDocumentBase(), "goofy/mickey/rtb_down.jpg"); // a 4K .jpg
JLabel lab = new JLabel("test", new ImageIcon(img), JLabel.CENTER);
Container content = getContentPane();
content.add(lab);
validate();
repaint();
I run that, and have ample time to curse and fume. About 20-50 seconds.
Note the docs for getImage:
"This method always returns immediately, whether or not the image exists. When this applet attempts to draw the image on the screen, the data will be loaded. The graphics primitives that draw the image will incrementally paint on the screen."
First of all, timing tests have shown that this definition of "immediately" is pretty flexible. In my last test, getImage took 38230 ms.
I've been cruising around the Forums, looking for an answer to this question and have yet to find it. This is disturbing--I can't believe SUN would ship the plug-in with this kind of behavior--but does this mean there is no solution?
Cheers,
Jon

You need to wait for the image to load in an applet. If you use the Swing version of ImageIcon it will do this automatically for you. Else, use the following methods:
* Loads an image as a resource.
* Note:  With Swing, could use ImageIcon instead of createImage()/MediaTracker.
public Image loadImage(String imageName) {
   Image image = null;
   URL url = getClass().getResource(imageName);
   try {
      image = createImage((ImageProducer) url.getContent());
      if (image==null) throw new Exception();
      waitForImageToLoad(this,image);
   } catch (Exception e) {
      System.out.println("unable to load image: "+imageName);
   }//end try
   return image;
}//end loadImage
* wait for an image to completely load. Use in an applet.
public static void waitForImageToLoad(Component component, Image image) {
   MediaTracker tracker = new MediaTracker(component);
   try {
      tracker.addImage(image, 0);
      tracker.waitForID(0);
   } catch (InterruptedException e) {
      //this should not occur
      e.printStackTrace();
   }//end try
}//end waitForImageToLoad

Similar Messages

  • Applet.getImage(URL) problem

    My computer is installed with JRE7. I found that calling getImage from applet will send the request twice to the server. The request being send to server is http://server:8000/abc?id=100.
    The first request received by server is http://server:8000/abc%3fid%3d100. [which is failed]
    The second request received by server is http://server:8000/abc?id=100. [which is ok]
    My code simply call the following line once:
    theApplet.getImage (theApplet.getCodeBase(), "abc?id=100");
    Is this a bug in the Java plugin?

    I have had exactly the same problem with Applet.getImage.
    In previous JRE versions, Applet.getImage returned immediately,
    but this has apparently changed (I don't know at which version).
    I had to rewrite my program to use Applet.getToolkit().getImage
    - then the program worked as before...
    Looks like a bug to me.
    H�vard Tveite

  • Applet.getImage(URL url) question

    Hi,
    I experienced delays of up to several hundreds milliseconds for calling Applet.getImage(URL url) when accessing an image the first time.
    The API states that "This method always returns immediately, whether or not the image exists." but this does not seem to be correct. In contrast, Applet.getToolkit().getImage() returns immediately.
    What are the differences between these two methods?
    What caching mechanisms (browser, SUN cache) are running behind the scenes?
    Used environment: IE6/Java1.5, IE6/Java1.6, Firefox2/Java1.6 ...all running under WinXP.
    Thank you so much!

    I have had exactly the same problem with Applet.getImage.
    In previous JRE versions, Applet.getImage returned immediately,
    but this has apparently changed (I don't know at which version).
    I had to rewrite my program to use Applet.getToolkit().getImage
    - then the program worked as before...
    Looks like a bug to me.
    H�vard Tveite

  • Applet works in applet viewer but not in website.

    I am an experienced programmer, but new to java (second week). I have made working client/server chatroom in java that works when I use the applet viewer, but when trying to run the applet in an html file, I get this error.
    java.security.AccessControlException: access denied (java.net.SocketPermission 192.168.1.3:5136 connect,resolve)
         at java.security.AccessControlContext.checkPermission(Unknown Source)
         at java.security.AccessController.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkConnect(Unknown Source)
         at sun.plugin2.applet.Applet2SecurityManager.checkConnect(Unknown Source)
         at java.net.Socket.connect(Unknown Source)
         at java.net.Socket.connect(Unknown Source)
         at java.net.Socket.<init>(Unknown Source)
         at java.net.Socket.<init>(Unknown Source)
         at client.Client.init(Client.java:34)
         at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Exception: java.security.AccessControlException: access denied (java.net.SocketPermission 192.168.1.3:5136 connect,resolvI am unsure how to fix this. My first guess is that it is a security issue. Do I need some certificate or something?

    I am trying to connect an applet to a server application run on my computer. The server application is run in the eclipse ide, but I doubt that makes a difference.
    When connecting to the server from the client run through the eclipse ide with the app viewer, everything works fine. When making an html file for the app and running it also on that computer it fails.
    I tried using localhost instead of my internal ip address, and it gave the same errors. I will try signing next, but there must be a way to get this to work without that.

  • Applet compiles but does not appear...

    the applet compiles but does not appear :(
    all that appears is a blank box...hopefully someone can help
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    public class program2 extends Applet implements ActionListener
         private Button btLeft, btRight, btUp, btDown, btBgYellow,
         btBgRed, btBgBlue, btBgOrange, btTxtRed,btTxtYellow, btTxtBlue,
         btTxtOrange, btFtHel, btFtCr, btFtTr, btFtSy;
         private MessagePanel messagePanel;
         private Panel p = new Panel();
         public void init()
              p.setLayout(new BorderLayout());
              messagePanel = new MessagePanel("Java is Life");
              messagePanel.setBackground(Color.white);
              //directional buttons
              Panel pButtons = new Panel();
              pButtons.setLayout(new FlowLayout());
              pButtons.add(btLeft = new Button());
              pButtons.add(btRight = new Button());
              pButtons.add(btUp = new Button());
              pButtons.add(btDown = new Button());
              //Background buttons
              Panel BgButtons = new Panel();
              BgButtons.setLayout(new FlowLayout());
              BgButtons.add(btBgRed = new Button());
              btBgRed.setBackground(Color.red);
              BgButtons.add(btBgYellow = new Button());
              btBgYellow.setBackground(Color.yellow);
              BgButtons.add(btBgBlue = new Button());
              btBgBlue.setBackground(Color.blue);
              BgButtons.add(btBgOrange = new Button());
              btBgOrange.setBackground(Color.orange);
              //text color buttons
              Panel txtButtons = new Panel();
              txtButtons.setLayout(new GridLayout(4,1));
              txtButtons.add(btTxtRed = new Button());
              btTxtRed.setBackground(Color.red);
              txtButtons.add(btTxtYellow = new Button());
              btTxtYellow.setBackground(Color.yellow);
              txtButtons.add(btTxtBlue = new Button());
              btTxtBlue.setBackground(Color.blue);
              txtButtons.add(btTxtOrange = new Button());
              btTxtOrange.setBackground(Color.orange);
              //font buttons
              Panel ftButtons = new Panel();
              ftButtons.setLayout(new GridLayout(4,1));
              ftButtons.add(btFtHel = new Button());
              ftButtons.add(btFtCr = new Button());
              ftButtons.add(btFtTr = new Button());
              ftButtons.add(btFtSy = new Button());
              //layout
              p.add(messagePanel, BorderLayout.CENTER);//set center 1st
              p.add(pButtons, BorderLayout.SOUTH);
              p.add(BgButtons, BorderLayout.NORTH);
              p.add(txtButtons, BorderLayout.EAST);
              p.add(ftButtons, BorderLayout.WEST);
              //listeners
              btLeft.addActionListener(this);
              btRight.addActionListener(this);
              btUp.addActionListener(this);
              btDown.addActionListener(this);
              btBgRed.addActionListener(this);
              btBgYellow.addActionListener(this);
              btBgBlue.addActionListener(this);
              btBgOrange.addActionListener(this);
              btTxtRed.addActionListener(this);
              btTxtYellow.addActionListener(this);
              btTxtBlue.addActionListener(this);
              btTxtOrange.addActionListener(this);
              btFtHel.addActionListener(this);
              btFtCr.addActionListener(this);
              btFtTr.addActionListener(this);
              btFtSy.addActionListener(this);
         //implement listener
         public void actionPerformed(ActionEvent e)
              if(e.getSource() == btLeft)
                   left();
              else if(e.getSource() == btRight)
                   right();
              else if(e.getSource() == btUp)
                   up();
              else if(e.getSource() == btDown)
                   down();
              else if(e.getSource() == btBgRed)
                   red();
              else if(e.getSource() == btBgYellow)
                   yellow();
              else if(e.getSource() == btBgBlue)
                   blue();
              else if(e.getSource() == btBgOrange)
                   orange();
              else if(e.getSource() == btTxtRed)
                   redText();
              else if(e.getSource() == btTxtYellow)
                   yellowText();
              else if(e.getSource() == btTxtBlue)
                   blueText();
              else if(e.getSource() == btTxtOrange)
                   orangeText();
              else if(e.getSource() == btFtHel)
                   helvetica();
              else if(e.getSource() == btFtCr)
                   courier();
              else if(e.getSource() == btFtTr)
                   times();
              else if(e.getSource() == btFtSy)
                   symbol();
         //directional methods :0)
         private void left()
              int x = messagePanel.getXCoordinate();
              if(x > 10)
                   messagePanel.setXCoordinate(x - 10);
                   messagePanel.repaint();
         private void right()
              int x = messagePanel.getXCoordinate();
              if(x < (getSize().width - 5))
                   messagePanel.setXCoordinate(x + 5);
                   messagePanel.repaint();
         private void up()
              int y = messagePanel.getYCoordinate();
              if(y < (getSize().height - 10))
                   messagePanel.setYCoordinate(y - 10);
                   messagePanel.repaint();
         private void down()
              int y = messagePanel.getYCoordinate();
              if(y < (getSize().height + 10))
                   messagePanel.setYCoordinate(y + 10);
                   messagePanel.repaint();
         //background methods :)
         private void red()
              messagePanel.setBackground(Color.red);
         private void yellow()
              messagePanel.setBackground(Color.yellow);
         private void blue()
              messagePanel.setBackground(Color.blue);
         private void orange()
              messagePanel.setBackground(Color.orange);
         //text color methods :)
         private void redText()
              messagePanel.setForeground(Color.red);
         private void yellowText()
              messagePanel.setForeground(Color.yellow);
         private void blueText()
              messagePanel.setForeground(Color.blue);
         private void orangeText()
              messagePanel.setForeground(Color.orange);
         private void helvetica()
              Font myfont = new Font("Helvetica", Font.PLAIN,12);
              messagePanel.setFont(myfont);
         private void courier()
              Font myfont = new Font("Courier", Font.PLAIN,12);
              messagePanel.setFont(myfont);
         private void times()
              Font myfont = new Font("TimesRoman", Font.PLAIN,12);
              messagePanel.setFont(myfont);
         private void symbol()
              Font myfont = new Font("Symbol", Font.PLAIN,12);
              messagePanel.setFont(myfont);

    You add everything to the Panel p but you never add that panel to the applet. What you probably want is to add everything to the applet. An applet is a special kind of panel so you can just change "p" to "this" everywhere in init and remove the declaration of p at the top.

  • Why IE5 could not find applet class but Netscape can ?

    Hi,
    I have an applet which is running fine on Netscripts6,
    But not on IE5.
    <APPLET codebase="http://10.1.1.1/demo/" code="ClientApplet.class" HEIGHT=300 WIDTH=300>
    <PARAM NAME="relay" VALUE="1">
    I have all class files under demo directory(the same directory as html file).
    IE5.0 still could not find applet class but Netscript can.

    are you sure its failing to load your classes or is it failing to load a class you are using?
    Remember IE only uses things from 1.1 so simple things like component.getHeight() does not work you have to use size().height
    Its woth enabling the java console and viewing the exact problem.

  • JMF works in Applet View, but in web browser, cannot find device

    I'm developing an Applet which can capture image from a web camera.
    It's working very well in the applet view, but it says "No devices" error message through web browser.
    How can I make it work? How can I find device on the web browser?
    I changed permission using "java JMFRegistry", and tried signed Jar.
    Anyone can help me?
    or some of samples would be appreciated...

    Applet view means Applet viewer..

  • Applet running in IDE's applet viewer but not within browser

    Hello,
    I have this applet which runs perfectly on JBuilder4's Applet viewer but when I access the HTML file which JBuilder generated as part of the applet creation the applet won't run.
    The parameters in the applet tag in the HTML file are correct, i.e. the code attribute of this tag has as its value the correct class that implements the applet.
    The only io operations associated with the applet are writing/reading objects to the socket's input/output stream, to communicate with a threaded server which has been started before running the applet. It all runs on the local host. So, I'm not sure it should be signed for it to run in the browser, should it?
    I have tried several browsers, and have the latest java plug-in installed.
    Any comments on this?

    Check this link which might be helpful:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=126261

  • Applet works but not through program?

    I am creating an applet. When I compile my program in textmate, I get this error and the code does not run.
    Exception in thread "main" java.lang.NoSuchMethodError: main
    Program exited with status 1.But when I open the html page I created, it runs perfectly! Any ideas as to why this occurs?
    There is an image that goes with this. You can substitute any tiny gif image you like, just change it's name to camel.gif*
         Chapter 6:     Move It
         Filename:     MoveIt.java
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    public class MoveIt extends Applet implements ActionListener
         private Image camel;
         private Panel keyPad;
         private int top = 15;
         private int left = 15;
         private Button keysArray[];
         public void init()
               camel = getImage(getDocumentBase(), "camel.gif");
              Canvas myCanvas = new Canvas();
              keyPad = new Panel();
              Button up = new Button("Up");
              Button left = new Button("Left");
              Button right = new Button("Right");
              Button center = new Button("Center");
              Button down = new Button("Down");
                   setLayout(new BorderLayout());
                   keyPad.setLayout(new BorderLayout());
                   keyPad.add(up, BorderLayout.NORTH);
                   keyPad.add(left, BorderLayout.WEST);
                   keyPad.add(center, BorderLayout.CENTER);
                   keyPad.add(right, BorderLayout.EAST);
                   keyPad.add(down, BorderLayout.SOUTH);
                   add(myCanvas, BorderLayout.NORTH);
                   add(keyPad, BorderLayout.SOUTH);
                   up.addActionListener(this);
                   left.addActionListener(this);
                   center.addActionListener(this);
                   right.addActionListener(this);
                   down.addActionListener(this);
         } //end init
                   public void paint( Graphics g)
                        g.drawImage( camel, left, top, this);
                   public void actionPerformed(ActionEvent e)
                        String arg = e.getActionCommand();
                          if(arg == "Up")
                             top = top - 15;
                             if(arg == "Down")
                                  top = top + 15;
                                  if(arg == "Left")
                                       left = left - 15;
                                       if(arg == "Right")
                                            left = left + 15;
                                            if(arg == "Center")
                                                 top = 60;
                                                 left = 125;
                                                 repaint();
                   } //end actionperformed
    }And the html page is:
    <HTML>
    <APPLET CODE = "MoveIt.class" WIDTH = "325" HEIGHT = "250">
    </APPLET>
    </HTML>

    Oh. I thought that was standard across all editors. At school we use TextPad and it allows you to select the html host document and run the application from the program. I am using TextMate since I am on a mac and figured it would be the same. Thank you.
    One question tho, why does the window not open up to the pixel size I specified in the html host document? Does it do so on your machine? What OS and browser are you running?
    It won't take that size in neither Firefox or Safari on my mac.

  • Applet compiles but doesn't work as intended

    My program intends to add, subtract, multiply or divide two numbers, whereby, if the user enters 'A' the program adds the two numbers, and 'S' to subtract them etc. The program compiles fine but as I am pretty new to Java I'm finding it hard to find my error. Reagrds in advance.
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    import java.lang.*;
    public class CharacterCalculation extends Applet implements ActionListener
         Label input1, input2, input3, output;
         TextField ip1, ip2, ip3, op;
         Double num1, number1, num2, number2, calculationa, calculations, calculationm, calculationd;
         String characterentered;
         public void init()
              setSize(280,180);
              input1 = new Label ("Enter first number here:");
              ip1 = new TextField(5);
              add(input1);
              add(ip1);
              ip1.addActionListener(this);
              number1=0.0;
              input2 = new Label ("Enter mathematical operator here:");
              ip2 = new TextField(5);
              add(input2);
              add(ip2);
              input3 = new Label ("Enter second number here:");
              ip3 = new TextField(5);
              add(input3);
              add(ip3);
              ip3.addActionListener(this);
              number2=0.0;
              output = new Label("The answer is:");
              op = new TextField(32);
              add(output);
              add(op);
              op.setEditable(false);
         public void paint (Graphics graf)
              graf.drawString("A = Add S = Subtract D = Divide M = Multiply",20,160);
         public void actionPerformed(ActionEvent ev)
              num1=Double.parseDouble(ip1.getText());
              num2=Double.parseDouble(ip3.getText());
              characterentered=(ip2.getText());
              calculationa=(num1+num2);
              calculations=(num1-num2);
              calculationm=(num1*num2);
              calculationd=(num1/num2);
              if (characterentered == "A")
                   op.setText(Double.toString(calculationa));
              if (characterentered == "S")
                   op.setText(Double.toString(calculations));
              if (characterentered == "M")
                   op.setText(Double.toString(calculationm));
              if (characterentered == "D")
                   op.setText(Double.toString(calculationd));
              else
                   op.setText("Please enter a valid mathematical operator");
    }

    if (characterentered == "A")This is never going to work. A String is an object. What the above line does is compare the reference of characterentered to the reference of the object "A", which will never be the same (they are two different objects stored in two different memory locations).
    If you want to compare two strings you need to use the equals() method, so change to four comparison lines to:
    if(characterentered.equals("A")){
    }

  • Java applet load but no way to enter credential

    Hello, I have all software up to date, and also last java version, seems that the applet start and load, but no way to enter credential, somebody can help? Do I use the java imbedded in safari or the last I download?
    Works well with Firefox.
    Thanks
    Pfoke

    Hello Pfoke,
    Welcome to the Apple Support Communities. If you have the latest update for Java and you are still having issues with the Java applets working properly, you can re-enable Java SE 6. The following article will walk you through this process. Do not forget to restart your computer after you do this.
    Java for OS X 2013-002: How to re-enable the Apple-provided Java SE 6 web plug-in and Web Start functionality.
    http://support.apple.com/kb/HT5559
    Regards,
    -Norm G.

  • Works in applet viewer but not in internet explorer

    I origionaly posted this on devshed. I got 55 views but no replies. It seems to be a common problem to which no one knows the answer. Surprise me :O)I'm sure this is a really common but there seems to be surprisinly litttle on the web about it.
    I developed a game applet a while ago in applet viewer and am now thinking about putting it on my web site. However I have found that it doesn't work in internet explorer. I can browse other sites using Java fine. There is clearly just something about my applet that ie doesn't like.
    Does anyone have any suggestions? What sort of things upset ie?
    All help very much apreciated, you are very nice people
    Flo.

    There must be some thing that tells you it isn't working. You should tell us so we don't have to guess. Does the browser hang? Do you get an error? Did you try opening the Java Console to see if there were any messages? I am guessing that your code is using something that the security level of an Applet does not allow (but appletviewer does allow).

  • Applet works on applet viewer but not in html, why not?

    I'm using Eclipse as a development system and the Eclipse applet viewer shows my applets with no problem. They work the way I expect them to work and all is well.
    When I try to run them in Internet Explorer, I first get a security warning. OK, I trust myself, so I tell Internet Explorer to run the applet. All I get is the text "Hello Dolly", but the applet doesn't run.
    I tried refreshing it, running it again, allowing popups and opening the file, but it just won't run. What could be wrong with something so trivial?
    Any suggestions would be appreciated.
    <html>
    <head>
    <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Hello to Everyone</title>
    </head>
    <body>
    <applet CODE="Hello.class" width=300 height=100>Hello Dolly
    </applet>
    </body>
    </html>

    Sorry, I didn't think there was anything special in the applet.
    This just happens to be what I'm checking at the moment.
    It has changed depending upon where in the tutorial I find myself.
    Thanks for you help.
    It has to be something really stupid that I'm missing, but since I'm still new at this game, I can miss something obvious to everyone else.
    package hello;
    import java.applet.Applet;
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.util.Date;
    public class Hello extends Applet implements Runnable {
         private static final long serialVersionUID = 1L;
         Color colors[] = new Color[50];
         Date date1 = null;
         Thread run1 = null;
         Font f1 = new Font("Ariel", Font.PLAIN, 14);
         public void run() {
              int i = 0;
              Thread currThread = Thread.currentThread();
              while (currThread == run1) {
                   setForeground(colors);
                   repaint();
                   i++;
                   if( i>= colors.length) i = 0;
                   try { Thread.sleep(50); }
                   catch (InterruptedException e) {}
         public void init() {
              int i;
              float c = 0.0f;
              for(i=0; i<colors.length; i++) {
                   colors[i] = Color.getHSBColor(c, 1.0f, 1.0f);
                   c += 0.2f;
         public void start() {
              if (run1 == null) {
                   run1 = new Thread(this);
                   run1.start();
         public void stop() {
              run1 = null;
         public void paint(Graphics g){
              date1 = new Date();
              g.setFont(f1);
              g.drawString(date1.toString(), 10, 50);

  • Applet works in applet viewer but not browser...why?

    I won't go into the code, but here's my problem: I work on my applet using Eclipse and its appletviewer, and the applet works fine. I test my applet once in a while by packing all class files and graphics into a jar file, copying it and html file to my desktop and opening the html file. Before, this would work (the applet would get all its info from the jar file), but now... I get a nullpointer exception when I open the browser. If this were to happen in Eclipse, I'd have some way of tracking it. Is there some way of tracking this problem when its seen in a browser?

    here's certain key parts of my code... I think this whole "applet not working outside of the project folder" thing started ever since I changed my init() and start() functions so...
         public void init()
              t = new Thread(this);
              t.start();
              addKeyListener(this);
              addMouseListener(this);
              addMouseMotionListener(this);
              sound = new SoundList(); 
         public void start()
              URL resdir;     
              resdir = getClass().getResource("Graphics/Spacebackdrop_01.jpg");
              backgrndImg = new ImageIcon(resdir);
                   resdir = getClass().getResource("Graphics/Ship_Blue.gif");
              player1 = new Ship(100, 300, new ImageIcon(resdir), this,
                        gameRect, sound);
              player1.setOrientation(90);
              resdir = getClass().getResource("Graphics/Ship_Green.png");
              player2 = new Ship(700, 300, new ImageIcon(resdir), this,
                        gameRect, sound);
              player2.setOrientation(270);
              resdir = getClass().getResource("Graphics/Ball.gif");
              ball = new Ball(50, 50, new ImageIcon(resdir), this,
                          gameRect, sound);
              initMenus();
              //Initialize the goals
              resdir = getClass().getResource("Graphics/Goalpost.png");
              ImageIcon goalImg = new ImageIcon(resdir);
              goal1 = new Goal(8, gameRect.height/2, 100, goalImg, this);
              goal2 = new Goal(gameRect.width - 8, gameRect.height/2, 100, goalImg, this);
              font = new Font("Verdana", Font.BOLD, 16);
         public void initMenus()
              startMenu = new Menu();
              pauseMenu = new Menu();     
              confirmMenu = new Menu();
              int setY = 200;
              ImageIcon img = new ImageIcon(getClass().getResource("Graphics/newgame.png"));
              ImageIcon imgRoll = new ImageIcon(getClass().getResource("Graphics/newgame_h.png"));
              ImageIcon imgPressed = new ImageIcon(getClass().getResource("Graphics/newgame_p.png"));
              startMenu.addCenteredButton(img, imgRoll, imgPressed, setY, 0, gameRect.width);
              pauseMenu.addCenteredButton(img, imgRoll, imgPressed, setY, 0, gameRect.width);
              setY += 20;
              img = new ImageIcon(getClass().getResource("Graphics/resumegame.png"));
              imgRoll = new ImageIcon(getClass().getResource("Graphics/resumegame_h.png"));
              imgPressed = new ImageIcon(getClass().getResource("Graphics/resumegame_p.png"));
              pauseMenu.addCenteredButton(img, imgRoll, imgPressed, setY, 0, gameRect.width);
              img = new ImageIcon(getClass().getResource("Graphics/Yes.png"));
              imgRoll = new ImageIcon(getClass().getResource("Graphics/Yes_h.png"));
              imgPressed = new ImageIcon(getClass().getResource("Graphics/Yes_p.png"));
              setY += 25;
              int imgWidth = img.getIconWidth();
              confirmMenu.addButton(img, imgRoll, imgPressed, gameRect.width/2 - imgWidth, setY);
              //startMenu.activate(); //make starmenu active.
              img = new ImageIcon(getClass().getResource("Graphics/No.png"));
              imgRoll = new ImageIcon(getClass().getResource("Graphics/No_h.png"));
              imgPressed = new ImageIcon(getClass().getResource("Graphics/No_p.png"));
              confirmMenu.addButton(img, imgRoll, imgPressed, gameRect.width/2 + 2, setY);
         }

  • Any idea why the applets starts but nothing works?

    I am 1 month old. Here is small training program that I am trying. Any idea why the applet is running but nothing works?
    thanks
    package javaapplication1;
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.event.*;
    import javax.swing.*;
    public class MoneyCollect extends JApplet implements ActionListener {
    private JLabel promt;
    private JTextField input;
    private int total;
        public void main(String [] args){
            Container c = getContentPane();
            c.setLayout( new FlowLayout() );
            promt = new JLabel ("Enter number of hours");
            input = new JTextField (10);
            input.addActionListener(this);
            c.add(promt);
            c.add(input);
        public int calculateCharges(int hrs){
            if ( (hrs>=0) && (hrs<=3) && (hrs != 24) ){
            total = 2*hrs;   
            if((hrs>=3)&& (hrs<24) && (hrs != 24)){
            total = (int) (((hrs - 3) * 0.50) + 6);
            if (hrs == 24){
                total = 10;
            return total;
        public void actionPerformed(ActionEvent e) {
            int hrs = Integer.parseInt(e.getActionCommand());
            showStatus ("You have to pay:"+calculateCharges(hrs));
    }

    ...because changing this:
    public class MoneyCollect extends JFrameto this:
    public class MoneyCollect extends JAppletdoes not create an applet. Get a beginning java book and start reading it. I recommend "Java2: A Beginner's Guide".
    Or, you can read the following tutorial to learn why your program is not an applet:
    [http://java.sun.com/docs/books/tutorial/deployment/applet/getStarted.html]

Maybe you are looking for

  • Can 2 users have the same email login with different passwords for seperate itunes accounts

    My daughter is currently using the home email address for her account and i have just purchased an ipad. I would like a seperate account. Is it possible to use the same email address as the login and have two accounts. Thanks Tracey (a mum who is try

  • Return key does not work in address bar after updating to Firefox 10

    I just updated to Firefox 10. The return key will no longer work in the address bar. I have to manually click on the "go to" arrow. Are there any fixes for this? Thanks!

  • Change button is not appearing in the SC after SP Application

    Hi SRM Gurus, Change button is not appearing in SC check status after Higher SP Applicaation implementation. Can any body tell what will be the reason and solution.. Thanks in advance CK Edited by: CK on May 13, 2009 6:30 AM

  • AA 7.0 unable to "Create PDF From Scanner..."

    I am unable to use Adobe Acrobat 7.0 to scan from my Lexmark X9575 multifunction scanner. The scanner shows up in the drop down; however, when i go to scan it says "the selected scanner was not found". HELP please :)

  • Read xml nodes

    Hello to everyone. I 'm trying to build an rss reader in PLSQL. I'm confused and i want your help. I used dbms_xmlparser to parse an xml and read its nodes but I have a problem with the character set (xml is iso-8859-7 but i cannot read it). So, i th