From de338a05e5fbbb3c707a69335677ca805f1a042f Mon Sep 17 00:00:00 2001 From: Donald Shan Date: Sun, 21 Aug 2022 16:11:18 -0700 Subject: Organized Code --- src/main/java/Main.java | 192 ++++++++---------------------------------------- 1 file changed, 31 insertions(+), 161 deletions(-) (limited to 'src/main/java/Main.java') diff --git a/src/main/java/Main.java b/src/main/java/Main.java index a1fc151..ec95ad9 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -2,19 +2,14 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.*; -import java.net.URL; import java.util.ArrayList; -import java.util.regex.Matcher; import org.jaudiotagger.audio.AudioFile; import org.jaudiotagger.audio.AudioFileIO; import org.jaudiotagger.tag.FieldKey; import org.jaudiotagger.tag.Tag; import org.jaudiotagger.tag.datatype.Artwork; - import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.text.DefaultCaret; -import java.util.regex.Pattern; public class Main extends JFrame { String textPath = ""; @@ -23,11 +18,22 @@ public class Main extends JFrame { JScrollPane scrollPane; JButton editButton = new JButton("Edit Tags"); int progress = 0; + FileUtility fileUtil = new FileUtility(); JProgressBar progressBar = new JProgressBar(); JLabel title = new JLabel("SUPER JUICER DOWNLOAD MUSIC COVERS AND TAG NOW 100% SAFE"); JButton startButton = new JButton("Set .txt File"); static JTextArea outputArea = new JTextArea("this is bery bery bery safe no worries no virus malwar ur monies back granteed"); + public Main(){ + initializeComponents(); + initializeActionsListeners(); + } + + public static void main(String[] args) { + new Main().setVisible(true); + } + + private void initializeComponents(){ this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setLocationRelativeTo(null); this.add(panel); @@ -54,13 +60,17 @@ public class Main extends JFrame { panel.add(scrollPane); panel.add(Box.createVerticalStrut(5)); panel.add(editButton); + this.setSize(550,300); + } + + private void initializeActionsListeners(){ startButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if(textPath.equals("")||readyState==false){ outputArea.setText(outputArea.getText()+"\n"+"txt path has not been set. Launching chooserPane"); System.out.println(".txt path has not been set. Launching chooserPane"); - textPath = showFileChooser(); + textPath = fileUtil.showTextFileChooser(); if(!textPath.equals("")){ showWarning("File has been set.\nMake sure you add a new line for each URL.\nOr else say bye bye to your system32"); readyState = true; @@ -73,7 +83,7 @@ public class Main extends JFrame { Runnable runnable = () -> { outputArea.setText(""); startButton.setEnabled(false); - downloadLoop(); + downloadAndTag(); startButton.setEnabled(true); }; @@ -88,32 +98,29 @@ public class Main extends JFrame { } }); - this.setSize(550,300); - - } - public static void main(String[] args) { - new Main().setVisible(true); } - private void downloadLoop(){ - ArrayList songs = readFile(textPath); + + private void downloadAndTag(){ + ArrayList songs = fileUtil.txtToArrayList(textPath); progress = 0; for(int i = 0;i readFile(String fileName) { - ArrayList lines = new ArrayList(); - try { - FileReader fr = new FileReader(fileName); - BufferedReader br = new BufferedReader(fr); - String line; - while ((line = br.readLine()) != null) { - lines.add(line); - } - br.close(); - } catch (Exception e) { - e.printStackTrace(); - } - return lines; - } + -- cgit v1.2.3