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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:17:10+00:00 2026-05-17T17:17:10+00:00

I have an applet where I am drawing stuff by overriding the paint() method,

  • 0

I have an applet where I am drawing stuff by overriding the paint() method, and have added a Canvas to the applet, which will take up the whole screen. This canvas seems to be being drawn after my paint()ing, and so my applet’s paint()ed stuff is invisible. Any ideas on how to force the canvas to be drawn before my paint method on my applet?

Edit:

public void paint(Graphics g) {
    super.paint(g);
    if (DEBUG) {
        g.setColor(Color.red);
        g.drawString("Memory free: " + ((Runtime.getRuntime().freeMemory()
            / 1024) / 1024) + "MB", 5, 20);
        g.drawString("Memory total: " + ((Runtime.getRuntime().totalMemory()
            / 1024) / 1024) + "MB", 5, 35);
        g.drawString("Memory used: " + (((Runtime.getRuntime().totalMemory()
            - Runtime.getRuntime().freeMemory()) / 1024) / 1024) + "MB", 5, 50);
    }
}
  • 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-05-17T17:17:10+00:00Added an answer on May 17, 2026 at 5:17 pm

    Even if you must use AWT, you should be able to use a separate Panel for the GL content and the memory status:

    import java.awt.*;
    import java.awt.event.*;
    
    public class AWTPaintTest {
    
        public static void main(String[] args) {
            Frame frame = new Frame();
            // frame.add(new AWTGLCanvas(), BorderLayout.CENTER);
            frame.add(new MemoryPanel(), BorderLayout.SOUTH);
            frame.addWindowListener(new WindowAdapter() {
    
                @Override
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
                }
            });
            frame.pack();
            frame.setVisible(true);
        }
    
        private static class MemoryPanel extends Panel {
    
            private final Runtime r = Runtime.getRuntime();
    
            public MemoryPanel() {
                this.setPreferredSize(new Dimension(240, 120));
                this.setForeground(Color.blue);
                this.setFont(new Font("Monospaced", Font.BOLD, 16));
                this.addMouseListener(new MouseAdapter() {
    
                    @Override
                    public void mousePressed(MouseEvent e) {
                        r.gc();
                        MemoryPanel.this.repaint();
                    }
                });
            }
    
            @Override
            public void paint(Graphics g) {
                super.paint(g);
                long m = r.maxMemory();
                long t = r.totalMemory();
                long f = r.freeMemory();
                int y = g.getFontMetrics().getHeight() + 4;
                g.drawString("Memory max:   " + toMB(m), 5, 1 * y);
                g.drawString("Memory total: " + toMB(t), 5, 2 * y);
                g.drawString("Memory free:  " + toMB(f), 5, 3 * y);
                g.drawString("Memory used:  " + toMB(t - f), 5, 4 * y);
                g.drawString("Click to update.", 5, 5 * y);
            }
    
            private String toMB(long bytes) {
                return (bytes / 1024) / 1024 + " MB";
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an applet which runs in a browser and is called from Javascript.
I have an applet. In this I have a JLabel component. When the user
I have an applet that throws this exception when trying to communicate with the
We have a Java Applet built using AWT. This applet lets you select pictures
Normally an applet will call different methods that will have a Graphics2D-object that ends
I have an applet which have to read a file from server. But I
I have an applet which repaints itself once the text has changed Design 1:
I have a problem with drawing a polygon in Java applet. I don't understand
I have an applet, which I was writing in Java. Recently, I thought that
I have an applet which contains some images, regular java classes and class, which

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.