Skip to content

Instantly share code, notes, and snippets.

@figengungor
Created March 9, 2013 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save figengungor/5125016 to your computer and use it in GitHub Desktop.
Save figengungor/5125016 to your computer and use it in GitHub Desktop.
GUI Basic I : JFrame, Container and JLabel
import javax.swing.*; //For Window Frame (JFrame)
import java.awt.*; //For Container object
public class MyGUI {
public static void main(String[] args) {
new MyGUI();
}
public MyGUI(){
JFrame jf=new JFrame();
jf.setTitle("My frame");
jf.setSize(300,200);
jf.setDefaultCloseOperation(jf.EXIT_ON_CLOSE);
jf.setVisible(true);
//Creating a container
Container pane = jf.getContentPane();
//3 row and 2 column
pane.setLayout(new GridLayout(3,2));
//Creating label to put in the container
//JLabel label = new JLabel("I am a label");
//Adding label to container
//pane.add(label);
JLabel l1=new JLabel("label 1");
JLabel l2=new JLabel("label 2");
JLabel l3=new JLabel("label 3");
JLabel l4=new JLabel("label 4");
JLabel l5=new JLabel("label 5");
JLabel l6=new JLabel("label 6");
//Components are added from left to right and top to bottom when using the grid layout.
pane.add(l1);
pane.add(l3);
pane.add(l5);
pane.add(l2);
pane.add(l4);
pane.add(l6);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment