GridLayout in Java AWT GUI and Swing example Source code
package edu.umt.guiexamples;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class GridLayoutExample {
public static void main(String[] args) {
// TODO code application logic here
JButton btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btn0;
JButton btnPlus, btnMinus, btnMul, btnPoint, btnEqual, btnClear;
JFrame f = new JFrame("Grid Layout Example");
JPanel p = new JPanel( );
GridLayout L = new GridLayout(4,4 );
btn0 = new JButton("0");
btn1 = new JButton("1");
btn2 = new JButton("2");
btn3 = new JButton("3");
btn4 = new JButton("4");
btn5 = new JButton("5");
btn6 = new JButton("6");
btn7 = new JButton("7");
btn8 = new JButton("8");
btn9 = new JButton("9");
btnPlus = new JButton("+");
btnMinus = new JButton("-");
btnMul = new JButton("*");
btnPoint = new JButton(".");
btnEqual = new JButton("=");
btnClear = new JButton("C");
p.setLayout(L);
p.add(btn1);
p.add(btn2);
p.add(btn3);
p.add(btnClear);
p.add(btn4);
p.add(btn5);
p.add(btn6);
p.add(btnMul);
p.add(btn7);
p.add(btn8);
p.add(btn9);
p.add(btnMinus);
p.add(btn0);
p.add(btnPoint);
p.add(btnPlus);
p.add(btnEqual);
f.setContentPane(p);
f.setSize(300,300);
f.setVisible(true);
}
}
package edu.umt.guiexamples;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class GridLayoutExample {
public static void main(String[] args) {
// TODO code application logic here
JButton btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btn0;
JButton btnPlus, btnMinus, btnMul, btnPoint, btnEqual, btnClear;
JFrame f = new JFrame("Grid Layout Example");
JPanel p = new JPanel( );
GridLayout L = new GridLayout(4,4 );
btn0 = new JButton("0");
btn1 = new JButton("1");
btn2 = new JButton("2");
btn3 = new JButton("3");
btn4 = new JButton("4");
btn5 = new JButton("5");
btn6 = new JButton("6");
btn7 = new JButton("7");
btn8 = new JButton("8");
btn9 = new JButton("9");
btnPlus = new JButton("+");
btnMinus = new JButton("-");
btnMul = new JButton("*");
btnPoint = new JButton(".");
btnEqual = new JButton("=");
btnClear = new JButton("C");
p.setLayout(L);
p.add(btn1);
p.add(btn2);
p.add(btn3);
p.add(btnClear);
p.add(btn4);
p.add(btn5);
p.add(btn6);
p.add(btnMul);
p.add(btn7);
p.add(btn8);
p.add(btn9);
p.add(btnMinus);
p.add(btn0);
p.add(btnPoint);
p.add(btnPlus);
p.add(btnEqual);
f.setContentPane(p);
f.setSize(300,300);
f.setVisible(true);
}
}
0 comments:
Post a Comment