1 |
import java.io.File; |
2 |
import java.io.IOException; |
3 |
import javax.swing.JFileChooser; |
4 |
import javax.swing.JOptionPane; |
5 |
|
6 |
/** |
7 |
A program to test the Caesar cipher encryptor. |
8 |
*/ |
9 |
public class EncryptorTest |
10 |
{ |
11 |
public static void main(String[] args) |
12 |
{ |
13 |
try |
14 |
{ |
15 |
JFileChooser chooser = new JFileChooser(); |
16 |
if (chooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION) System.exit(0); |
17 |
|
18 |
File inFile = chooser.getSelectedFile(); |
19 |
if (chooser.showSaveDialog(null) != JFileChooser.APPROVE_OPTION) System.exit(0); |
20 |
File outFile = chooser.getSelectedFile(); |
21 |
String input = JOptionPane.showInputDialog("Key"); |
22 |
int key = Integer.parseInt(input); |
23 |
Encryptor crypt = new Encryptor(key); |
24 |
crypt.encryptFile(inFile, outFile); |
25 |
} |
26 |
catch (NumberFormatException exception) |
27 |
{ |
28 |
System.out.println("Key must be an integer: " + exception); |
29 |
} |
30 |
catch (IOException exception) |
31 |
{ |
32 |
System.out.println("Error processing file: " + exception); |
33 |
} |
34 |
System.exit(0); |
35 |
} |
36 |
} |