import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class PictureFrame extends JFrame{
private ImagePanel X;
private String imageFile;
PictureFrame(String jpegFileName) {
super("-- "+jpegFileName+" --"); //Set Title
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set to terminate program when closing window
imageFile = jpegFileName;
JPanel frame = new JPanel(); //create panel to hold button and image panel
frame.setLayout(new BorderLayout());
// construct an ImagePanel and assign it to X here
try{ //deal with stupid fucking exception
ImagePanel X = new ImagePanel(imageFile); //create image panel
X.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); //add 10px border
frame.add(X, BorderLayout.NORTH); //position at the top
} catch (Exception ex) {
System.out.println(ex);
}
JButton button = new JButton("Lights On");
button.setBorder(BorderFactory.createEmptyBorder(0,10,10,10));
button.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent ae) {
if (X.lightIs(1)) {
X.lightOff();
//button.setText("Lights On");
} else {
X.lightOn();
//button.setText("Lights OFF");
}
}
});
add(button, BorderLayout.SOUTH);
this.add(frame, BorderLayout.CENTER); //add panel containing button and image panel centered
pack(); //pack jframe (make it look pretty)
setVisible(true); // make it so people can see it
}
}