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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:18:53+00:00 2026-05-12T00:18:53+00:00

I’m developing a sim game based on Theme Hospital, which is quite an old

  • 0

I’m developing a sim game based on Theme Hospital, which is quite an old game.
I’ve made lots of progress on the underlying workings, however now I am coming to the GUI elements, which I haven’t done alot of before. I am still rather new to java.
The effect I am trying to create is like shown here…

http://www.tubechop.com/watch/18438

Click on a button, opens up a panel with tabs to select from different selections, and then click a button to build a room. I believe for the “tabs” I can use a card layout? For the actual building of rooms, I am pretty much sorted. The main problem I have right now, is getting the panel to open up on the click of a button.

At current, I have 1 JFrame and 2 JPanels ontop, the main game panel and the control panel with a few buttons.

Can anyone show me some simple example of how I would do such a thing? I know its probably really simple, and I bet some of you could even write the code off the top of your head, but I am new to java, and have been taught more about the logical elements of programming so far rather than how to build a more complex multi layered GUI like required in a game.

I know it’s an ambitious project, but I have come a long way, and have even implemented custom path finding using A*, which I’m happy about (All thanks to you people here at StackOverflow!)

Thank you in advance for your help.

  • 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-12T00:18:53+00:00Added an answer on May 12, 2026 at 12:18 am

    JDialogs would work, but they’re going to pop up new top level windows over your game window. You could implement your main game display and control panel as the background of a JDesktopPane(which extends JLayeredPane), and could make the pop ups JInternalFrames.

    Contrived (but working) example:

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ComponentEvent;
    import java.awt.event.ComponentAdapter;
    import java.awt.event.ActionListener;
    import java.text.NumberFormat;
    
    public class DesktopTest extends JFrame {
    
    private JDesktopPane desktop;
    private JPanel background;
    private JInternalFrame firstFrame;
    private JInternalFrame secondFrame;
    
    public DesktopTest() {
        super("DesktopTest");
    
        desktop = new JDesktopPane();
        setContentPane(desktop);
    
        background = new JPanel(new BorderLayout());
        JToolBar toolbar = new JToolBar();
        toolbar.add(new AbstractAction("1") {
    
            public void actionPerformed(ActionEvent actionEvent) {
                firstFrame.setVisible(true);
            }
        });
    
        toolbar.add(new AbstractAction("2") {
    
            public void actionPerformed(ActionEvent actionEvent) {
                secondFrame.setVisible(true);
            }
        });
        AddPanel addPanel = new AddPanel();
        background.add(addPanel, BorderLayout.CENTER);
        background.add(toolbar, BorderLayout.SOUTH);
        addComponentListener(new ComponentAdapter() {
    
            public void componentResized(ComponentEvent componentEvent) {
                background.setSize(desktop.getSize());
                background.revalidate();
                background.repaint();
            }
    
            public void componentShown(ComponentEvent componentEvent) {
                background.setSize(desktop.getSize());
                background.revalidate();
                background.repaint();
            }
        });
        desktop.add(background);
    
        firstFrame = new TermFrame("First Term", "Update First Term: ", addPanel) {
    
            protected int getValue() {
                return addPanel.getFirst();
            }
    
            protected void update(int value) {
                addPanel.setFirst(value);
            }
        };
        firstFrame.pack();
        firstFrame.setBounds(10, 10, 200, 150);
        desktop.add(firstFrame);
    
        secondFrame = new TermFrame("Second Term", "Update Second Term: ", addPanel){
    
            protected int getValue() {
                return addPanel.getSecond();
            }
    
            protected void update(int value) {
                addPanel.setSecond(value);
            }
        };
        secondFrame.pack();
        secondFrame.setBounds(200, 200, 200, 150);
        desktop.add(secondFrame);
    
    }
    
    public static void main(String[] args) {
        JFrame f = new DesktopTest();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setSize(400, 400);
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    }
    
    static class AddPanel extends JPanel {
        private JLabel first;
        private JLabel second;
        private JLabel result;
    
        public AddPanel() {
            first = new JLabel("0");
            second = new JLabel("0");
            result = new JLabel("0");
    
            Box vertical = Box.createVerticalBox();
            vertical.add(Box.createVerticalGlue());
            Box horizontal = Box.createHorizontalBox();
            horizontal.add(Box.createHorizontalGlue());
            horizontal.add(first);
            horizontal.add(new JLabel("+"));
            horizontal.add(second);
            horizontal.add(new JLabel("="));
            horizontal.add(result);
            horizontal.add(Box.createHorizontalGlue());
            vertical.add(horizontal);
            vertical.add(Box.createVerticalGlue());
    
            setLayout(new BorderLayout());
            add(vertical, BorderLayout.CENTER);
        }
    
        public void setFirst(int i) {
            first.setText(Integer.toString(i));
            updateResult();
        }
    
        public int getFirst() {
            return Integer.parseInt(first.getText());
        }
    
        public void setSecond(int j) {
            second.setText(Integer.toString(j));
            updateResult();
        }
    
        public int getSecond() {
            return Integer.parseInt(second.getText());
        }
    
        private void updateResult() {
            int i = Integer.parseInt(first.getText());
            int j = Integer.parseInt(second.getText());
            result.setText(Integer.toString(i + j));
            revalidate();
        }
    }
    
    static abstract class TermFrame extends JInternalFrame {
    
        protected AddPanel addPanel;
        private JFormattedTextField termField;
    
        public TermFrame(String title, String message, AddPanel addPanel) {
            super(title, true, true, true);
            this.addPanel = addPanel;
            NumberFormat format = NumberFormat.getNumberInstance();
            format.setMaximumFractionDigits(0);
            termField = new JFormattedTextField(format);
            termField.setColumns(3);
            termField.setValue(getValue());
    
            JPanel content = new JPanel(new FlowLayout());
            content.add(new JLabel(message));
            content.add(termField);
            JButton apply = new JButton("apply");
            apply.addActionListener(new ActionListener() {
    
                public void actionPerformed(ActionEvent actionEvent) {
                    Integer value = Integer.parseInt(termField.getText());
                    update(value);
                }
            });
            content.add(apply);
            setContentPane(content);
    
            setDefaultCloseOperation(JInternalFrame.HIDE_ON_CLOSE);
        }
    
        protected abstract int getValue();
    
        protected abstract void update(int value);
    
    
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you running on OS 3.0? I saw the same… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer It looks like you need to register Apache::Session::Memcached with Apache::Session::Wrapper,… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Use DATENAME or DATEPART: SELECT DATENAME(dw,GETDATE()) -- Friday SELECT DATEPART(dw,GETDATE())… May 12, 2026 at 1:19 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.