Reformatted code
This commit is contained in:
@@ -6,12 +6,14 @@ import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
|
||||
class BookSellerGui extends JFrame {
|
||||
class BookSellerGui extends JFrame
|
||||
{
|
||||
private BookSellerAgent myAgent;
|
||||
|
||||
private JTextField titleField, priceField;
|
||||
|
||||
BookSellerGui(BookSellerAgent a) {
|
||||
BookSellerGui(BookSellerAgent a)
|
||||
{
|
||||
super(a.getLocalName());
|
||||
|
||||
myAgent = a;
|
||||
@@ -27,9 +29,11 @@ class BookSellerGui extends JFrame {
|
||||
getContentPane().add(p, BorderLayout.CENTER);
|
||||
|
||||
JButton addButton = new JButton("Add");
|
||||
addButton.addActionListener( new ActionListener() {
|
||||
addButton.addActionListener( new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent ev) {
|
||||
try {
|
||||
try
|
||||
{
|
||||
String title = titleField.getText().trim();
|
||||
String price = priceField.getText().trim();
|
||||
myAgent.updateCatalogue(title, Integer.parseInt(price));
|
||||
@@ -45,8 +49,10 @@ class BookSellerGui extends JFrame {
|
||||
p.add(addButton);
|
||||
getContentPane().add(p, BorderLayout.SOUTH);
|
||||
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
addWindowListener(new WindowAdapter()
|
||||
{
|
||||
public void windowClosing(WindowEvent e)
|
||||
{
|
||||
myAgent.doDelete();
|
||||
}
|
||||
} );
|
||||
@@ -54,12 +60,13 @@ class BookSellerGui extends JFrame {
|
||||
setResizable(false);
|
||||
}
|
||||
|
||||
public void display() {
|
||||
public void display()
|
||||
{
|
||||
pack();
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int centerX = (int)screenSize.getWidth() / 2;
|
||||
int centerY = (int)screenSize.getHeight() / 2;
|
||||
setLocation(centerX - getWidth() / 2, centerY - getHeight() / 2);
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user