Here are the examples of the java api lib.SerialStatus.addEventListener() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1 Examples
18
Source : Principal.java
with MIT License
from anastaciocintra
with MIT License
from anastaciocintra
public void showWindow() throws IOException {
serialStatus = new SerialStatusTMT20("com1");
frame = new JFrame("Printer Coffee");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
WindowListener wls = new WindowListener() {
@Override
public void windowOpened(WindowEvent windowEvent) {
}
@Override
public void windowClosing(WindowEvent windowEvent) {
serialStatus.finish();
frame.dispose();
}
@Override
public void windowClosed(WindowEvent windowEvent) {
}
@Override
public void windowIconified(WindowEvent windowEvent) {
}
@Override
public void windowDeiconified(WindowEvent windowEvent) {
}
@Override
public void windowActivated(WindowEvent windowEvent) {
}
@Override
public void windowDeactivated(WindowEvent windowEvent) {
}
};
frame.addWindowListener(wls);
frame.setLayout(new FlowLayout());
JButton buttonPrint = new JButton("Print");
buttonPrint.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
try {
print();
} catch (IOException e) {
e.printStackTrace();
}
}
});
JButton buttonFinish = new JButton("Finish");
buttonFinish.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
serialStatus.finish();
}
});
frame.add(buttonPrint);
frame.add(buttonFinish);
JLabel labelStatus = new JLabel("Status");
labelStatus.setOpaque(true);
frame.add(labelStatus);
JTextArea textArea = new JTextArea();
textArea.setColumns(25);
textArea.setRows(7);
frame.add(textArea);
serialStatus.addEventListener(new PrinterStatusEvent() {
@Override
public void onStatusChanged() {
textArea.setText("");
Map<Integer, SerialStatus.Status> mapErrors = serialStatus.getMapErrors();
for (SerialStatus.Status error : mapErrors.values()) {
textArea.append(error.value + "\n");
}
Map<Integer, SerialStatus.Status> mapInfo = serialStatus.getMapInfo();
for (SerialStatus.Status info : mapInfo.values()) {
textArea.append(info.value + "\n");
}
}
});
// just change color
serialStatus.addEventListener(new PrinterStatusEvent() {
@Override
public void onStatusChanged() {
if (serialStatus.haveAnyError()) {
labelStatus.setBackground(Color.red);
} else {
labelStatus.setBackground(Color.green);
}
}
});
frame.pack();
frame.setMinimumSize(frame.getPreferredSize());
frame.setVisible(true);
}