import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
public class Users extends JScrollPane{
JList list;
DefaultListModel data;
JLabel lName,lPassword,lType;
JTextField tName, tPassword,tType;
JButton clear,add,edit,delete;
Users(){
init();
add();
}
void init(){
this.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
this.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
data = new DefaultListModel();
//data.addElement("a");
list = new JList(data);
lName = new JLabel("Name");
lPassword = new JLabel("Password");
lType = new JLabel("Type");
tName = new JTextField(20);
tPassword = new JTextField(20);
tType = new JTextField(20);
clear = new JButton("Clear");
add = new JButton("Add");
edit = new JButton("Edit");
delete = new JButton("Delete");
Font f = new Font("courier", Font.PLAIN, 14);
lName.setFont(f);
lPassword.setFont(f);
lType.setFont(f);
tName.setFont(f);
tPassword.setFont(f);
tType.setFont(f);
clear.setFont(f);
add.setFont(f);
edit.setFont(f);
delete.setFont(f);
list.setFont(f);
}
void add(){
GridBagConstraints gc = new GridBagConstraints();
gc.insets = new Insets(5,5,5,5);
JPanel buttonPane = new JPanel();
TitledBorder tb = new TitledBorder("Functions");
buttonPane.setBorder(tb);
buttonPane.add(clear);
buttonPane.add(add);
buttonPane.add(edit);
buttonPane.add(delete);
JPanel dataPane = new JPanel();
tb = new TitledBorder("Data");
dataPane.setBorder(tb);
dataPane.setLayout(new GridBagLayout());
gc.gridy = 0;
gc.gridx=0;
dataPane.add(lName,gc);
gc.gridx=1;
dataPane.add(tName,gc);
gc.gridy = 1;
gc.gridx=0;
dataPane.add(lPassword,gc);
gc.gridx=1;
dataPane.add(tPassword,gc);
gc.gridy = 2;
gc.gridx=0;
dataPane.add(lType,gc);
gc.gridx=1;
dataPane.add(tType,gc);
JScrollPane listPane = new JScrollPane(list);
tb = new TitledBorder("Select User");
listPane.setBorder(tb);
JPanel top = new JPanel(new GridBagLayout());
gc.gridx=0;
gc.gridy=0;
gc.gridheight=2;
gc.fill = GridBagConstraints.BOTH;
gc.ipadx =100;
top.add(listPane,gc);
gc.ipadx=0;
gc.gridx=1;
gc.gridy = 0;
gc.gridheight=1;
gc.fill = GridBagConstraints.NONE;
top.add(dataPane,gc);
gc.gridy = 1;
top.add(buttonPane,gc);
this.setViewportView(top);
}
}