26 June 2014

Sample Frame


A Simple Example of Frame by Notepad


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

public class Grid{



private JFrame f;
private Panel p1,p2,p3,p4;

public Grid(){


f = new JFrame("Hello Grid");
p1= new Panel();
p2= new Panel();
p3= new Panel();
p4= new Panel();
}

public void launchFrame(){
f.setVisible(true);
f.setSize(600,600);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new GridLayout(2,2));
p1.setBackground(Color.red);
f.add(p1);
p2.setBackground(Color.blue);
f.add(p2);
p3.setBackground(Color.yellow);
f.add(p3);
p4.setBackground(Color.green);
f.add(p4);
}
public static void main(String args[]){
Grid Mad = new Grid();
Mad.launchFrame();
}
}


Save it as Grid.java ( same as class name)



in cmd prompt type  "javac Grid.java"

then   "java Grid"


Output Will As




No comments:

Post a Comment