Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Changing backgrounds and starting a thread, help!

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Changing backgrounds and starting a thread, help!

    I am rather new to java, just a 10th grader in my schools Programming II class. I recently took up the challenge of creating the old school Pong game. I have the game all working and stuff, to were it runs and you can play. However, I have been trying to build upon that. I want there to be a main "Title screen" with a button that changes the image of the background to the main game background and also starting my game thread. I have all these in seperate classes, and I can't seem to figure out how when the area of the button is clicked, to change the image and start the game. I've been looking around for hours and still I am clueless. If someone could help, I'd much appreciate it.


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Changing backgrounds and starting a thread, help!

    Welcome to Java Programming Forums zachbray. Without seeing your code we can only assume. So, first assumption, incoming is to create a frame and call the game starting thread frame by clicking on the button of the created frame and pass the image to the next where you are setting the image as background in your game.

  3. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Changing backgrounds and starting a thread, help!

    Excuse me for not putting any of my code. Here is my main class, which handles the frames.
    import javax.swing.*;

    public class Windows extends JPanel{

    public static void main(String[] args){
    Graphic g = new Graphic();
    RunGame rungame = new RunGame();
    TitleScreen title = new TitleScreen();

    JFrame mainWindow = new JFrame("Main Window");
    mainWindow.setSize(700,500);
    mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON _CLOSE);
    mainWindow.setVisible(true);
    mainWindow.setResizable(false);
    mainWindow.setLocationRelativeTo(null);
    mainWindow.add(title);
    }
    }

    The thing I've been trying to figure out is how to (on response to clicking) remove title, then add g and rungame to mainWindow. I've tried a ton of ways but they always just keep the component title up. If you know of anyways I could do this, help, or if there is another way to do it other than what I've been trying, please tell me.

  4. #4
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Changing backgrounds and starting a thread, help!

    Quote Originally Posted by zachbray View Post
    Excuse me for not putting any of my code. Here is my main class, which handles the frames.
    import javax.swing.*;

    public class Windows extends JPanel{

    public static void main(String[] args){
    Graphic g = new Graphic();
    RunGame rungame = new RunGame();
    TitleScreen title = new TitleScreen();

    JFrame mainWindow = new JFrame("Main Window");
    mainWindow.setSize(700,500);
    mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON _CLOSE);
    mainWindow.setVisible(true);
    mainWindow.setResizable(false);
    mainWindow.setLocationRelativeTo(null);
    mainWindow.add(title);
    }
    }

    The thing I've been trying to figure out is how to (on response to clicking) remove title, then add g and rungame to mainWindow. I've tried a ton of ways but they always just keep the component title up. If you know of anyways I could do this, help, or if there is another way to do it other than what I've been trying, please tell me.
    Your game will be surely in some other frame, so you just need to read about action listeners and then apply them for invoking the new frame that is in this case your game class frame.

Similar Threads

  1. Starting a New Game After One Ends.
    By Delgado21 in forum AWT / Java Swing
    Replies: 1
    Last Post: September 19th, 2011, 07:11 AM
  2. Starting BlackBerry development
    By AttilioCarotenuto in forum Java ME (Mobile Edition)
    Replies: 1
    Last Post: July 29th, 2011, 12:11 PM
  3. starting to make a simple database
    By chronoz13 in forum JDBC & Databases
    Replies: 1
    Last Post: January 15th, 2010, 02:06 PM
  4. Help starting program, need done by Nov 4
    By raidcomputer in forum What's Wrong With My Code?
    Replies: 7
    Last Post: November 4th, 2009, 07:22 PM
  5. Need help starting a program
    By Mickey2315 in forum Java Theory & Questions
    Replies: 2
    Last Post: September 7th, 2009, 02:21 PM