Java programming part 59 GUI : Adding Buttons with ActionListener and FlowLayout LayoutManager.
Channel: Redemptie
Date: 2012-05-21

Java Programming tutorial, GUI, Graphical User Interface. this tutorial is teaching adding Buttons, using ActionListener and FlowLayout LayoutManager.

import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
public class UserFrame extends JFrame implements ActionListener{
 UserFrame(){
  setTitle("UsersFrame");
  setSize(200,200);
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  setVisible(true);
 }


public static void main(String[] args){
 UserFrame f = new UserFrame();
 Container cp = f.getContentPane();
 f.setLayout(new FlowLayout());
 JButton jb1 = new JButton("first click");
 jb1.addActionListener(f);
 
 JButton jb2 = new JButton("Second click");
 jb2.addActionListener(new ActionListener(){

  @Override
  public void actionPerformed(ActionEvent e) {
   // TODO Auto-generated method stub
   System.out.println(" SEe waht i mean we are all different!!");
  }
  
 });
 f.add(jb1);
 f.add(jb2);
}


@Override
public void actionPerformed(ActionEvent e) {
 // TODO Auto-generated method stub
 System.out.println("The first button has been clickled");
}


}