This is a class in a program I am working on:
Code:
class ImageBox extends JFrame {
JTextField filename = new JTextField(15);
JLabel label = new JLabel("Save as: ", JLabel.LEFT);
JButton capture = new JButton("Get the image");
GridLayout layout = new GridLayout(2, 2);
DataConnect dataconn = new DataConnect(999);
byte[] image;
int i = 0;
String file;
public ImageBox() {
super("Save a screenshot");
capture.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
dataconn.establishConnection();
try {
while (true) {
image[i] = dataconn.data_reader.readByte();
i++;
}
} catch (IOException e) {
System.err.println("Exception: " + e.getMessage());
}
file = filename.getText();
}
});
JPanel pane = new JPanel();
pane.setLayout(layout);
pane.add(label);
pane.add(filename);
pane.add(capture);
setContentPane(pane);
}
void applyWindowListener() {
WindowListener l = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
setVisible(false);
}
};
this.addWindowListener(l);
this.pack();
this.setVisible(true);
}
}
Why, when I click the capture button an exception is thrown that there was an event generated at an unknown source, although I have added an ActionListener?