Results 1 to 10 of 10
  1. #1
    Ark3 is offline Member
    Join Date
    Jun 2014
    Posts
    59
    Rep Power
    0

    Question Applet Doesn't Run Complete in HTML File...

    I compiled the applet, then put the applet in an HTML file using notepad and saved the html file in the right place
    for it to run correctly. The HTML file runs smoothly, but then it only shows the scrollbar part of my applet, and not the images
    or any text...
    Why is This?????

    Java Code:
    import java.awt.*;
    import java.applet.Applet;
    import java.awt.event.*;
    
    import javax.swing.ImageIcon;
    
    public class Temperature_Convert extends Applet 
    		     implements AdjustmentListener {
      private Image temp;
      private Scrollbar bar;
      private int old, newtemp = 0;
      private double fahr = 33.8;
      public void init() {
    	repaint();
    	bar = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, 100);
        bar.addAdjustmentListener(this);
        setLayout(new BorderLayout());  
        add(bar, "South");
      } 
    public void paint(Graphics g) {
        super.paint(g);
        ImageIcon temp5 = new ImageIcon("un.gif");
        g.drawImage(temp5.getImage(),  0, 200, this);
        ImageIcon temp4 = new ImageIcon("un2.gif");
        g.drawImage(temp4.getImage(),  950, 200, this);
        ImageIcon temp3 = new ImageIcon("thermometer-fire-ice.png");
        g.drawImage(temp3.getImage(),  450, 200, this);
    	g.setColor(Color.RED);
    	g.drawString("Celsius = " + newtemp, 600, 200);
    	g.setColor(Color.BLUE);
    	g.drawString("Fahrenheit = " + fahr, 600, 220);
      }
      public void adjustmentValueChanged(AdjustmentEvent e) {
        newtemp = bar.getValue();
        if (newtemp != old) {
          fahr = newtemp * (9/5) + 32;
          old = newtemp;
          repaint();
        }
    GODLIKE!!!!

  2. #2
    Ark3 is offline Member
    Join Date
    Jun 2014
    Posts
    59
    Rep Power
    0

    Default Re: Applet Doesn't Run Complete in HTML File...

    Updated Code:
    Java Code:
    import java.awt.*;
    import java.applet.Applet;
    import java.awt.event.*;
    
    import javax.swing.ImageIcon;
    
    public class Temperature_Convert extends Applet 
    		     implements AdjustmentListener {
      private Scrollbar bar;
      private int old, newtemp = 0;
      private double fahr = 33.8;
      public void init() {
    	repaint();
    	bar = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, 100);
        bar.addAdjustmentListener(this);
        setLayout(new BorderLayout());  
        add(bar, "South");
      } 
    public void paint(Graphics g) {
        super.paint(g);
        ImageIcon temp3 = new ImageIcon("un.gif");
        g.drawImage(temp3.getImage(),  0, 200, this);
        ImageIcon temp2 = new ImageIcon("un2.gif");
        g.drawImage(temp2.getImage(),  950, 200, this);
        ImageIcon temp = new ImageIcon("thermometer-fire-ice.png");
        g.drawImage(temp.getImage(),  450, 200, this);
    	g.setColor(Color.RED);
    	g.drawString("Celsius = " + newtemp, 600, 200);
    	g.setColor(Color.BLUE);
    	g.drawString("Fahrenheit = " + fahr, 600, 220);
      }
      public void adjustmentValueChanged(AdjustmentEvent e) {
        newtemp = bar.getValue();
        if (newtemp != old) {
          fahr = newtemp * (9/5) + 32;
          old = newtemp;
          repaint();
        }     
      }
    }
    GODLIKE!!!!

  3. #3
    Ark3 is offline Member
    Join Date
    Jun 2014
    Posts
    59
    Rep Power
    0

    Default Re: Applet Doesn't Run Complete in HTML File...

    This is the HTML SCRIPT:
    Java Code:
    <HTML>
    <BODY>
    	<APPLET code="Temperature_Convert" width=1500 height=1000></APPLET>
    </BODY>
    <HTML>
    GODLIKE!!!!

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,050
    Rep Power
    20

    Default Re: Applet Doesn't Run Complete in HTML File...

    Maybe the images haven't loaded for some reason.
    The ImageIcon class has some methods for checking this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Ark3 is offline Member
    Join Date
    Jun 2014
    Posts
    59
    Rep Power
    0

    Default Re: Applet Doesn't Run Complete in HTML File...

    But, the images are in the same folder as the html file and the applet!!
    GODLIKE!!!!

  6. #6
    Ark3 is offline Member
    Join Date
    Jun 2014
    Posts
    59
    Rep Power
    0

    Default Re: Applet Doesn't Run Complete in HTML File...

    Could you tell me what are the methods, I'm only been programming and learning for 2 months
    GODLIKE!!!!

  7. #7
    Ark3 is offline Member
    Join Date
    Jun 2014
    Posts
    59
    Rep Power
    0

    Default Re: Applet Doesn't Run Complete in HTML File...

    Wait, TOLLS, the text doesn't show either, like the temperature and celsius (old, fahr, newtemp)
    GODLIKE!!!!

  8. #8
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,050
    Rep Power
    20

    Default Re: Applet Doesn't Run Complete in HTML File...

    Here's the API for ImageIcon.
    And here's a method for determining the status of the icon.

    If nothing's being painted then look into the console to see if any errors are being thrown.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    Ark3 is offline Member
    Join Date
    Jun 2014
    Posts
    59
    Rep Power
    0

    Default Re: Applet Doesn't Run Complete in HTML File...

    Tolls, How do I use the methods, I don't understand....
    The image isn't null, that's all I know.
    GODLIKE!!!!

  10. #10
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,050
    Rep Power
    20

    Default Re: Applet Doesn't Run Complete in HTML File...

    Use the method I pointed to.
    ImageIcon will not be null, as it's just a wrapper around the actual image. You can check whether the image itself is null using one of the other methods of ImageIcon.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 1
    Last Post: 10-15-2011, 03:48 AM
  2. Jar file not complete
    By desoky725 in forum NetBeans
    Replies: 6
    Last Post: 09-23-2011, 07:33 AM
  3. First signed applet, doesn't even run :\
    By menzow in forum Java Applets
    Replies: 2
    Last Post: 02-21-2011, 11:19 AM
  4. jTextPane doesn't show HTML
    By indra-uolles in forum AWT / Swing
    Replies: 5
    Last Post: 08-31-2010, 02:29 PM
  5. Opening applet with .html file
    By Atriamax in forum New To Java
    Replies: 12
    Last Post: 09-13-2009, 06:26 AM

Posting Permissions

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