From 3a7bcfb97d41df6f89747dbfb856459e493c11d9 Mon Sep 17 00:00:00 2001 From: handledvirus43 Date: Tue, 19 Nov 2019 14:31:31 -0500 Subject: [PATCH] Add files via upload --- FileAnalyzer.java | 22 ++++++++++++++++++++++ NoExtensionException.java | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 FileAnalyzer.java create mode 100644 NoExtensionException.java diff --git a/FileAnalyzer.java b/FileAnalyzer.java new file mode 100644 index 0000000..0e88832 --- /dev/null +++ b/FileAnalyzer.java @@ -0,0 +1,22 @@ +/** + * @author William Hiranpat + * Analyze file extension and returns it. If there is no extension, let the user know that there is no extension. + */ + +import java.io.file; + +public class FileAnalyzer{ + private static String fileAnalyze(File file) throws { + String extention = ""; + + if (file != null && file.exists()){ + String name = file.getName(); + extension = name.substring(name.lastIndexOf(".");) + } + else{ + throw new NoExtensionException("No extension found."); + } + + return extension; + } +} \ No newline at end of file diff --git a/NoExtensionException.java b/NoExtensionException.java new file mode 100644 index 0000000..89b0054 --- /dev/null +++ b/NoExtensionException.java @@ -0,0 +1,38 @@ +package file_organizer_gui; + +import java.awt.Color; +import java.awt.Font; +import java.nio.file.Path; + +import javax.swing.JFrame; +import javax.swing.JTextArea; + +/** + * @@author William Hiranpat + * Exception that is thrown when the file has no extension + */ + +public class NoExtensionException extends Exception{ + private String message; + private String pathName; + private JFrame popUp; + private JTextArea buttonForException; + + public NoExtensionException(String message){ + this.message = message; + popUp = new JFrame("Extension not Found"); + popUp.getContentPane().setBackground(Color.WHITE); + popUp.setBounds(500, 500, 500, 200); + popUp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + popUp.getContentPane().setLayout(null); + + buttonForException = new JTextArea(message); + buttonForException.setFont(new Font("Times New Roman",Font.BOLD,24)); + buttonForException.setBounds((int)popUp.getAlignmentX()/2, (int)popUp.getAlignmentY(), 500, 300); + popUp.getContentPane().add(buttonForException); + } + + public void showExceptionPopUp() { + popUp.setVisible(true); + } +} \ No newline at end of file