This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BarcodeReaderTestDriver.java
75 lines (65 loc) · 1.91 KB
/
BarcodeReaderTestDriver.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
65
66
67
68
69
70
71
72
73
74
75
package BicycleGarage;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.awt.BorderLayout;
import java.awt.event.*;
/**
* This is an abstract class representing the common parts for all
* barcode readers.
*
* @version 1.0
* @author Martin H�st
*/
abstract public class BarcodeReaderTestDriver implements BarcodeReader, ActionListener {
private JFrame frame;
private JTextField scannedCode;
protected GarageGUI gui;
private JButton scanButton;
/**
* Register bicycle garage manager so that the bar code
* reader knows which manager to call when a user has used
* the reader.
* @param manager The bicycle garage manager
*/
public void register(GarageGUI gui) {
this.gui = gui;
}
/**
* Create a BarcodeReaderTestDriver.
* @param windowName text to be written in window frame.
*/
public BarcodeReaderTestDriver(String windowName) {
frame = new JFrame(windowName);
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
// make the window impossible to close
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
scannedCode = new JTextField(5);
panel.add(new JLabel("Scanned code:"), BorderLayout.WEST);
panel.add(scannedCode, BorderLayout.EAST);
scanButton = new JButton("Scan");
scanButton.addActionListener(this);
panel.add(scanButton, BorderLayout.SOUTH);
frame.add(panel);
frame.pack();
frame.setVisible(true);
}
/**
* This abstract method is implemented by subclasses.
* Subclasses either call the manager�s entryBarcode
* or exitBarcode.
* @param code the scanned code.
*/
abstract void informManager(String code);
/**
* Handles the event that the "scan button" is pressed.
*/
public void actionPerformed(ActionEvent e) {
String code = scannedCode.getText();
scannedCode.setText(null);
informManager(code);
}
}