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");
}
}
On this page of the site you can watch the video online Java programming part 59 GUI : Adding Buttons with ActionListener and FlowLayout LayoutManager. with a duration of hours minute second in good quality, which was uploaded by the user Redemptie 21 May 2012, share the link with friends and acquaintances, this video has already been watched 7,912 times on youtube and it was liked by 17 viewers. Enjoy your viewing!