-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClubAbstractEntity.java
64 lines (57 loc) · 1.97 KB
/
ClubAbstractEntity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public abstract class ClubAbstractEntity extends JFrame
{
//-----------data fields---------
protected JPanel mainPanel;
protected JButton okButton;
protected JButton cancelButton;
private ButtonsHandler handler;
//-----------constructors--------
public ClubAbstractEntity()
{
JPanel subJP = new JPanel();
this.mainPanel = new JPanel();
this.okButton=new JButton("OK");
this.cancelButton=new JButton("CANCEL");
this.handler=new ButtonsHandler();
mainPanel.setLayout(new BorderLayout());
this.okButton.addActionListener(handler);
this.cancelButton.addActionListener(handler);
subJP.add(cancelButton);
subJP.add(okButton);
mainPanel.add(subJP,BorderLayout.SOUTH);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
setContentPane(mainPanel);
getContentPane().setPreferredSize(Toolkit.getDefaultToolkit().getScreenSize());
setResizable(false);
setLocationRelativeTo(null);
setVisible(true);
}
//-----------methods----------
protected void addToCenter(Component guiComponent)
{
this.mainPanel.add(guiComponent,BorderLayout.CENTER);
}
private class ButtonsHandler implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == okButton && validateData()){
commit();
mainPanel.setVisible(false); //TO DO
}
if (e.getSource() == cancelButton){
rollBack();
mainPanel.setVisible(false); //TO DO
}
}
}
//absracts:
public abstract boolean match(String key);
protected abstract boolean validateData();
protected abstract void commit();
protected abstract void rollBack();
}