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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:20:50+00:00 2026-06-14T01:20:50+00:00

I’m currently trying to create a gui for a game that I am making

  • 0

I’m currently trying to create a gui for a game that I am making and I’m beginning to run into some trouble. I can’t for some reason get the background of the timer to change to blue and the background of the gameGUI to be green for the main board. This is my first time programming in swing so I’m new to all of this.

I also am wondering if I am going about the layeredpane usage the right way. The board needs to be able to be a layered pane so that I can put images over top of it all the time. The timer will be a sky with a sun on top, and clouds will go over top of it at some point also.

If you could give me tips and help me out along the way that would be great even if you just correct a few little things here and there.

Thank you.

public class gameGUI extends JPanel{

    private ArrayList<BufferedImage> nativeOne = new ArrayList<BufferedImage>();
    private ArrayList<BufferedImage> nativeTwo = new ArrayList<BufferedImage>();
    private ArrayList<BufferedImage> nativeThree = new ArrayList<BufferedImage>();
    private ArrayList<BufferedImage> exoticOne = new ArrayList<BufferedImage>();
    private ArrayList<BufferedImage> exoticTwo = new ArrayList<BufferedImage>();
    private ArrayList<BufferedImage> exoticThree = new ArrayList<BufferedImage>();

    private static int screenWidth = 680;
    private static int screenHeight = 680;

    private JLayeredPane layeredPane;

    public gameGUI(){        
        layeredPane = new JLayeredPane();
        layeredPane.setPreferredSize(new Dimension(680, 680));
        layeredPane.setBackground(Color.GREEN);
        layeredPane.setBorder(BorderFactory.createLineBorder(Color.BLACK,2));        
    }

    private static JLayeredPane timer(){
        JLayeredPane timer = new JLayeredPane();
        timer.setPreferredSize(new Dimension(800,120));
        timer.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
        timer.setBackground(Color.BLUE);
        return timer;
    }

    private static JPanel sideBar(){
        //Create the side bar and add buttons
        JPanel returnMofo = new JPanel();
        JButton nativeOne = new JButton(native1);
        JButton nativeTwo = new JButton(native2);
        JButton nativeThree = new JButton(native3);
        JButton exoticOne = new JButton(exotic1);
        JButton exoticTwo = new JButton(exotic2);
        JButton exoticThree = new JButton(exotic3);
        returnMofo.setLayout(new GridLayout(6,1));
        returnMofo.setPreferredSize(new Dimension(120, 680));
        returnMofo.setBorder(BorderFactory.createLineBorder (Color.BLACK, 2));
        returnMofo.add(nativeOne);
        returnMofo.add(nativeTwo);
        returnMofo.add(nativeThree);
        returnMofo.add(exoticOne);
        returnMofo.add(exoticTwo);
        returnMofo.add(exoticThree);
        return returnMofo;
    }


    private static void createAndShowGUI(){
        JFrame frame = new JFrame();
        frame.setTitle("Storm Watch");
        frame.setSize(800, 800);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        gameGUI gui = new gameGUI();
        frame.add(timer(), BorderLayout.NORTH);
        frame.add(sideBar(), BorderLayout.WEST);
        frame.add(gui, BorderLayout.EAST);                        

        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args){    
        createAndShowGUI();    
    }                
}
  • 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-14T01:20:51+00:00Added an answer on June 14, 2026 at 1:20 am

    Make sure you set layeredPane and timer to opaque.

    For example…

    layeredPane.setOpaque(true);
    

    You might want to, also, add layeredPane to the main board…

    public TestGameBoard() {
        layeredPane = new JLayeredPane();
        layeredPane.setPreferredSize(new Dimension(680, 680));
        layeredPane.setBackground(Color.GREEN);
        layeredPane.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
        layeredPane.setOpaque(true);
    
        setLayout(new BorderLayout()); // Easy to use layout manager
        add(layeredPane); // Now I'm visible ;)
    }
    

    And while I have your attention, you should always create/manipulate the UI from within the context of the Event Dispatching Thread…

    public static void main(String[] args) {
    
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                createAndShowGUI();
            }
        });
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to create an if statement in PHP that prevents a single post
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am currently running into a problem where an element is coming back from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.