sadjfda
[rmh3093.git] / lab7 / DialogViewer.java,v
blobf1ad40ac2f08a0b6dc2b6ad3e8cb0a257ad678c3
1 head    1.1;
2 access;
3 symbols;
4 locks
5         rmh3093:1.1; strict;
6 comment @# @;
9 1.1
10 date    2008.04.30.14.29.05;    author rmh3093; state Exp;
11 branches;
12 next    ;
15 desc
16 @initial commit
20 1.1
21 log
22 @Initial revision
24 text
25 @/*
26  * DialogViewer.java
27  *
28  * Version:
29  *     $Id$
30  *
31  * Revisions:
32  *     $Log$
33  */
35 import java.awt.*;
36 import java.awt.event.ActionEvent;
37 import java.io.File;
39 import javax.swing.*;
41 public class DialogViewer extends JPanel {
43         public void actionPerformed(ActionEvent e) {
44                 System.out.println(e.getSource().toString());
45     }
46         
47         /**
48          * Create new DialogViewer
49          * @@param type display type
50          */
51         public DialogViewer(char[] type){
52                 int ret;
53                 switch (type[0]) {
54                 case 'f':                       
55                         JFileChooser filechooser = new JFileChooser();
56                         ret = filechooser.showOpenDialog(DialogViewer.this);
57             if (ret == JFileChooser.APPROVE_OPTION) {
58                 File file = filechooser.getSelectedFile();
59                 System.out.println(file.getName());
60             } else {
61                 System.out.println("No file was chosen!");
62             }
63                         break;
64                 case 'c':
65                         JOptionPane confirmation = new JOptionPane();
66                         ret = confirmation.showConfirmDialog(DialogViewer.this, 
67                                         "Are you sure?");
68                         switch (ret) {
69                         case 0: System.out.println("Yes"); break;
70                         case 1: System.out.println("No"); break;
71                         case 2: System.out.println("Cancel"); break;
72                         }
73                         break;
74                 case 'm':
75                         JOptionPane.showMessageDialog(DialogViewer.this, "Ryan Hope");
76                         break;
77                 }
78         }
80         /**
81          * Main loop
82          */
83         public static void main(String args[]) {
84                 if (args.length==1 && args[0].length()==1) {
85                         new DialogViewer(args[0].toCharArray());                        
86                 } else {
87                         System.out.println("Usage: java DialogViewer [f|c|m]");
88                 }
89         }