/Users/lyon/j4p/src/gui/run/SampleImageApp.java
|
1 package gui.run;
2
3 import java.awt.Graphics;
4 import java.awt.Image;
5 import java.awt.Toolkit;
6
7
8 public class SampleImageApp {
9
10 Image img = null;
11 gui.ClosableJFrame cf = new gui.ClosableJFrame("ImageProcessing Frame"){
12 public void paint(Graphics g){
13 super.paint(g);
14 if (! (img==null))
15 g.drawImage(img, 20, 120, null);
16 }
17 };
18
19
20 public void openImage() {
21 img = getImageFromFile();
22 cf.repaint();
23 }
24 public Image getImageFromFile() {
25 return Toolkit.getDefaultToolkit().getImage(
26 futils.Futil.getReadFileName("please select a gif or jpg file"));
27 }
28 public SampleImageApp() {
29
30 java.awt.Container c = cf.getContentPane();
31
32 javax.swing.JMenuBar mb = new javax.swing.JMenuBar();
33 javax.swing.JMenu fileMenu = new javax.swing.JMenu("File");
34 fileMenu.setMnemonic('F');
35 javax.swing.JMenu hppMenu = new javax.swing.JMenu("Hpp");
36 hppMenu.setMnemonic('h');
37 fileMenu.add(new RunMenuItem("open") {
38 public void run() {
39 openImage();
40 }
41 });
42 hppMenu.add(new RunMenuItem("negate") {
43 public void run() {
44 System.out.println("negate me baby!");
45 }
46 });
47 mb.add(fileMenu);
48 mb.add(hppMenu);
49 cf.setJMenuBar(mb);
50 cf.setSize(200, 200);
51 cf.setVisible(true);
52 }
53
54 public static void main(String args[]) {
55 SampleImageApp om = new SampleImageApp();
56 }
57
58 }