JAVA GUI
A java non interactive interfaces
Example
import [Link].*;
import [Link].*;
public class guib1 extends JFrame{
//adding controls here you want on the interface
JLabel l1,l2,l3;
JTextField t1,t2,t3;
JButton b1;
//creating constructor of the class
A constructor is a special method of a class it is like an instance method
that usually has the same name as the class, and can be used to set the
values of the members of an object. Use the constructor to initialize our
controls as seen below
public guib1(){
super("Container");
l1= new JLabel("Enter your Name here:");
l2= new JLabel("Enter your age here:");
l3=new JLabel("Enter your Gender here:");
t1=new JTextField(10);
t2=new JTextField(10);
t3=new JTextField(10);
b1=new JButton("ADD INFOR");
Add a layout specifying the vgap and hgap to contain our controls
setLayout(new FlowLayout([Link], 90,30));
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(b1);
setSize(300,400);
setVisible(true);
}
Declare our main function and then create an object that will call the
constructor
public static void main(String[] args) {
new guib1();
}
}
An interactive java program
Addition of two numbers example
import [Link].*;
import [Link].*;
import [Link];
import [Link];
public class Gui extends JFrame implements ActionListener {
JLabel l1,l2,l3;
JTextField t1,t2,t3;
JButton b1;
public Gui(){
super("SUMMATION");
l1=new JLabel("ENTER NUMBER ONE");
l2=new JLabel("ENTER NUMBER TWO");
l3=new JLabel("RESULT");
t1=new JTextField(10);
t2=new JTextField(10);
t3=new JTextField(10);
b1 =new JButton("ADD");
setLayout(new FlowLayout([Link], 150,20 ));
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(b1);
[Link](this);
setSize(400,500);
setVisible(true);
@Override
public void actionPerformed(ActionEvent e) {
int a=[Link]([Link]());
int b =[Link]([Link]());
int sum=a+b;
[Link]([Link](sum));
public static void main(String[] args) {
new Gui();
}
}
//the program above adds an action listener to make it more interactive.
output