Credits

Monday, February 15, 2010

Java's Buttons

Buttons are used to at least have a corresponding action once they are clicked  like when we click Save Button on a Microsoft Window Environment.

Buttons can be created either through the java.awt or javax.swing with a little modification. Find below a sample program made with Swing components.

[+/-] show/hide




import javax.swing.*;
import java.awt.*;

public class PlayBack extends JFrame {
public PlayBack() {
super("My Player");
setBounds(300,200,450, 100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
FlowLayout flo = new FlowLayout();
setLayout(flo);
JButton play = new JButton("Play");
JButton stop = new JButton("Stop");
JButton pause = new JButton("Pause");
JButton rewind = new JButton("Rewind");
JButton forward = new JButton("Forward");
add(play);
add(stop);
add(pause);
add(rewind);
add(forward);
}

public static void main(String[] arguments) {
PlayBack pb = new PlayBack();
pb.setVisible(true);
}
}

AddThis