Question: Javafx Program for encrypting file from user. Need help to fix/improve the following code: public class Encrypting extends Application{ double paneWidth = 400; double paneHeight
Javafx Program for encrypting file from user. Need help to fix/improve the following code:
public class Encrypting extends Application{
double paneWidth = 400;
double paneHeight = 100;
TextField tfEncryptInput;
TextField tfEncryptOutput;
@Override
public void start(Stage primaryStage) throws IOException,EOFException {
// TODO Auto-generated method stub
tfEncryptInput = new TextField();
tfEncryptInput.setPromptText("File to encrypt");
tfEncryptInput.getText();
tfEncryptOutput = new TextField();
tfEncryptOutput.setPromptText("Save encrypted file to");
// Create encrypt button
Button btCrypt = new Button("Encrypt");
// New pane, add tf`s and bt
GridPane pane = new GridPane();
pane.setAlignment(Pos.CENTER);
pane.add(tfEncryptInput, 1, 0);
pane.add(tfEncryptOutput, 2, 0);
pane.add(btCrypt,1,2);
// Create a scene and place it in the stage
Scene scene = new Scene(pane, paneWidth, paneHeight);
primaryStage.setTitle("Encrypt file"); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
btCrypt.setOnAction(new EventHandler
public void handle(ActionEvent event) {
try {BufferedInputStream input = new BufferedInputStream( // Input file from user
new FileInputStream(new File(tfEncryptInput.getText())));
BufferedOutputStream output = new BufferedOutputStream( // Outputfile from user
new FileOutputStream(new File(tfEncryptInput.getText())));
int value;
while ((value=input.read())!=-1) {
output.write(value+5);
}
input.close();
output.close();
} catch (IOException e) {//Exception
}
}
});
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
