4 import java.awt.Rectangle;
5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
7 import java.rmi.Naming;
8 import java.rmi.RemoteException;
9 import java.util.Enumeration;
10 import java.util.Vector;
12 import javax.swing.JButton;
13 import javax.swing.JFrame;
14 import javax.swing.JLabel;
15 import javax.swing.JPanel;
16 import javax.swing.JScrollPane;
17 import javax.swing.JTable;
18 import javax.swing.border.EmptyBorder;
19 import javax.swing.table.DefaultTableModel;
21 import common.AccountInterface;
22 import common.AdminInterface;
24 import configuration.___IntNames;
27 public class DeleteOwnerGUI extends JFrame {
32 private static final long serialVersionUID = 1L;
33 private JPanel contentPane;
36 private DefaultTableModel tableModel;
37 private AdminInterface AdM = null;
38 private Vector<Owner> owners = new Vector<Owner>();
43 public DeleteOwnerGUI() {
44 setTitle("Current owners:");
47 } catch (Exception e) {
52 private void init() throws Exception {
53 setBounds(100, 100, 600, 500);
54 contentPane = new JPanel();
55 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
56 setContentPane(contentPane);
57 contentPane.setLayout(null);
59 AdM = (AdminInterface) Naming
60 .lookup(___IntNames.AdminManager);
61 } catch (Exception e1) {
63 .println("Error accessing remote authentication: "
66 this.owners = AdM.getAllOwners();
67 JLabel lblNewLabel = new JLabel();
68 lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
69 lblNewLabel.setBounds(23, 41, 536, 33);
70 contentPane.add(lblNewLabel);
71 if (this.owners.isEmpty())
73 .setText("There are not owners in the system");
75 lblNewLabel.setText("List of owners:");
76 JScrollPane scrollPane = new JScrollPane();
77 scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
78 scrollPane.setBounds(23, 113, 536, 271);
79 contentPane.add(scrollPane);
80 final JLabel feedback = new JLabel("");
81 feedback.setBounds(134, 447, 307, 14);
82 contentPane.add(feedback);
83 JButton btnNewButton = new JButton("Delete from the system");
84 btnNewButton.addActionListener(new ActionListener() {
85 public void actionPerformed(ActionEvent e) {
86 if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
87 AccountInterface acm = null;
90 acm = (AccountInterface) Naming
91 .lookup(___IntNames.AccountManager);
92 } catch (Exception e1) {
93 System.out.println("Error accessing remote authentication: "
98 if(acm.removeAccount(table.getSelectedRow()))
100 feedback.setText("Deleted from the system");
102 } catch (RemoteException e1) {
103 e1.printStackTrace();
106 ((DefaultTableModel)table.getModel()).removeRow(table.getSelectedRow());
110 btnNewButton.setBounds(88, 396, 428, 40);
111 contentPane.add(btnNewButton);
112 table = new JTable() {
113 private static final long serialVersionUID = 1L;
115 public boolean isCellEditable(int row, int column) {
120 scrollPane.setViewportView(table);
121 tableModel = new DefaultTableModel(null, new String[] {
122 "Name", "E-mail", "Bank Account" });
124 table.setModel(tableModel);
127 Enumeration<Owner> rhs = this.owners.elements();
128 while (rhs.hasMoreElements()) {
129 Owner own = rhs.nextElement();
130 Vector<Object> row = new Vector<Object>();
131 row.add(own.getName());
132 row.add(own.getMailAccount());
133 row.add(own.getBankAccount());
134 tableModel.addRow(row);