The ButtonPanel Class
This class can be used to create a panel with five buttons. The ButonPanel
class uses the SwingComp class to create
buttons.
Listing
15.2 ButtonPanel.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
//class used to create a button panel
public class ButtonPanel extends JPanel{
//constructor
public ButtonPanel(ActionListener listener){
super(new GridLayout(1,4));
//create buttons
SwingComp.createButton(this,listener,"Add");
SwingComp.createButton(this,listener,"Update");
SwingComp.createButton(this,listener,"Delete");
SwingComp.createButton(this,listener,"Clear");
SwingComp.createButton(this,listener,"Find");
//set the border of the panel
setBorder(BorderFactory.createEtchedBorder(
Color.white,Color.black));
}
}
The design of both the classes is very simple.
|