Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8288531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:18:04+00:00 2026-06-08T12:18:04+00:00

i wrote this code for showing some simple picture on the applet screen, but

  • 0

i wrote this code for showing some simple picture on the applet screen, but the picture doesnt show untill i resize the applet window, what can i do to overcome it?

public class Test extends JApplet {
    public void init () {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createGUI();
            }
        });
    }
    public void start() {
    }
    public void createGUI() {
        getContentPane().add(new GUIThing(getImage(getCodeBase(), "gladiator.gif")));
    }
}

public class GUIThing extends JPanel {
    Image image;
    public GUIThing(Image i2) {
        image=i2;
    }
    public void paintComponent(Graphics g) {
        Graphics2D g2=(Graphics2D) g;
        g2.drawImage(image,100,100,100, 100, null);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:18:05+00:00Added an answer on June 8, 2026 at 12:18 pm

    Try passing the applet context to the drawImage method, this allows the appet to be notified when the image is loaded and it will repaint itself

    g2.drawImage(image,100,100,100, 100, this);
    

    And, if you’re really desperate, call invalidate() repaint() in the start method

    UPDATE WITH EXAMPLE

    This is the code that I used. I had no issue with loading the image:

    public class TestApplet extends JApplet {
    
        public void init() {
    
            System.out.println("Init..." + EventQueue.isDispatchThread());
    
            EventQueue.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    createGUI();
                }
            });
    
        }
    
        public void start() {
    
            System.out.println("Start..." + EventQueue.isDispatchThread());
    
        }
    
        public void createGUI() {
    
            URL documentBase = getDocumentBase();
    
            System.out.println(documentBase);
            System.out.println(getCodeBase());
    
    //        file:.../build/TestApplet.html
    //        file:.../build/classes/        
            Image image = getImage(documentBase, "MT-vol-6-STOP-image-Kogumiko-megatokyo-11434773-1559-1852.jpg");
    
            System.out.println("image = " + image);
    
            getContentPane().add(new GUIThing(image));
        }
    
        public class GUIThing extends JPanel {
    
            Image image;
    
            public GUIThing(Image i2) {
                image = i2;
            }
    
            public void paintComponent(Graphics g) {
    
                super.paintComponent(g);
    
                Graphics2D g2 = (Graphics2D) g;
                g2.drawImage(image, 0, 0, this);
    
                g2.setColor(Color.RED);
                g2.drawLine(0, 0, getWidth(), getHeight());
    
            }
        }
    
    }
    

    Wow, it’s been a long time since I played with applets. I changed your code from using the code base to the document base it seems to have worked. I was loading an image of 1559×1852 pixels with little to no delay (locally)

    Double check your applet tag in you HTML file as well. I was using

    <APPLET codebase="classes" code="stack/TestApplet.class" width=350 height=200></APPLET>
    

    Through the applet viewer. Note the code base is different from the document base!!

    My image was in the same location as the HTML file

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My brother wrote this code for me to show an example of polymorhism. But
I wrote this code for zoom in/out . it works but even with one
I wrote this code. The constructor works normally, but in the destructor I get
Im new to ruby, wrote this code and works but i know is not
I wrote this code for zoom in / out and it suppesed to only
I wrote this code to create a custom annotation image - (MKAnnotationView *)mapView:(MKMapView *)mapView
I wrote this code in C# to encrypt a string with a key: private
I wrote this code that compiles on Solaris gcc it works fine too for
I wrote this code in my viewDidLoad function in my iOS project. lettersLeftLabel.text =
I wrote this code: ScheduledExecutorService ExtractorTimer=Executors.newScheduledThreadPool(1); final ScheduledFuture<?> SchedulerHandle; SchedulerHandle =ExtractorTimer.scheduleWithFixedDelay( new Runnable() {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.