-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageWindow.java
More file actions
61 lines (45 loc) · 1.29 KB
/
Copy pathImageWindow.java
File metadata and controls
61 lines (45 loc) · 1.29 KB
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
import javax.swing.*; // needed for JPanel, JLabel
//import javax.swing.event.*;
import java.awt.event.*; // needed for actionlistener
import java.awt.*;
public class ImageWindow extends JFrame
{
private JPanel buttonPanel;
private JPanel imagePanel;
private JLabel imageLabel;
private JButton imageButton;
public ImageWindow()
{
super("My First Icons!");
//setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
buttonPanel = new JPanel();
imagePanel = new JPanel();
ImageIcon picture = new ImageIcon("bio-cycle.jpg");
imageLabel = new JLabel("Nothing is here");
imageLabel.setIcon(picture);
imageButton = new JButton("Click to see picture");
imageButton.addActionListener(new PictureButtonListener());
buttonPanel.add(imageButton);
imagePanel.add(imageLabel);
add(imagePanel, BorderLayout.CENTER);
add(buttonPanel, BorderLayout.SOUTH);
pack();
setVisible(true);
}
private class PictureButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
ImageIcon picture = new ImageIcon();
imageLabel.setIcon(picture);
imageLabel.setText(null);
pack();
}
}
public static void main(String[] args)
{
new ImageWindow();
}
}