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

    Default Why Does The PNG Image Not Show in The Applet??

    The PNG Image is already in the src package thingie...
    It's a 400 * 258 image...
    Java Code:
    package frame;
    import java.awt.*;
    import java.applet.Applet;
    import java.awt.event.*;
    
    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() {
    	temp = getImage(getCodeBase(),"temperature-variation.PNG");
    	bar = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, 100);
        bar.addAdjustmentListener(this);
        setLayout(new BorderLayout());  
        add("South", bar);
      } 
    public void paint(Graphics g) {
    	 if (temp!=null){
    	        g.drawImage(temp, 40, 40, null);
    	 }
    	g.setColor(Color.RED);
    	g.drawString("Celsius = " + newtemp, 600, 200);
    	g.setColor(Color.BLUE);
    	g.drawString("Fahrenheit = " + fahr, 600, 220);a
      }
      public void adjustmentValueChanged(AdjustmentEvent e) {
        newtemp = bar.getValue();
        if (newtemp != old) {
          fahr = newtemp * (9/5) + 32;
          old = newtemp;
          repaint();
        }     
      }
      }
    Plz Help As quickly as Possible
    GODLIKE!!!!

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

    Default Re: Why Does The PNG Image Not Show in The Applet??

    The Image is the temp Image
    GODLIKE!!!!

  3. #3
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    843
    Rep Power
    6

    Default Re: Why Does The PNG Image Not Show in The Applet??

    ur code is perfectly right.have just put s.o.p for getCodeBase()
    Ramya:cool:

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Why Does The PNG Image Not Show in The Applet??

    'temp' is probably null, implying that the file is not where you think it should be in the deployed code.
    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: Why Does The PNG Image Not Show in The Applet??

    But, the temp file is in the bin of my Java Project, exactly like the textbook I use says.
    But, when I run it, it doesn't show the picture, just a blank area.
    GODLIKE!!!!

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

    Default Re: Why Does The PNG Image Not Show in The Applet??

    But, the temp file is in the bin of my Java Project, exactly like the textbook I use says.
    But, when I run it, it doesn't show the picture, just a blank area.
    GODLIKE!!!!

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Why Does The PNG Image Not Show in The Applet??

    As Ramya suggests, print out the value from getCodeBase() and check it points to the directory containing that image.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

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

    Default Re: Why Does The PNG Image Not Show in The Applet??

    Wait, it does contain it though
    GODLIKE!!!!

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

    Default Re: Why Does The PNG Image Not Show in The Applet??

    I did like she asked, CodeBase: /C:/Users/Samuel/workspace/The_Ultimate_Project_ASIT/bin/
    GODLIKE!!!!

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

    Default Re: Why Does The PNG Image Not Show in The Applet??

    The image is there, and I imported it into the package my applet is in, yet it shows up blank
    GODLIKE!!!!

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

    Default Re: Why Does The PNG Image Not Show in The Applet??

    I also tried changing getCodeBase() to getDocumentBase(), both don't work.

    Here's the current code up to date:
    Java Code:
    package frame;
    import java.awt.*;
    import java.applet.Applet;
    import java.awt.event.*;
    
    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() {
    	  System.out.println("I have the code base:::::::"+getCodeBase());
    	temp = getImage(getDocumentBase(),"C:\\Users\\Samuel\\workspace\\The_Ultimate_Project_ASIT\\bin\\themometer-fire-ice.png");
    	bar = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, 100);
        bar.addAdjustmentListener(this);
        setLayout(new BorderLayout());  
        add("South", bar);
      } 
    public void paint(Graphics g) {
    	 if (temp!=null){
    	        g.drawImage(temp, 400, 417, null);
    	 }
    	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!!!!

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Why Does The PNG Image Not Show in The Applet??

    "I imported it into the package my applet is in"

    What does that mean?

    Also
    Java Code:
    getImage(getDocumentBase(),"C:\\Users\\Samuel\\workspace\\The_Ultimate_Project_ASIT\\bin\\themometer-fire-ice.png");
    this isn't the correct usage.
    You were right in the original code, with just the file name.

    OK, so the next thing is to check whether the image is null.
    So stick some debugging in to check that.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  13. #13
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,025
    Rep Power
    6

    Default Re: Why Does The PNG Image Not Show in The Applet??

    First, reverse the order of your add method. It should be add(bar, "South"). It will work the other way but it is obsolete.
    Second, replace the null value of your imageObserver with this. And print out the image variable to ensure it is not null.
    Then your image should appear. Also, you may want to change newtemp to celcius and initialize fahr to 32.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

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

    Default Re: Why Does The PNG Image Not Show in The Applet??

    THX SO MUCH!!!!


    GODLIKE!!!!

Similar Threads

  1. Why doesn't this image show in the frame?
    By Astralogic in forum New To Java
    Replies: 4
    Last Post: 08-27-2012, 04:25 PM
  2. How to show image on images
    By johny2011 in forum AWT / Swing
    Replies: 5
    Last Post: 05-19-2011, 02:51 PM
  3. JMenuItem - image won't show
    By javawriter in forum AWT / Swing
    Replies: 10
    Last Post: 07-13-2010, 07:11 PM
  4. show image that I refresh
    By erwillie in forum New To Java
    Replies: 1
    Last Post: 04-29-2010, 04:23 PM
  5. Replies: 0
    Last Post: 03-20-2010, 12: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
  •