Created
March 9, 2013 17:49
-
-
Save figengungor/5125016 to your computer and use it in GitHub Desktop.
GUI Basic I : JFrame, Container and JLabel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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