Created
March 9, 2013 19:28
-
-
Save figengungor/5125420 to your computer and use it in GitHub Desktop.
Java GUI JButton
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.*; | |
import java.awt.*; | |
public class MyGUI { | |
JLabel l1,l2; | |
JTextField tf1,tf2; | |
JButton b1,b2; | |
public static void main(String[] args) { | |
// TODO, add your application code | |
new MyGUI(); | |
} | |
public MyGUI(){ | |
JFrame jf=new JFrame(); | |
jf.setTitle("My frame"); | |
jf.setSize(500,300); | |
JLabel l1=new JLabel("label 1"); | |
JLabel l2=new JLabel("label 2"); | |
JTextField tf1=new JTextField(10); | |
JTextField tf2=new JTextField(5); | |
JButton b1=new JButton("Button 1"); | |
JButton b2=new JButton("Button 2"); | |
tf1.setText("i am a text field"); | |
tf2.setText("i am a text field and can not be changed"); | |
tf2.setEditable(false); | |
Container pane=jf.getContentPane(); | |
pane.setLayout(new GridLayout(3,2) ); | |
pane.add(l1); | |
pane.add(l2); | |
pane.add(b1); | |
pane.add(b2); | |
pane.add(tf1); | |
pane.add(tf2); | |
jf.setDefaultCloseOperation(jf.EXIT_ON_CLOSE); | |
jf.setVisible(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment