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 8915759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:02:50+00:00 2026-06-15T05:02:50+00:00

Edit: uses awt… I am trying to display random numbers in an applet based

  • 0

Edit: uses awt…

I am trying to display random numbers in an applet based maths game, and have run into an issue. Either one of two things happen depending on where I call the method:

  • The numbers generate and display properly, without automatically updating each frame but get drawn over by the background and artwork each frame as they’re being updated at runtime, or…
  • The number displayed on-screen appear above the background elements but are redrawn fresh every frame.

Quick illustration:

private int setNumberOne() {

    return rand.nextInt(11) + 2;
}

private int setNumberTwo() {

    return rand.nextInt(11) + 2;
}

private int setAnswer() {

    return setNumberTwo() * setNumberOne();
}

private void displayOutput() {

    Graphics2D g2d = graphics();

    int one = setNumberOne();
    int ans = setAnswer();

    setNumberTwo();

    g2d.setColor(Color.WHITE);
    g2d.drawString(one + " x ? = " + ans, 480, 480);
}

Calling this function in the initialisation method displays a static question that I can update elsewhere when specific triggers are met, however everything else gets drawn on top of it by the update event, rendering it invisible. The only way I’ve managed to see this working is to remove the other images from the game for testing.

Is there a way to set the “precedence” of GUI elements in an applet?

I’m currently looking at attempting to include the displayOutput() method in it’s own thread, but I’m not so experienced with Java and its proving very hard to resolve.

I also tried to not allow the background to update at runtime, but the result was that the moving game objects left trails all over the screen.

What am I missing? If anyone has any suggestions as to how this can be correctly implemented, I’d be delighted to hear them.

update: “…draw in a […] Component’s paint(…) method if AWT, and use the Graphics object passed in by the JVM” –

Resolved, Thank you!

  • 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-15T05:02:52+00:00Added an answer on June 15, 2026 at 5:02 am

    Don’t use getGraphics() for your Graphics component as this will return a non-persisting object that will get drawn over with the next repaint. Instead draw in a JComponent’s paintComponent(...) method if this is a Swing app (you don’t say) or a Component’s paint(...) method if AWT, and use the Graphics object passed in by the JVM. Mostly read the tutorials on how to draw with Java as this has been well explained there.

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

Sidebar

Related Questions

I have a Java Applet that uses AWT. In some (rare) circumstances, the platform
I have an application that uses MSWord automation to edit some documents, after they
I have an edit form that uses an ajax form to submit to the
I have an application which uses JTables to display data, and the cells are
I have an application that displays, edits and deletes Accounts. Display uses displayAccounts.jsp and
I have DataGridViewColumn that uses a DateTimePicker control in order to edit cell values.
I'm currently trying to edit a website for a client which uses Adobe Contribute
I have an mode that uses TComboBox.SelStart to indicate progress along the edit text
I have an edit-form page to edit my website posts. It uses post method
EDIT: See my answer below--> I am wanting to have a view that when

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.