by Dinesh Thakur Category: Swing

Frame is the most common container used to create top-level window having title, border and window-management buttons. It can also be used to create secondary windows for an application. A frame is an object of JFrame class.

The constructors defined by this class JFrame class are as follows.

JFrame ()

JFrame(String title)

where,

title specifies the title for the frame

Example :

import java.awt.*;

import javax.swing.*;
public class JFrameColor extends JFrame
 {
    private final int SIZE = 100;
    private Container cntnr = getContentPane();
    private JButton BtnClckHere = new JButton("Click Here");
    public JFrameColor()
     {
       super("JFrame Color in Java Swing Example");
       setSize(200,150);
       setVisible(true);
       cntnr.setLayout(new FlowLayout());
       cntnr.add(BtnClckHere);
       cntnr.setBackground(Color.YELLOW);
       BtnClckHere.setBackground(Color.blue);
       BtnClckHere.setForeground(Color.cyan);
     }
       public static void main(String[] args)
          {
            JFrameColor frame = new JFrameColor();
          }
 }




About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles