Jump to content
  • Advertisement
Sign in to follow this  

Java JFrame windows

This topic is 4274 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys. Well I am learning java and I am working on a small program that displays two different windows. One on top of the other. My problem is that I want one window to display a white background and the other black. I am following a sample program froma textbook from school. The program compiles and runs just fine, but the window colors do not change. They stay the default gray. Here is the code.
// imports
import java.awt.Color;
import javax.swing.JFrame;

public class Window
    /** Creates a new instance of Window */
    public Window()
    public static void main( String[] args )
        JFrame window;
        JFrame blackWindow;
        window = new JFrame( "First Window" );
        window.setBounds( 50, 50, 300, 200 );
        window.setLayout( null );
        window.setVisible( true );

        blackWindow = new JFrame("Black Window");
        blackWindow.setBounds(150, 150, 250, 125);

     } // end main

I tried a different example using labels and the background and foreground colors changed as they should. I just don't know why the windows won't. By the way I am using Netbeans 5.0 with the JDK 5 that installed with it. Any ideas? Thanks for your help.

Share this post

Link to post
Share on other sites
Hey thanks. I never would have even thought that it would be something like that. I was just blindly following what the book was teaching me. The bad thing is is that the book was published this year(2006) and you would think that the auther would know about using contentPane(). But maybe not.

After reading the link you provided and doing a little bit more research I now have working programs. Thanks again. :)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!