Java #11: How to change the JFrame Background Color

//Changing the frame color
frame.getContentPane().setBackground(Color.BLUE);

JFrame_Color


Entire program

//Programmer:Akinwale Owi
//Program Purpose: How to Build A JFrame
//Company:Dagba Computers
//——————————————————

//package name
package dagba.computers;

//imports
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

//class name
public class DagbaComputers
{

//private function where I build the jFrame
private static void buildingJFrame ()
{

JFrame frame = new JFrame(“Dagba Sample JFrame”); //Frame Heading
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //What happens when the frame closes

//Setting frame dimensions
frame.setPreferredSize(new Dimension (400, 400));

//Changing the frame color
frame.getContentPane().setBackground(Color.BLUE);

//Frame
frame.pack();
frame.setVisible(true); //So we can see the frame

}

//main function
public static void main(String[] args)
{
javax.swing.SwingUtilities.invokeLater (new Runnable ()
{
public void run ()
{
//The Function
buildingJFrame();//Function where we built the Frame in
}
});

}//End of main function

}//end of DagbaComputers Class

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: