/Users/lyon/j4p/src/ip/hak/SmallImage.java

1    package ip.hak; 
2     
3    import java.awt.*; 
4    import java.awt.event.MouseEvent; 
5    import java.awt.event.MouseListener; 
6     
7    public class SmallImage extends ImageComponent implements MouseListener { 
8     
9        FileDialog fd; 
10       Image im; 
11       boolean iLoad = false; 
12       int index; 
13    
14       public SmallImage(int w, int h, MyPanel myp, int idx) { 
15           mp = myp; 
16           index = idx; 
17           setSize(w, h); 
18           addMouseListener(this); 
19       } 
20    
21       public Image getResizedImage(int wid, int hei) { 
22           if (im == null) 
23               return null; 
24           Image ni = im.getScaledInstance(wid, hei, Image.SCALE_DEFAULT); 
25           return ni; 
26       } 
27    
28       public void paint(Graphics g) { 
29           super.paint(g); 
30           if (im == null) { 
31               Dimension d = getSize(); 
32               g.drawString("Click", d.width / 2 - 15, d.height / 2 + 5); 
33               return; 
34           } 
35           Dimension d = getSize(); 
36           g.drawImage(im, 0, 0, d.width, d.height, this); 
37           iLoad = true; 
38           mp.setImageSize(im.getWidth(this), im.getHeight(this), index); 
39       } 
40    
41       public void mousePressed(MouseEvent e) { 
42           fd = new FileDialog(new Frame(), "Select Image File", 0); 
43           fd.setVisible(true); 
44           String fname = fd.getFile(); 
45           if (fname == null) 
46               return; 
47           String fdir = fd.getDirectory(); 
48           im = Toolkit.getDefaultToolkit().getImage(fdir + fname); 
49           repaint(); 
50           mp.setImageState(index); 
51           if (index == 1) 
52               mp.makeSmallImageFrame(im); 
53    
54           // if second image 
55           //if (index==1) 
56           //  mp.initPoint(); 
57       } 
58    
59       public void mouseClicked(MouseEvent e) { 
60       } 
61    
62       public void mouseReleased(MouseEvent e) { 
63       } 
64    
65       public void mouseEntered(MouseEvent e) { 
66       } 
67    
68       public void mouseExited(MouseEvent e) { 
69       } 
70   }