hi, for a project im doing, i need to reproduce these 2 frames:
add
search
this is a picture of what i've got so far:
[my frames|http://i149.photobucket.com/albums/s41/mypetdinosaur_photo/searchaperson.jpg]
i'm just wondering how to achieve a ui like that; spaced out evenly. it's really difficult to me. any tips on approaching it? is my approach really messed up?
class AddPanel extends JPanel
{
//ui
JPanel infoPanel, buttonPanel;
JLabel nameLabel, addressLabel, phoneLabel;
JTextField nameField, addressField, phoneField;
JButton saveButton, clearButton, backButton;
//app
Person person;
String name, address, phone;
public AddPanel()
{
super();
setLayout(new BorderLayout());
setInfo();
setButtons();
}
public void setInfo()
{
nameLabel = new JLabel("NAME");
nameField = new JTextField();
addressLabel = new JLabel("ADDRESS");
addressField = new JTextField();
phoneLabel = new JLabel("PHONE");
phoneField = new JTextField();
infoPanel = new JPanel();
infoPanel.setLayout(new GridLayout(3,3));
infoPanel.add(nameLabel);
infoPanel.add(nameField);
infoPanel.add(addressLabel);
infoPanel.add(addressField);
infoPanel.add(phoneLabel);
infoPanel.add(phoneField);
add(infoPanel, BorderLayout.NORTH);
}
public void setButtons()
{
saveButton = new JButton("Save");
saveButton.addActionListener(new SaveListener());
clearButton = new JButton("Clear");
clearButton.addActionListener(new ClearListener());
backButton = new JButton("Back");
backButton.addActionListener(new BackListener());
buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(1, 3));
buttonPanel.add(saveButton);
buttonPanel.add(clearButton);
buttonPanel.add(backButton);
add(buttonPanel, BorderLayout.SOUTH);
}
class SaveListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
name = nameField.getText();
address = addressField.getText();
phone = phoneField.getText();
person = new Person(name, address, phone);
App.people.add(person);
}
}
class ClearListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
}
}
class BackListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
}
}
}
class SearchPanel extends JPanel
{
//top
JPanel topPanel;
JLabel searchLabel;
JTextField searchField;
JButton searchButton;
//center
JPanel centerPanel;
//left
JPanel leftPanel;
JLabel resultsLabel;
JList resultsList;
//right
JPanel rightPanel;
JPanel infoPanel, buttonPanel;
JLabel nameLabel, addressLabel, phoneLabel;
JTextField nameField, addressField, phoneField;
JButton updateButton, deleteButton, backButton;
Vector<Integer> indexes;
Vector<String> results;
String criteria;
public SearchPanel()
{
super();
indexes = new Vector<Integer>();
results = new Vector<String>();
setLayout(new BorderLayout());
setTop();
setCenter();
add(centerPanel, BorderLayout.CENTER);;
}
public void setTop()
{
searchLabel = new JLabel("Name");
searchField = new JTextField(20);
searchButton = new JButton("Search");
searchButton.addActionListener(new SearchListener());
topPanel = new JPanel();
topPanel.add(searchLabel);
topPanel.add(searchField);
topPanel.add(searchButton);
add(topPanel, BorderLayout.NORTH);
}
public void setCenter()
{
centerPanel = new JPanel();
centerPanel.setLayout(new GridLayout(0, 2));
setLeft();
setRight();
}
public void setLeft()
{
leftPanel = new JPanel();
leftPanel.setLayout(new BorderLayout());
resultsLabel = new JLabel("Results");
resultsList = new JList(results);
leftPanel.add(resultsLabel, BorderLayout.NORTH);
leftPanel.add(resultsList, BorderLayout.CENTER);
centerPanel.add(leftPanel);
}
public void setRight()
{
rightPanel = new JPanel();
rightPanel.setLayout(new BorderLayout());
setInfo();
setButton();
centerPanel.add(rightPanel);
}
public void setInfo()
{
infoPanel = new JPanel();
infoPanel.setLayout(new GridLayout(3, 1));
nameLabel = new JLabel("Name");
addressLabel = new JLabel("Address");
phoneLabel = new JLabel("Phone");
nameField = new JTextField(20);
addressField = new JTextField(20);
phoneField = new JTextField(20);
infoPanel.add(nameLabel);
infoPanel.add(nameField);
infoPanel.add(addressLabel);
infoPanel.add(addressField);
infoPanel.add(phoneLabel);
infoPanel.add(phoneField);
rightPanel.add(infoPanel, BorderLayout.CENTER);
}
public void setButton()
{
buttonPanel = new JPanel();
updateButton = new JButton("Update");
deleteButton = new JButton("Delete");
backButton = new JButton("Back");
buttonPanel.add(updateButton);
buttonPanel.add(deleteButton);
buttonPanel.add(backButton);
rightPanel.add(buttonPanel, BorderLayout.SOUTH);
}
class SearchListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
indexes.clear();
results.clear();
criteria = searchField.getText();
indexes = App.people.search(criteria);
for(int i = 0; i < indexes.size(); i++)
{
results.add(App.people.get(i).getName());
}
resultsList.setListData(results);
}
}
class AddListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
}
}
class ExitListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
}
}
/*class ListListener implements ListSelectionListener
{
}*/
}
Edited by: petpetpetpet on Apr 29, 2009 7:52 PM