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

  • Home
  • SEARCH
  • 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 9257347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:09:12+00:00 2026-06-18T12:09:12+00:00

So I am faced with a situation that I have been stuck with for

  • 0

So I am faced with a situation that I have been stuck with for an hour.

Here’s my situation: I want to add an image that says “Life:” separate from my game canvas very much like this game Legend of Zelda for the NES.

Example

Problem is: my code still only shows my game canvas.

public class Game extends Canvas {

           private Game(){

           JFrame container = new JFrame("Arcade Shooter Clone");

            panel = (JPanel)container.getContentPane();
            panel.setLayout(new BorderLayout());

            panel.add(this,BorderLayout.CENTER);

            ShipLifeTitle shipLifeTitle = new ShipLifeTitle();
            panel.add(shipLifeTitle,BorderLayout.SOUTH);
           }

    }

    public class ShipLifeTitle extends Sprite {

        private Image image;

        public ShipLifeTitle()
        {
            try
            {
                image = ImageIO.read(new File("src/Ship/shipLifeTitle.PNG"));


            }
            catch(IOException e)
            {
                e.printStackTrace();
            }

        }

        @Override
        public void draw(Graphics g) {
            // TODO Auto-generated method stub
            g.drawImage(image, 200, 200, null);
        }


    }

    public class Sprite extends Component implements GameComponent {

        public Vector2D position;
        public Vector2D velocity;

        @Override
        public void update(long milliseconds) {
            // TODO Auto-generated method stub

        }

        @Override
        public void draw(Graphics g) {
            // TODO Auto-generated method stub

        }



    }
  • 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-18T12:09:13+00:00Added an answer on June 18, 2026 at 12:09 pm

    In you ShipLifeTitle panel, you need to override its getPreferredSize method.

    public class ShipLifeTitle extends Sprite {
        //...
        public Dimension getPreferredSize() {
            return new Dimension(image.getWidth(null), image.getHeight(null));
        }
    }
    

    This will give BorderLayout some hints as to how you want the panel to be laied out

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

Sidebar

Related Questions

On several occations, I have faced the situation that the default.aspx page on a
I have a simple situation here. lets face html code first => <form name=geoKey
I have faced a problem when using PLY. I want to create a call
I currently face a strange situation, and I have no explanation for it. Here
I am facing a situation in which I want to ensure that if a
There is a situation that I am faced with which seems like it has
I'm faced with a situation where I have two tables: A and B. B
I have written a WPF application that I want to port to Silverlight 2.
I'm faced with a situation that I think can only be solved by using
Good day all, I have a preset situation that can't be changed, that revolves

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.