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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:52:53+00:00 2026-06-17T11:52:53+00:00

I am making a Java game and I need some advice on how to

  • 0

I am making a Java game and I need some advice on how to do something.

Currently I am using 2 different .java files to make the game. I have a main program that extends JFrame and I call the other .java file which extends JPanel.

The game currently works but I want to make another mode for the game and I think it would be better if I made another file for it.

Here is all of the code for the main file. I removed all the useless unneeded things:

import java.awt.*;
import javax.swing.*;

public class ProgramMain extends JFrame  implements KeyListener
{
    private Program mode1;
    private Program2 mode2;

    public ProgramMain ()
    {
        setResizable (false);
        mode1 = new Program ();
        getContentPane ().add (mode1, BorderLayout.CENTER);
        if (mode1.change == true)
        {
            this.remove (mode1);
            board = new Program2 ();
            this.getContentPane ().add (mode2);            
        }
    }

  public void actionPerformed (ActionEvent event)
  {
  }

    public static void main (String[] args)
    {
        GameMain frame = new GameMain ();
        frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
        frame.pack ();
        frame.setVisible (true);
    }
}

Is there a way where I can relaunch the ProgramMain () method so it does another check, so if this time, the if statement becomes true, it changes the screen and opens the Program2.java file instead.

That is my main problem here. I am not sure how I can switch between .java programs. What do I need to do if I would like my Main program (ProgramMain) to read another program/.java file.

  • 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-17T11:52:54+00:00Added an answer on June 17, 2026 at 11:52 am

    For switching you can have a action in your frame where you need switch.

    ActionListener al = new ActionListener(){
        public void actionPerformed(ActionEvent ae) {
            if (board1) {
                getContentPane().add(gameBoard, BorderLayout.CENTER);
            } else {
                getContentPane().add(gameBoard2, BorderLayout.CENTER);
            }
        }
    };
    buttonSwitch.addActionListener (al);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently making a pacman game in java. I have a question about the
I'm making my first game using Java on Android. I need to draw a
I am making a text based game in Java. I have a text field,
I am making a basic little game in Java and I want to have
i am making a game which will ask different questions in java. questions are
I'm making a Java program that can solve the roots using the quadratic equation
I'm making a game in Java, and I need a good file format to
I am making a simple 2D game in java... I am using java's Graphics2D
I'm making a simple game in Java using swing and am having problems with
I'm making a Java game that has a main class, a battle class, a

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.