B
Ben Aroia
heres a program that incrypts files. comlpeate with 'regestration',
I/O file writing, and a help menu with a scroll pane. try it out and
tell me how u like it in a posting! no e-mail please!
-Ben
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.util.*;
public class joshFinalUnit16 extends JFrame
{
//Creates a new menu bar
JMenuBar bar=new JMenuBar();
//Menus to add to the menu bar
//Menu 1
JMenu m1=new JMenu("Encryption");
//Menu 2
JMenu m2=new JMenu("File");
//Menu 3
JMenu m3=new JMenu("Exit");
//Menu 4
JMenu m4=new JMenu("About");
//Menu items to add to the menus on the menu bar
//Menu 1 Items
JMenuItem m1i1=new JMenuItem("New Encryption sequence");
JMenuItem m1i2=new JMenuItem("Encrypt file");
JMenuItem m1i3=new JMenuItem("Decrypt file");
JMenuItem m1i4=new JMenuItem("Help");
//Menu 2 Items
JMenuItem m2i1=new JMenuItem("Set input encrypt file");
JMenuItem m2i2=new JMenuItem("Set output encrypt file");
JMenuItem m2i3=new JMenuItem("Set input decrypt file");
JMenuItem m2i4=new JMenuItem("Set output decrypt file");
JMenuItem m2i5=new JMenuItem("Save Log");
//Menu 3 Items
JMenuItem m3i1=new JMenuItem("Quit");
//Menu 4 Items
JMenuItem m4i1=new JMenuItem("About");
JMenuItem m4i2=new JMenuItem("Dedications");
static JMenuItem m4i3=new JMenuItem("Register Now!");
//Variables
//Booleans
public static boolean ss=false;
public static boolean reg=false;
public boolean time=true;
public static boolean ter=false;
//Strings
String sEnc,fromE,toE,fromD,toD;
public static String address,name,city,code,state;
//Ints
int encrypt;
//Check boxes
JCheckBox showTime=new JCheckBox("Show time",true);
//Buttons
JButton clear=new JButton("Clear all");
//ScrollPanes
ScrollPane encryptedScroll=new ScrollPane();
ScrollPane decryptedScroll=new ScrollPane();
//Text
JTextArea encrypted=new JTextArea(285,350);
JTextArea decrypted=new JTextArea(285,350);
//Labels
JLabel l1= new JLabel("Encrpted file log:");
JLabel l2=new JLabel("Decrypted file log:");
//Main part of program
public static void main(String [] a)
{
//Creates a new frame
joshFinalUnit16 frame=new joshFinalUnit16();
//Sets is visible
if(ter==false)
{
frame.setVisible(true);
}
}
public joshFinalUnit16()
{
//Calls the super method of the JFrame class
super("EncryptoPro!");
//Query the user on wether or not they want to agree to the
statement
int af=JOptionPane.showConfirmDialog(null,"EncryptoPro!\nThis
program is licenced under Programmers, Inc. and may not be duped,
\ntransfered, or copied unless"+
" otherwise said in written form. Do you agreee to the above?
\n(c)2004 Programmers, Inc.");
//If they selected 'yes' then do the following
if(af==0)
{
setSize(450,500);
ActionListener list=new ChoiceListener();
setResizable(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Container pane=getContentPane();
GridLayout grid=new GridLayout(6,1);
pane.setLayout(grid);
bar=new JMenuBar();
setJMenuBar(bar);
pane.add(l1);
bar.add(m1);
bar.add(m2);
bar.add(m4);
bar.add(m3);
bar.setVisible(true);
m1.add(m1i1);
m1.addSeparator();
m1.add(m1i2);
m1.add(m1i3);
m1.addSeparator();
m1.add(m1i4);
m1i4.addActionListener(list);
m1i3.addActionListener(list);
m1i2.addActionListener(list);
m1i1.addActionListener(list);
m2.add(m2i1);
m2.add(m2i2);
m2.addSeparator();
m2.add(m2i3);
m2.add(m2i4);
m2.addSeparator();
m2.add(m2i5);
m2i5.addActionListener(list);
m2i4.addActionListener(list);
m2i3.addActionListener(list);
m2i2.addActionListener(list);
m2i1.addActionListener(list);
m3.add(m3i1);
m3i1.addActionListener(list);
m4.add(m4i1);
m4.addSeparator();
m4.add(m4i2);
m4.addSeparator();
m4.add(m4i3);
m4i1.addActionListener(list);
m4i2.addActionListener(list);
m4i3.addActionListener(list);
pane.add(encryptedScroll);
encryptedScroll.add(encrypted);
encryptedScroll.setSize(285,350);
pane.add(l2);
pane.add(decryptedScroll);
decryptedScroll.setSize(285,350);
decryptedScroll.add(decrypted);
pane.add(clear);
clear.addActionListener(list);
encrypted.setEditable(false);
encryptedScroll.setVisible(true);
decryptedScroll.setVisible(true);
decrypted.setEditable(false);
pane.add(showTime);
showTime.addActionListener(list);
setContentPane(pane);
pane.setVisible(true);
}
//Otherwise
else
{
JOptionPane.showMessageDialog(null,"Program was termanated");
ter=true;
}
}
//Method for decrypting a file
public void decryptFile(String f, String t, int e)
{
int INTERFERENCE=1;
int RANDOMBYTE=e;
try{
//New file
File song=new File(f);
//Input stream
FileInputStream file=new FileInputStream(song);
File trashedSong=new File(t);
//Output stream
FileOutputStream trash=new FileOutputStream(trashedSong);
int count=0;
boolean eof=false;
JOptionPane.showMessageDialog(null,"Creating file...");
while(!eof)
{
//Read the next byte in the file
int input=file.read();
//When it reaches the end of a file, a value of -1 is returned.
//So if the input is -1 then end the loop
if(input==-1)
{
eof=true;
//Return to start of loop
continue;
}
//If not the end of file...
else
{
count++;
if(count%INTERFERENCE==0)
{
int newInput=input-RANDOMBYTE;
if(newInput>255)
{
newInput=newInput+255;
}
//Write to file
trash.write(newInput);
}
}
}
//Close files
file.close();
trash.close();
//Tell the user that the process is done
JOptionPane.showMessageDialog(null,"Done");
//Catch any thrown exceptions
}catch(Exception r)
{
JOptionPane.showMessageDialog(null,"Error-"+r.toString());
}
}
//Method to encrypt file
public void encryptFile(String f, String t, int e)
{
int INTERFERENCE=1;
int RANDOMBYTE=e;
try{
File song=new File(f);
FileInputStream file=new FileInputStream(song);
File trashedSong=new File(t);
FileOutputStream trash=new FileOutputStream(trashedSong);
int count=0;
boolean eof=false;
JOptionPane.showMessageDialog(null,"Creating file...");
while(!eof)
{
int input=file.read();
if(input==-1)
{
eof=true;
continue;
}
else
{
count++;
if(count%INTERFERENCE==0)
{
int newInput=input+RANDOMBYTE;
if(newInput>255)
{
newInput=newInput-255;
}
trash.write(newInput);
}
}
}
file.close();
trash.close();
JOptionPane.showMessageDialog(null,"Done");
}catch(Exception d)
{
JOptionPane.showMessageDialog(null,"Error-"+d.toString());
}
}
//Method to disable item 3 in menu 4 to
public static void setReg()
{
m4i3.setEnabled(false);
}
//Method to save the log to a file
public void save(String aFile)
{
try
{
JOptionPane.showMessageDialog(null,"Saving file...");
File out=new File(aFile);
FileOutputStream outFile=new FileOutputStream(aFile);
boolean eof=false;
//Gets text from the text areas
String input=encrypted.getText()+" "+decrypted.getText();
//Takes the String area and make it a char area
char [] cha=input.toCharArray();
byte x;
x=0;
for(int i=0;i<cha.length;i++)
{
//If the end of one log entry is reached, insert a carrage return
if(cha=='~')
{
outFile.write(13);
}
else
{
//Use the utility to make a byte out if a char
outFile.write(utility.toByte(cha));
}
}
JOptionPane.showMessageDialog(null,"Done.");
}catch(Exception e)
{
JOptionPane.showMessageDialog(null,"Error-"+e.toString());
}
}
//Yes! a class within a class
private class ChoiceListener implements ActionListener
{
//Method called when something is clicked, checked or otherwise
changed
public void actionPerformed(ActionEvent evn)
{
//Gets the source of the event (what caused it)
Object evt=evn.getSource();
//If it is the check box, change the boolean variable time to
//the opisite.
if(evt==showTime)
{
time=!time;
}
//menu 1, item 4
if(evt==m1i4)
{
//Creats a new help window
helpWin newhelp=new helpWin();
newhelp.setVisible(true);
}
//menu 4,item 3
if(evt==m4i3)
{
//Creats a new register window
regester newreg=new regester();
newreg.setVisible(true);
}
//Menu 2, Item 5
if(evt==m2i5)
{
String saveFile=JOptionPane.showInputDialog("Please type the name
of the file you wish to save to.");
save(saveFile);
}
//Menu 4, Item 2
if(evt==m4i2)
{
JOptionPane.showMessageDialog(null,"Dedicated to Mr. Smith,\nMy
Java teacher.");
}
//Menu 4, Item 1
if(evt==m4i1)
{
//Lots and lots of backup code that i am to lazy to explain right
now
if(reg==true&&ss==false)
{
int ans=JOptionPane.showConfirmDialog(null,"Data was not
subbmitted properly on the registraion form. \n"+
"Do you wish to re-regester?");
if(ans==0)
{
regester win=new regester();
win.setVisible(true);
}
if(ans==1||ans==2)
{
JOptionPane.showMessageDialog(null,"EncryptoPro!\nVersion 1.1
\nUnregistered version\n(c)2004 Programmers, Inc.");
}
}
if(reg==true&&ss==true)
{
JOptionPane.showMessageDialog(null,code+"\nEncryptoPro!\nVersion
1.1 "+
"Registered Version to\n"+
name+"\n"+address+"\n"+city+" "+state+
"\n(c)2004 Programmers, Inc.");
}
if(reg==false)
{
JOptionPane.showMessageDialog(null,"EncryptoPro!\nVersion 1.1
\nUnregistered version\n(c)2004 Programmers, Inc.");
}
}
//Clear button
if(evt==clear)
{
//If there is something in one of the fields
if(encrypted.getText().length()>0||decrypted.getText().length()>0)
{
//Query the user
int answer=JOptionPane.showConfirmDialog(null,"Are you sure you
want to clear ALL records? (You cannot undo this)");
//Find out what he clicked
if(answer==0)
{
encrypted.setText(null);
decrypted.setText(null);
}
else
{
//do nothing
}
}
else
{
JOptionPane.showMessageDialog(null,"Sorry. There are no records
to delete.");
}
}
//Menu 1, Item 1
if(evt==m1i1)
{
//New integer for encryption
sEnc=JOptionPane.showInputDialog("Please enter new integer.");
encrypt=Integer.parseInt(sEnc);
}
//Menu 1, Item 2
if(evt==m1i2)
{
if(fromE.length()>0 && toE.length()>0)
{
//More useless code that nevertheless makes up a substantiol part
of the program
encryptFile(fromE,toE,encrypt);
JOptionPane.showMessageDialog(null,"File has been successfully
encrypted.");
if(time==true)
{
Calendar cal=Calendar.getInstance();
encrypted.setText(encrypted.getText()+"\nFile succesfully
encrypted: "+fromE+" to "+toE+" at: "+
cal.getTime()+"~");
}
if(time==false)
{
encrypted.setText(encrypted.getText()+"\nFile succesfully
encrypted: "+fromE+" to "+toE+"~");
}
}
else
{
JOptionPane.showMessageDialog(null,"There has been an error in
encrypting the file: File specified could not be found.");
}
}
//Menu 1, Item 3
if(evt==m1i3)
{
//Etc...
if(fromD.length()>0 && toD.length()>0)
{
decryptFile(fromD,toD,encrypt);
JOptionPane.showMessageDialog(null,"File has been successfully
decrypted.");
if(time==true)
{
Calendar cal=Calendar.getInstance();
decrypted.setText(decrypted.getText()+("\nFile succsesfully
decrypted: "+fromD+" to "+toD+" at: "+
cal.getTime()+"~"));
}
if(time==false)
{
decrypted.setText(decrypted.getText()+"\nFile succesfully
decrypted: "+fromD+" to "+toD+"~");
}
}
else
{
JOptionPane.showMessageDialog(null, "There has been an error in
decrypting the file: File specified could not be found.");
}
}
//Menu 2, Item 1
if(evt==m2i1)
{
//Specifies a new input encryption file
fromE=JOptionPane.showInputDialog("Please enter a new input
encryption file.");
}
//Menu 2, Item 2
if(evt==m2i2)
{
//New out put file
toE=JOptionPane.showInputDialog("Please enter a new output
encryption file.");
}
//Menu 2, Item 3
if(evt==m2i3)
{
fromD=JOptionPane.showInputDialog("Please enter a new input
decryption file.");
}
//Menu 2, Item 4
if(evt==m2i4)
{
toD=JOptionPane.showInputDialog("Please enter a new output
decryption file.");
}
//Menu 3, Item 1
if(evt==m3i1)
{
//Quiting Query
int answer=JOptionPane.showConfirmDialog(null,"Are you sure you
want to quit?");
if(answer==0)
{
exit1.exit(0);
}
if(answer==1)
{
JOptionPane.showMessageDialog(null,"Exit termanated by user");
}
if(answer==2)
{
//do nothing
}
}
}
}
}
import java.awt.*;
import java.awt.Event.*;
import javax.swing.*;
public class helpWin extends JFrame
{
ScrollPane helptxt= new ScrollPane();
JTextArea hp=new JTextArea();
String helpText="To encrypt a file: \n"+
" 1. Set the input encrypt file to \n"+
"the desired file for encryption. \n"+
" 2. Set the output encrypt file to \n"+
"the desired file name. This will be \n"+
"the name of the encrypted file. \n"+
" 3. Set the encryption sequence \n"+
"to the desired level of encryption \n"+
"security. (1-100 1 being the lowest \n"+
"and 100 being the highest.) \n"+
" 4. Click \"Encrypt file\" to begin\n"+
"encryption.\n"+
"To decrypt a file: \n"+
" 1. Set the input decryption file \n"+
"to the desired file for decryption. \n"+
" 2. Set the output decryption file \n"+
"to the desired file name. This will \n"+
"be the name of the decrypted file. \n"+
" 3. Make sure that the current \n"+
"level of encryption security matches \n"+
"that of the file for decryption. THIS\n"+
"IS VERY IMPORTENT! If the numbers do \n"+
"not match, the file will not be \n"+
"decrypted correctly! It is advisable\n"+
"you keep a written record of the file\n"+
"names and the encryption security. \n"+
" 4. Click \"Decrypt file\" to begin\n"+
"decryption. \n"+
"To regester: \n"+
" 1. Click Regester Now! under the \n"+
"about menu to regester. \n"+
" 2. Fill-in ALL fields. \n"+
" 3. Click the Submit button. \n"+
" 4. Close the window. \n"+
" 5. The program is now regestered. \n"+
"This program and all included \n"+
"documents (c)2004 Programmers,Inc. \n";
public helpWin()
{
super("EncryptoPro! Help window");
setSize(350,350);
Container pane=getContentPane();
FlowLayout flow=new FlowLayout();
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
pane.setLayout(flow);
pane.add(helptxt);
helptxt.add(hp);
hp.setText(helpText);
hp.setEditable(false);
hp.setVisible(true);
helptxt.setSize(325,325);
helptxt.setVisible(true);
pane.setVisible(true);
setResizable(false);
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class regester extends JFrame
{
JLabel name=new JLabel("Name");
JTextField namet=new JTextField();
JLabel code=new JLabel("Registration code");
JTextField codet=new JTextField();
JLabel address=new JLabel("Address");
JTextField addresst=new JTextField();
JLabel state=new JLabel("State");
JTextField statet=new JTextField();
JLabel city=new JLabel("City");
JTextField cityt=new JTextField();
JLabel phone=new JLabel("Phone");
JTextField phonet=new JTextField();
JLabel cardtype=new JLabel("Card type");
JTextField cardtypet=new JTextField();
JLabel carddate=new JLabel("Card exparation date");
JTextField carddatet=new JTextField();
JLabel cardnum=new JLabel("Credit card number");
JTextField cardnumt=new JTextField();
JButton clear=new JButton("Clear all");
JButton submit=new JButton("Submit");
JButton cancel=new JButton("Cancel");
public regester()
{
super("Registration");
setSize(325,350);
GridLayout grid=new GridLayout(0,2);
Container pane=getContentPane();
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
ActionListener listener= new ChoiceListener();
pane.setLayout(grid);
pane.setVisible(true);
pane.add(name);
pane.add(namet);
namet.addActionListener(listener);
pane.add(code);
pane.add(codet);
codet.addActionListener(listener);
pane.add(address);
pane.add(addresst);
addresst.addActionListener(listener);
pane.add(city);
pane.add(cityt);
cityt.addActionListener(listener);
pane.add(state);
pane.add(statet);
statet.addActionListener(listener);
pane.add(phone);
pane.add(phonet);
phonet.addActionListener(listener);
pane.add(cardtype);
pane.add(cardtypet);
cardtypet.addActionListener(listener);
pane.add(carddate);
pane.add(carddatet);
carddatet.addActionListener(listener);
pane.add(cardnum);
pane.add(cardnumt);
cardnumt.addActionListener(listener);
pane.add(clear);
clear.setEnabled(false);
clear.addActionListener(listener);
pane.add(submit);
pane.add(cancel);
cancel.addActionListener(listener);
submit.setEnabled(false);
submit.addActionListener(listener);
}
public void clearAllFields() // method
{
codet.setText(null);
codet.setForeground(Color.black);
statet.setText(null);
statet.setForeground(Color.black);
cityt.setText(null);
cityt.setForeground(Color.black);
phonet.setText(null);
phonet.setForeground(Color.black);
cardtypet.setText(null);
cardtypet.setForeground(Color.black);
cardnumt.setText(null);
cardnumt.setForeground(Color.black);
carddatet.setText(null);
carddatet.setForeground(Color.black);
namet.setText(null);// clears the text from the text field
namet.setForeground(Color.black);// sets the text color to black
addresst.setText(null);
addresst.setForeground(Color.black);
clear.setEnabled(false);// disables the clear button
submit.setEnabled(false);
}
public void setClose()
{
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public static void main(String [] a)
{
regester n=new regester();
n.setVisible(true);
}
private class ChoiceListener implements ActionListener
{
public void actionPerformed(ActionEvent evn)
{
Object x=evn.getSource();
if(x==cancel||x==clear||x==namet||x==codet||x==addresst||x==statet||x==cityt||x==phonet||x==carddatet||x==cardtype||x==cardnumt||x==submit)
{
if(x==namet||x==codet||x==addresst||x==statet||x==cityt||x==phonet||x==carddatet||x==cardtype||x==cardnumt)
{
clear.setEnabled(true);
submit.setEnabled(true);
}
if(x==submit)
{
boolean cleared=false;
if(namet.getText().length()>0&&codet.getText().length()>0&&
statet.getText().length()>0&&cityt.getText().length()>0&&
phonet.getText().length()>0&&carddate.getText().length()>0&&
cardnum.getText().length()>0&&cardtype.getText().length()>0)
{
joshFinalUnit16.reg=true;
joshFinalUnit16.ss=true;
joshFinalUnit16.name=namet.getText().trim();
joshFinalUnit16.code=codet.getText().trim();
joshFinalUnit16.address=addresst.getText().trim();
joshFinalUnit16.city=cityt.getText().trim();
joshFinalUnit16.state=statet.getText().trim();
joshFinalUnit16.setReg();
namet.setEnabled(false);
name.setEnabled(false);
codet.setEnabled(false);
code.setEnabled(false);
statet.setEnabled(false);
addresst.setEnabled(false);
address.setEnabled(false);
cityt.setEnabled(false);
city.setEnabled(false);
state.setEnabled(false);
phonet.setEnabled(false);
phone.setEnabled(false);
carddatet.setEnabled(false);
carddate.setEnabled(false);
cardtypet.setEnabled(false);
cardtype.setEnabled(false);
cardnumt.setEnabled(false);
cardnum.setEnabled(false);
setClose();
clearAllFields();
cleared=true;
setVisible(false);
}
else
{
JOptionPane.showMessageDialog(null,"One or more of the fields
are empty. Please fill them in and ");
}
}
if(x==cancel)
{
namet.setEnabled(false);
name.setEnabled(false);
codet.setEnabled(false);
code.setEnabled(false);
statet.setEnabled(false);
state.setEnabled(false);
phonet.setEnabled(false);
phone.setEnabled(false);
carddatet.setEnabled(false);
carddate.setEnabled(false);
cardtypet.setEnabled(false);
cardtype.setEnabled(false);
cardnumt.setEnabled(false);
cardnum.setEnabled(false);
setClose();
joshFinalUnit16.reg=true;
setVisible(false);
}
if(x==clear)
{
clearAllFields();
}
}
}
}
}
import java.io.*;
import javax.swing.*;
public class utility
{
public static byte toByte(char x)
{
byte t=0;
if(x==' ')
{
t=32;
}
else if(x=='!')
{
t=33;
}
else if(x=='"')
{
t=34;
}
else if(x=='#')
{
t=35;
}
else if(x=='$')
{
t=36;
}
else if(x=='%')
{
t=37;
}
else if(x=='&')
{
t=38;
}
else if(x=='\'')
{
t=39;
}
else if(x=='(')
{
t=40;
}
else if(x==')')
{
t=41;
}
else if(x=='*')
{
t=42;
}
else if(x=='+')
{
t=43;
}
else if(x==',')
{
t=44;
}
else if(x=='-')
{
t=45;
}
else if(x=='.')
{
t=46;
}
else if(x=='/')
{
t=47;
}
else if(x=='0')
{
t=48;
}
else if(x=='1')
{
t=49;
}
else if(x=='2')
{
t=50;
}
else if(x=='3')
{
t=51;
}
else if(x=='4')
{
t=52;
}
else if(x=='5')
{
t=53;
}
else if(x=='6')
{
t=54;
}
else if(x=='7')
{
t=55;
}
else if(x=='8')
{
t=56;
}
else if(x=='9')
{
t=57;
}
else if(x==':')
{
t=58;
}
else if(x==';')
{
t=59;
}
else if(x=='<')
{
t=60;
}
else if(x=='=')
{
t=61;
}
else if(x=='>')
{
t=62;
}
else if(x=='?')
{
t=63;
}
else if(x=='@')
{
t=64;
}
else if(x=='A')
{
t=65;
}
else if(x=='B')
{
t=66;
}
else if(x=='C')
{
t=67;
}
else if(x=='D')
{
t=68;
}
else if(x=='E')
{
t=69;
}
else if(x=='F')
{
t=70;
}
else if(x=='G')
{
t=71;
}
else if(x=='H')
{
t=72;
}
else if(x=='I')
{
t=73;
}
else if(x=='J')
{
t=74;
}
else if(x=='K')
{
t=75;
}
else if(x=='L')
{
t=76;
}
else if(x=='M')
{
t=77;
}
else if(x=='N')
{
t=78;
}
else if(x=='O')
{
t=79;
}
else if(x=='P')
{
t=80;
}
else if(x=='Q')
{
t=81;
}
else if(x=='R')
{
t=82;
}
else if(x=='S')
{
t=83;
}
else if(x=='T')
{
t=84;
}
else if(x=='U')
{
t=85;
}
else if(x=='V')
{
t=86;
}
else if(x=='W')
{
t=87;
}
else if(x=='X')
{
t=88;
}
else if(x=='Y')
{
t=89;
}
else if(x=='Z')
{
t=90;
}
else if(x=='[')
{
t=91;
}
else if(x==']')
{
t=92;
}
else if(x=='\\')
{
t=93;
}
else if(x=='^')
{
t=94;
}
else if(x=='_')
{
t=95;
}
else if(x=='`')
{
t=96;
}
else if(x=='a')
{
t=97;
}
else if(x=='b')
{
t=98;
}
else if(x=='c')
{
t=99;
}
else if(x=='d')
{
t=100;
}
else if(x=='e')
{
t=101;
}
else if(x=='f')
{
t=102;
}
else if(x=='g')
{
t=103;
}
else if(x=='h')
{
t=104;
}
else if(x=='i')
{
t=105;
}
else if(x=='j')
{
t=106;
}
else if(x=='k')
{
t=107;
}
else if(x=='l')
{
t=108;
}
else if(x=='m')
{
t=109;
}
else if(x=='n')
{
t=110;
}
else if(x=='o')
{
t=111;
}
else if(x=='p')
{
t=112;
}
else if(x=='q')
{
t=113;
}
else if(x=='r')
{
t=114;
}
else if(x=='s')
{
t=115;
}
else if(x=='t')
{
t=116;
}
else if(x=='u')
{
t=117;
}
else if(x=='v')
{
t=118;
}
else if(x=='w')
{
t=119;
}
else if(x=='x')
{
t=120;
}
else if(x=='y')
{
t=121;
}
else if(x=='z')
{
t=122;
}
else if(x=='{')
{
t=123;
}
else if(x=='|')
{
t=124;
}
else if(x=='}')
{
t=125;
}
else if(x=='~')
{
t=126;
}
return(t);
}
public static void save(String aFile, String input)
{
try
{
JOptionPane.showMessageDialog(null,"Saving file...");
File out=new File(aFile);
FileOutputStream outFile=new FileOutputStream(aFile);
boolean eof=false;
//Takes the String area and make it a char area
char [] cha=input.toCharArray();
byte x;
x=0;
for(int i=0;i<cha.length;i++)
{
if(cha=='œ')
outFile.write(13);
else
outFile.write(toByte(cha));
}
JOptionPane.showMessageDialog(null,"Done.");
}catch(Exception e)
{
JOptionPane.showMessageDialog(null,"Error-"+e.toString());
}
}
}
I/O file writing, and a help menu with a scroll pane. try it out and
tell me how u like it in a posting! no e-mail please!
-Ben
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.util.*;
public class joshFinalUnit16 extends JFrame
{
//Creates a new menu bar
JMenuBar bar=new JMenuBar();
//Menus to add to the menu bar
//Menu 1
JMenu m1=new JMenu("Encryption");
//Menu 2
JMenu m2=new JMenu("File");
//Menu 3
JMenu m3=new JMenu("Exit");
//Menu 4
JMenu m4=new JMenu("About");
//Menu items to add to the menus on the menu bar
//Menu 1 Items
JMenuItem m1i1=new JMenuItem("New Encryption sequence");
JMenuItem m1i2=new JMenuItem("Encrypt file");
JMenuItem m1i3=new JMenuItem("Decrypt file");
JMenuItem m1i4=new JMenuItem("Help");
//Menu 2 Items
JMenuItem m2i1=new JMenuItem("Set input encrypt file");
JMenuItem m2i2=new JMenuItem("Set output encrypt file");
JMenuItem m2i3=new JMenuItem("Set input decrypt file");
JMenuItem m2i4=new JMenuItem("Set output decrypt file");
JMenuItem m2i5=new JMenuItem("Save Log");
//Menu 3 Items
JMenuItem m3i1=new JMenuItem("Quit");
//Menu 4 Items
JMenuItem m4i1=new JMenuItem("About");
JMenuItem m4i2=new JMenuItem("Dedications");
static JMenuItem m4i3=new JMenuItem("Register Now!");
//Variables
//Booleans
public static boolean ss=false;
public static boolean reg=false;
public boolean time=true;
public static boolean ter=false;
//Strings
String sEnc,fromE,toE,fromD,toD;
public static String address,name,city,code,state;
//Ints
int encrypt;
//Check boxes
JCheckBox showTime=new JCheckBox("Show time",true);
//Buttons
JButton clear=new JButton("Clear all");
//ScrollPanes
ScrollPane encryptedScroll=new ScrollPane();
ScrollPane decryptedScroll=new ScrollPane();
//Text
JTextArea encrypted=new JTextArea(285,350);
JTextArea decrypted=new JTextArea(285,350);
//Labels
JLabel l1= new JLabel("Encrpted file log:");
JLabel l2=new JLabel("Decrypted file log:");
//Main part of program
public static void main(String [] a)
{
//Creates a new frame
joshFinalUnit16 frame=new joshFinalUnit16();
//Sets is visible
if(ter==false)
{
frame.setVisible(true);
}
}
public joshFinalUnit16()
{
//Calls the super method of the JFrame class
super("EncryptoPro!");
//Query the user on wether or not they want to agree to the
statement
int af=JOptionPane.showConfirmDialog(null,"EncryptoPro!\nThis
program is licenced under Programmers, Inc. and may not be duped,
\ntransfered, or copied unless"+
" otherwise said in written form. Do you agreee to the above?
\n(c)2004 Programmers, Inc.");
//If they selected 'yes' then do the following
if(af==0)
{
setSize(450,500);
ActionListener list=new ChoiceListener();
setResizable(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Container pane=getContentPane();
GridLayout grid=new GridLayout(6,1);
pane.setLayout(grid);
bar=new JMenuBar();
setJMenuBar(bar);
pane.add(l1);
bar.add(m1);
bar.add(m2);
bar.add(m4);
bar.add(m3);
bar.setVisible(true);
m1.add(m1i1);
m1.addSeparator();
m1.add(m1i2);
m1.add(m1i3);
m1.addSeparator();
m1.add(m1i4);
m1i4.addActionListener(list);
m1i3.addActionListener(list);
m1i2.addActionListener(list);
m1i1.addActionListener(list);
m2.add(m2i1);
m2.add(m2i2);
m2.addSeparator();
m2.add(m2i3);
m2.add(m2i4);
m2.addSeparator();
m2.add(m2i5);
m2i5.addActionListener(list);
m2i4.addActionListener(list);
m2i3.addActionListener(list);
m2i2.addActionListener(list);
m2i1.addActionListener(list);
m3.add(m3i1);
m3i1.addActionListener(list);
m4.add(m4i1);
m4.addSeparator();
m4.add(m4i2);
m4.addSeparator();
m4.add(m4i3);
m4i1.addActionListener(list);
m4i2.addActionListener(list);
m4i3.addActionListener(list);
pane.add(encryptedScroll);
encryptedScroll.add(encrypted);
encryptedScroll.setSize(285,350);
pane.add(l2);
pane.add(decryptedScroll);
decryptedScroll.setSize(285,350);
decryptedScroll.add(decrypted);
pane.add(clear);
clear.addActionListener(list);
encrypted.setEditable(false);
encryptedScroll.setVisible(true);
decryptedScroll.setVisible(true);
decrypted.setEditable(false);
pane.add(showTime);
showTime.addActionListener(list);
setContentPane(pane);
pane.setVisible(true);
}
//Otherwise
else
{
JOptionPane.showMessageDialog(null,"Program was termanated");
ter=true;
}
}
//Method for decrypting a file
public void decryptFile(String f, String t, int e)
{
int INTERFERENCE=1;
int RANDOMBYTE=e;
try{
//New file
File song=new File(f);
//Input stream
FileInputStream file=new FileInputStream(song);
File trashedSong=new File(t);
//Output stream
FileOutputStream trash=new FileOutputStream(trashedSong);
int count=0;
boolean eof=false;
JOptionPane.showMessageDialog(null,"Creating file...");
while(!eof)
{
//Read the next byte in the file
int input=file.read();
//When it reaches the end of a file, a value of -1 is returned.
//So if the input is -1 then end the loop
if(input==-1)
{
eof=true;
//Return to start of loop
continue;
}
//If not the end of file...
else
{
count++;
if(count%INTERFERENCE==0)
{
int newInput=input-RANDOMBYTE;
if(newInput>255)
{
newInput=newInput+255;
}
//Write to file
trash.write(newInput);
}
}
}
//Close files
file.close();
trash.close();
//Tell the user that the process is done
JOptionPane.showMessageDialog(null,"Done");
//Catch any thrown exceptions
}catch(Exception r)
{
JOptionPane.showMessageDialog(null,"Error-"+r.toString());
}
}
//Method to encrypt file
public void encryptFile(String f, String t, int e)
{
int INTERFERENCE=1;
int RANDOMBYTE=e;
try{
File song=new File(f);
FileInputStream file=new FileInputStream(song);
File trashedSong=new File(t);
FileOutputStream trash=new FileOutputStream(trashedSong);
int count=0;
boolean eof=false;
JOptionPane.showMessageDialog(null,"Creating file...");
while(!eof)
{
int input=file.read();
if(input==-1)
{
eof=true;
continue;
}
else
{
count++;
if(count%INTERFERENCE==0)
{
int newInput=input+RANDOMBYTE;
if(newInput>255)
{
newInput=newInput-255;
}
trash.write(newInput);
}
}
}
file.close();
trash.close();
JOptionPane.showMessageDialog(null,"Done");
}catch(Exception d)
{
JOptionPane.showMessageDialog(null,"Error-"+d.toString());
}
}
//Method to disable item 3 in menu 4 to
public static void setReg()
{
m4i3.setEnabled(false);
}
//Method to save the log to a file
public void save(String aFile)
{
try
{
JOptionPane.showMessageDialog(null,"Saving file...");
File out=new File(aFile);
FileOutputStream outFile=new FileOutputStream(aFile);
boolean eof=false;
//Gets text from the text areas
String input=encrypted.getText()+" "+decrypted.getText();
//Takes the String area and make it a char area
char [] cha=input.toCharArray();
byte x;
x=0;
for(int i=0;i<cha.length;i++)
{
//If the end of one log entry is reached, insert a carrage return
if(cha=='~')
{
outFile.write(13);
}
else
{
//Use the utility to make a byte out if a char
outFile.write(utility.toByte(cha));
}
}
JOptionPane.showMessageDialog(null,"Done.");
}catch(Exception e)
{
JOptionPane.showMessageDialog(null,"Error-"+e.toString());
}
}
//Yes! a class within a class
private class ChoiceListener implements ActionListener
{
//Method called when something is clicked, checked or otherwise
changed
public void actionPerformed(ActionEvent evn)
{
//Gets the source of the event (what caused it)
Object evt=evn.getSource();
//If it is the check box, change the boolean variable time to
//the opisite.
if(evt==showTime)
{
time=!time;
}
//menu 1, item 4
if(evt==m1i4)
{
//Creats a new help window
helpWin newhelp=new helpWin();
newhelp.setVisible(true);
}
//menu 4,item 3
if(evt==m4i3)
{
//Creats a new register window
regester newreg=new regester();
newreg.setVisible(true);
}
//Menu 2, Item 5
if(evt==m2i5)
{
String saveFile=JOptionPane.showInputDialog("Please type the name
of the file you wish to save to.");
save(saveFile);
}
//Menu 4, Item 2
if(evt==m4i2)
{
JOptionPane.showMessageDialog(null,"Dedicated to Mr. Smith,\nMy
Java teacher.");
}
//Menu 4, Item 1
if(evt==m4i1)
{
//Lots and lots of backup code that i am to lazy to explain right
now
if(reg==true&&ss==false)
{
int ans=JOptionPane.showConfirmDialog(null,"Data was not
subbmitted properly on the registraion form. \n"+
"Do you wish to re-regester?");
if(ans==0)
{
regester win=new regester();
win.setVisible(true);
}
if(ans==1||ans==2)
{
JOptionPane.showMessageDialog(null,"EncryptoPro!\nVersion 1.1
\nUnregistered version\n(c)2004 Programmers, Inc.");
}
}
if(reg==true&&ss==true)
{
JOptionPane.showMessageDialog(null,code+"\nEncryptoPro!\nVersion
1.1 "+
"Registered Version to\n"+
name+"\n"+address+"\n"+city+" "+state+
"\n(c)2004 Programmers, Inc.");
}
if(reg==false)
{
JOptionPane.showMessageDialog(null,"EncryptoPro!\nVersion 1.1
\nUnregistered version\n(c)2004 Programmers, Inc.");
}
}
//Clear button
if(evt==clear)
{
//If there is something in one of the fields
if(encrypted.getText().length()>0||decrypted.getText().length()>0)
{
//Query the user
int answer=JOptionPane.showConfirmDialog(null,"Are you sure you
want to clear ALL records? (You cannot undo this)");
//Find out what he clicked
if(answer==0)
{
encrypted.setText(null);
decrypted.setText(null);
}
else
{
//do nothing
}
}
else
{
JOptionPane.showMessageDialog(null,"Sorry. There are no records
to delete.");
}
}
//Menu 1, Item 1
if(evt==m1i1)
{
//New integer for encryption
sEnc=JOptionPane.showInputDialog("Please enter new integer.");
encrypt=Integer.parseInt(sEnc);
}
//Menu 1, Item 2
if(evt==m1i2)
{
if(fromE.length()>0 && toE.length()>0)
{
//More useless code that nevertheless makes up a substantiol part
of the program
encryptFile(fromE,toE,encrypt);
JOptionPane.showMessageDialog(null,"File has been successfully
encrypted.");
if(time==true)
{
Calendar cal=Calendar.getInstance();
encrypted.setText(encrypted.getText()+"\nFile succesfully
encrypted: "+fromE+" to "+toE+" at: "+
cal.getTime()+"~");
}
if(time==false)
{
encrypted.setText(encrypted.getText()+"\nFile succesfully
encrypted: "+fromE+" to "+toE+"~");
}
}
else
{
JOptionPane.showMessageDialog(null,"There has been an error in
encrypting the file: File specified could not be found.");
}
}
//Menu 1, Item 3
if(evt==m1i3)
{
//Etc...
if(fromD.length()>0 && toD.length()>0)
{
decryptFile(fromD,toD,encrypt);
JOptionPane.showMessageDialog(null,"File has been successfully
decrypted.");
if(time==true)
{
Calendar cal=Calendar.getInstance();
decrypted.setText(decrypted.getText()+("\nFile succsesfully
decrypted: "+fromD+" to "+toD+" at: "+
cal.getTime()+"~"));
}
if(time==false)
{
decrypted.setText(decrypted.getText()+"\nFile succesfully
decrypted: "+fromD+" to "+toD+"~");
}
}
else
{
JOptionPane.showMessageDialog(null, "There has been an error in
decrypting the file: File specified could not be found.");
}
}
//Menu 2, Item 1
if(evt==m2i1)
{
//Specifies a new input encryption file
fromE=JOptionPane.showInputDialog("Please enter a new input
encryption file.");
}
//Menu 2, Item 2
if(evt==m2i2)
{
//New out put file
toE=JOptionPane.showInputDialog("Please enter a new output
encryption file.");
}
//Menu 2, Item 3
if(evt==m2i3)
{
fromD=JOptionPane.showInputDialog("Please enter a new input
decryption file.");
}
//Menu 2, Item 4
if(evt==m2i4)
{
toD=JOptionPane.showInputDialog("Please enter a new output
decryption file.");
}
//Menu 3, Item 1
if(evt==m3i1)
{
//Quiting Query
int answer=JOptionPane.showConfirmDialog(null,"Are you sure you
want to quit?");
if(answer==0)
{
exit1.exit(0);
}
if(answer==1)
{
JOptionPane.showMessageDialog(null,"Exit termanated by user");
}
if(answer==2)
{
//do nothing
}
}
}
}
}
import java.awt.*;
import java.awt.Event.*;
import javax.swing.*;
public class helpWin extends JFrame
{
ScrollPane helptxt= new ScrollPane();
JTextArea hp=new JTextArea();
String helpText="To encrypt a file: \n"+
" 1. Set the input encrypt file to \n"+
"the desired file for encryption. \n"+
" 2. Set the output encrypt file to \n"+
"the desired file name. This will be \n"+
"the name of the encrypted file. \n"+
" 3. Set the encryption sequence \n"+
"to the desired level of encryption \n"+
"security. (1-100 1 being the lowest \n"+
"and 100 being the highest.) \n"+
" 4. Click \"Encrypt file\" to begin\n"+
"encryption.\n"+
"To decrypt a file: \n"+
" 1. Set the input decryption file \n"+
"to the desired file for decryption. \n"+
" 2. Set the output decryption file \n"+
"to the desired file name. This will \n"+
"be the name of the decrypted file. \n"+
" 3. Make sure that the current \n"+
"level of encryption security matches \n"+
"that of the file for decryption. THIS\n"+
"IS VERY IMPORTENT! If the numbers do \n"+
"not match, the file will not be \n"+
"decrypted correctly! It is advisable\n"+
"you keep a written record of the file\n"+
"names and the encryption security. \n"+
" 4. Click \"Decrypt file\" to begin\n"+
"decryption. \n"+
"To regester: \n"+
" 1. Click Regester Now! under the \n"+
"about menu to regester. \n"+
" 2. Fill-in ALL fields. \n"+
" 3. Click the Submit button. \n"+
" 4. Close the window. \n"+
" 5. The program is now regestered. \n"+
"This program and all included \n"+
"documents (c)2004 Programmers,Inc. \n";
public helpWin()
{
super("EncryptoPro! Help window");
setSize(350,350);
Container pane=getContentPane();
FlowLayout flow=new FlowLayout();
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
pane.setLayout(flow);
pane.add(helptxt);
helptxt.add(hp);
hp.setText(helpText);
hp.setEditable(false);
hp.setVisible(true);
helptxt.setSize(325,325);
helptxt.setVisible(true);
pane.setVisible(true);
setResizable(false);
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class regester extends JFrame
{
JLabel name=new JLabel("Name");
JTextField namet=new JTextField();
JLabel code=new JLabel("Registration code");
JTextField codet=new JTextField();
JLabel address=new JLabel("Address");
JTextField addresst=new JTextField();
JLabel state=new JLabel("State");
JTextField statet=new JTextField();
JLabel city=new JLabel("City");
JTextField cityt=new JTextField();
JLabel phone=new JLabel("Phone");
JTextField phonet=new JTextField();
JLabel cardtype=new JLabel("Card type");
JTextField cardtypet=new JTextField();
JLabel carddate=new JLabel("Card exparation date");
JTextField carddatet=new JTextField();
JLabel cardnum=new JLabel("Credit card number");
JTextField cardnumt=new JTextField();
JButton clear=new JButton("Clear all");
JButton submit=new JButton("Submit");
JButton cancel=new JButton("Cancel");
public regester()
{
super("Registration");
setSize(325,350);
GridLayout grid=new GridLayout(0,2);
Container pane=getContentPane();
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
ActionListener listener= new ChoiceListener();
pane.setLayout(grid);
pane.setVisible(true);
pane.add(name);
pane.add(namet);
namet.addActionListener(listener);
pane.add(code);
pane.add(codet);
codet.addActionListener(listener);
pane.add(address);
pane.add(addresst);
addresst.addActionListener(listener);
pane.add(city);
pane.add(cityt);
cityt.addActionListener(listener);
pane.add(state);
pane.add(statet);
statet.addActionListener(listener);
pane.add(phone);
pane.add(phonet);
phonet.addActionListener(listener);
pane.add(cardtype);
pane.add(cardtypet);
cardtypet.addActionListener(listener);
pane.add(carddate);
pane.add(carddatet);
carddatet.addActionListener(listener);
pane.add(cardnum);
pane.add(cardnumt);
cardnumt.addActionListener(listener);
pane.add(clear);
clear.setEnabled(false);
clear.addActionListener(listener);
pane.add(submit);
pane.add(cancel);
cancel.addActionListener(listener);
submit.setEnabled(false);
submit.addActionListener(listener);
}
public void clearAllFields() // method
{
codet.setText(null);
codet.setForeground(Color.black);
statet.setText(null);
statet.setForeground(Color.black);
cityt.setText(null);
cityt.setForeground(Color.black);
phonet.setText(null);
phonet.setForeground(Color.black);
cardtypet.setText(null);
cardtypet.setForeground(Color.black);
cardnumt.setText(null);
cardnumt.setForeground(Color.black);
carddatet.setText(null);
carddatet.setForeground(Color.black);
namet.setText(null);// clears the text from the text field
namet.setForeground(Color.black);// sets the text color to black
addresst.setText(null);
addresst.setForeground(Color.black);
clear.setEnabled(false);// disables the clear button
submit.setEnabled(false);
}
public void setClose()
{
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public static void main(String [] a)
{
regester n=new regester();
n.setVisible(true);
}
private class ChoiceListener implements ActionListener
{
public void actionPerformed(ActionEvent evn)
{
Object x=evn.getSource();
if(x==cancel||x==clear||x==namet||x==codet||x==addresst||x==statet||x==cityt||x==phonet||x==carddatet||x==cardtype||x==cardnumt||x==submit)
{
if(x==namet||x==codet||x==addresst||x==statet||x==cityt||x==phonet||x==carddatet||x==cardtype||x==cardnumt)
{
clear.setEnabled(true);
submit.setEnabled(true);
}
if(x==submit)
{
boolean cleared=false;
if(namet.getText().length()>0&&codet.getText().length()>0&&
statet.getText().length()>0&&cityt.getText().length()>0&&
phonet.getText().length()>0&&carddate.getText().length()>0&&
cardnum.getText().length()>0&&cardtype.getText().length()>0)
{
joshFinalUnit16.reg=true;
joshFinalUnit16.ss=true;
joshFinalUnit16.name=namet.getText().trim();
joshFinalUnit16.code=codet.getText().trim();
joshFinalUnit16.address=addresst.getText().trim();
joshFinalUnit16.city=cityt.getText().trim();
joshFinalUnit16.state=statet.getText().trim();
joshFinalUnit16.setReg();
namet.setEnabled(false);
name.setEnabled(false);
codet.setEnabled(false);
code.setEnabled(false);
statet.setEnabled(false);
addresst.setEnabled(false);
address.setEnabled(false);
cityt.setEnabled(false);
city.setEnabled(false);
state.setEnabled(false);
phonet.setEnabled(false);
phone.setEnabled(false);
carddatet.setEnabled(false);
carddate.setEnabled(false);
cardtypet.setEnabled(false);
cardtype.setEnabled(false);
cardnumt.setEnabled(false);
cardnum.setEnabled(false);
setClose();
clearAllFields();
cleared=true;
setVisible(false);
}
else
{
JOptionPane.showMessageDialog(null,"One or more of the fields
are empty. Please fill them in and ");
}
}
if(x==cancel)
{
namet.setEnabled(false);
name.setEnabled(false);
codet.setEnabled(false);
code.setEnabled(false);
statet.setEnabled(false);
state.setEnabled(false);
phonet.setEnabled(false);
phone.setEnabled(false);
carddatet.setEnabled(false);
carddate.setEnabled(false);
cardtypet.setEnabled(false);
cardtype.setEnabled(false);
cardnumt.setEnabled(false);
cardnum.setEnabled(false);
setClose();
joshFinalUnit16.reg=true;
setVisible(false);
}
if(x==clear)
{
clearAllFields();
}
}
}
}
}
import java.io.*;
import javax.swing.*;
public class utility
{
public static byte toByte(char x)
{
byte t=0;
if(x==' ')
{
t=32;
}
else if(x=='!')
{
t=33;
}
else if(x=='"')
{
t=34;
}
else if(x=='#')
{
t=35;
}
else if(x=='$')
{
t=36;
}
else if(x=='%')
{
t=37;
}
else if(x=='&')
{
t=38;
}
else if(x=='\'')
{
t=39;
}
else if(x=='(')
{
t=40;
}
else if(x==')')
{
t=41;
}
else if(x=='*')
{
t=42;
}
else if(x=='+')
{
t=43;
}
else if(x==',')
{
t=44;
}
else if(x=='-')
{
t=45;
}
else if(x=='.')
{
t=46;
}
else if(x=='/')
{
t=47;
}
else if(x=='0')
{
t=48;
}
else if(x=='1')
{
t=49;
}
else if(x=='2')
{
t=50;
}
else if(x=='3')
{
t=51;
}
else if(x=='4')
{
t=52;
}
else if(x=='5')
{
t=53;
}
else if(x=='6')
{
t=54;
}
else if(x=='7')
{
t=55;
}
else if(x=='8')
{
t=56;
}
else if(x=='9')
{
t=57;
}
else if(x==':')
{
t=58;
}
else if(x==';')
{
t=59;
}
else if(x=='<')
{
t=60;
}
else if(x=='=')
{
t=61;
}
else if(x=='>')
{
t=62;
}
else if(x=='?')
{
t=63;
}
else if(x=='@')
{
t=64;
}
else if(x=='A')
{
t=65;
}
else if(x=='B')
{
t=66;
}
else if(x=='C')
{
t=67;
}
else if(x=='D')
{
t=68;
}
else if(x=='E')
{
t=69;
}
else if(x=='F')
{
t=70;
}
else if(x=='G')
{
t=71;
}
else if(x=='H')
{
t=72;
}
else if(x=='I')
{
t=73;
}
else if(x=='J')
{
t=74;
}
else if(x=='K')
{
t=75;
}
else if(x=='L')
{
t=76;
}
else if(x=='M')
{
t=77;
}
else if(x=='N')
{
t=78;
}
else if(x=='O')
{
t=79;
}
else if(x=='P')
{
t=80;
}
else if(x=='Q')
{
t=81;
}
else if(x=='R')
{
t=82;
}
else if(x=='S')
{
t=83;
}
else if(x=='T')
{
t=84;
}
else if(x=='U')
{
t=85;
}
else if(x=='V')
{
t=86;
}
else if(x=='W')
{
t=87;
}
else if(x=='X')
{
t=88;
}
else if(x=='Y')
{
t=89;
}
else if(x=='Z')
{
t=90;
}
else if(x=='[')
{
t=91;
}
else if(x==']')
{
t=92;
}
else if(x=='\\')
{
t=93;
}
else if(x=='^')
{
t=94;
}
else if(x=='_')
{
t=95;
}
else if(x=='`')
{
t=96;
}
else if(x=='a')
{
t=97;
}
else if(x=='b')
{
t=98;
}
else if(x=='c')
{
t=99;
}
else if(x=='d')
{
t=100;
}
else if(x=='e')
{
t=101;
}
else if(x=='f')
{
t=102;
}
else if(x=='g')
{
t=103;
}
else if(x=='h')
{
t=104;
}
else if(x=='i')
{
t=105;
}
else if(x=='j')
{
t=106;
}
else if(x=='k')
{
t=107;
}
else if(x=='l')
{
t=108;
}
else if(x=='m')
{
t=109;
}
else if(x=='n')
{
t=110;
}
else if(x=='o')
{
t=111;
}
else if(x=='p')
{
t=112;
}
else if(x=='q')
{
t=113;
}
else if(x=='r')
{
t=114;
}
else if(x=='s')
{
t=115;
}
else if(x=='t')
{
t=116;
}
else if(x=='u')
{
t=117;
}
else if(x=='v')
{
t=118;
}
else if(x=='w')
{
t=119;
}
else if(x=='x')
{
t=120;
}
else if(x=='y')
{
t=121;
}
else if(x=='z')
{
t=122;
}
else if(x=='{')
{
t=123;
}
else if(x=='|')
{
t=124;
}
else if(x=='}')
{
t=125;
}
else if(x=='~')
{
t=126;
}
return(t);
}
public static void save(String aFile, String input)
{
try
{
JOptionPane.showMessageDialog(null,"Saving file...");
File out=new File(aFile);
FileOutputStream outFile=new FileOutputStream(aFile);
boolean eof=false;
//Takes the String area and make it a char area
char [] cha=input.toCharArray();
byte x;
x=0;
for(int i=0;i<cha.length;i++)
{
if(cha=='œ')
outFile.write(13);
else
outFile.write(toByte(cha));
}
JOptionPane.showMessageDialog(null,"Done.");
}catch(Exception e)
{
JOptionPane.showMessageDialog(null,"Error-"+e.toString());
}
}
}