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
|
package untitled4;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Frame1 extends JFrame {
JPanel contentPane;
JPanel jPanel1 = new JPanel();
JLabel jLabel1 = new JLabel();
GridLayout gridLayout1 = new GridLayout();
JButton jButton1 = new JButton();
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
contentPane.setNextFocusableComponent(null);
contentPane.setLayout(null);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
jPanel1.setBounds(new Rectangle(61, 53, 265, 188));
jPanel1.setLayout(gridLayout1);
jLabel1.setLabelFor(jPanel1);
jLabel1.setText("jLabel1");
jButton1.setBounds(new Rectangle(104, 251, 163, 33));
jButton1.setText("jButton1");
jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
contentPane.add(jPanel1, null);
jPanel1.add(jLabel1, null);
contentPane.add(jButton1, null);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void jButton1_actionPerformed(ActionEvent e) {
jLabel1.setIcon(new ImageIcon("file:///C:/img001.jpg" ));
}
}
class Frame1_jButton1_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;
Frame1_jButton1_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
} |