Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author ThinkPad
- */
- import javax.swing.JFileChooser;
- import javax.swing.filechooser.FileNameExtensionFilter;
- import javax.swing.SwingWorker;
- import javax.swing.JDialog;
- import javax.swing.JPanel;
- import javax.swing.JLabel;
- import java.awt.BorderLayout;
- import java.io.File;
- public class TheFrame extends javax.swing.JFrame {
- /**
- * Creates new form TheFrame
- */
- public TheFrame() {
- initComponents();
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- OpenSongFile = new javax.swing.JButton();
- jScrollPane1 = new javax.swing.JScrollPane();
- ReadInfo = new javax.swing.JTextArea();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- OpenSongFile.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- OpenSongFile.setText("Open Song File");
- OpenSongFile.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- OpenSongFileActionPerformed(evt);
- }
- });
- ReadInfo.setColumns(20);
- ReadInfo.setRows(5);
- ReadInfo.setToolTipText("");
- jScrollPane1.setViewportView(ReadInfo);
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(39, 39, 39)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(jScrollPane1)
- .addComponent(OpenSongFile, javax.swing.GroupLayout.DEFAULT_SIZE, 584, Short.MAX_VALUE))
- .addContainerGap(124, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(34, 34, 34)
- .addComponent(OpenSongFile, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(18, 18, 18)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(67, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void OpenSongFileActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- JFileChooser fileChooser = new JFileChooser();
- fileChooser.setAcceptAllFileFilterUsed(false);
- FileNameExtensionFilter filter = new FileNameExtensionFilter("MP3 files", "mp3");
- fileChooser.addChoosableFileFilter(filter);
- fileChooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
- int result = fileChooser.showOpenDialog(this);
- if (result != JFileChooser.APPROVE_OPTION) {
- //ReadInfo.setText("No song file has been selected");
- System.out.println("OpenSongFile canceled by user");
- return;
- }
- final JDialog loading = new JDialog(this);
- JPanel p1 = new JPanel(new BorderLayout());
- p1.add(new JLabel("Please wait..."), BorderLayout.CENTER);
- loading.setUndecorated(true);
- loading.getContentPane().add(p1);
- loading.pack();
- loading.setLocationRelativeTo(this);
- loading.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
- loading.setModal(true);
- SwingWorker<String, Void> worker = new SwingWorker<String, Void>() {
- @Override
- protected String doInBackground() throws InterruptedException {
- for (int i = 0; i < 10000; i++)
- for (int j = 0; j < 10000; j++)
- ;
- return "hello";
- }
- @Override
- protected void done() {
- loading.dispose();
- }
- };
- worker.execute();
- loading.setVisible(true);
- try {
- worker.get();
- } catch (Exception e1) {
- e1.printStackTrace();
- }
- File selectedFile = fileChooser.getSelectedFile();
- ReadInfo.setText("Selected file: " + selectedFile.getAbsolutePath());
- //System.out.println();
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(TheFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(TheFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(TheFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(TheFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new TheFrame().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton OpenSongFile;
- private javax.swing.JTextArea ReadInfo;
- private javax.swing.JScrollPane jScrollPane1;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement