How to run ActionListenters in two different thread for the following code...

How to run ActionListenters in two different thread for the following code...

The ActionListeners here are not running concurrently...
    import java.io.*;    
    import javax.swing.*;
    import java.awt.event.*;
    import javazoom.jl.player.Player;  
    import java.io.FileInputStream;



        public class Play2 extends JFrame
        {  
        JButton b,b1;
        JTextField t;

        Play2()
        {
            JFrame j=new JFrame("MusicPlayer");
            j.setSize(300,300);
            j.setDefaultCloseOperation(EXIT_ON_CLOSE);
            b=new JButton("Play");
            b1=new JButton("Stop");
            JPanel p=new JPanel();
            t=new JTextField(20);
            p.add(t);
            p.add(b);
            p.add(b1);
            j.add(p);
            /**try {
                j.setContentPane(new JLabel(new ImageIcon(ImageIO.read(new File("jesus.jpg")))));
                } 
            catch (IOException e) {
                e.printStackTrace();
                }
            j.getContentPane().setOpaque(false);*/
            j.setVisible(true);


        }
        public void awt()
        {
        b.addActionListener(
                new ActionListener(){
                      public void actionPerformed(ActionEvent ae){
                    try  
                        {  

                String fname=t.getText();
                File directory = new File(fname);

                boolean isDirectory = directory.isDirectory();

                if (isDirectory) 
                 {
                        // It returns true if directory is a directory.
                    System.out.println("the name you have entered is a directory  : "  +  directory);  
                        //It returns the absolutepath of a directory.
                        System.out.println("the path is "  +  directory.getAbsolutePath());
                 }
                else
                {
                        // It returns false if directory is a file.
                    System.out.println("the name you have entered is a file  : " + directory);
                        //It returns the absolute path of a file.
                        System.out.println("the path is "  + directory.getAbsolutePath());
                }
                    String s=directory.getAbsolutePath();

                    s=s.replace("\\","/") ;

                        FileInputStream fis=new FileInputStream(s);  
                        final Player playMp3=new Player(fis);  

                        playMp3.play(); 
            }
            catch(Exception e){
                System.out.println(e);}
            }//end actionPerformed
          }//end ActionListener
        );//end addActionListener()

        b1.addActionListener(
          new ActionListener(){
            public void actionPerformed(
                                      ActionEvent ae){
              //Terminate playback before EOF
                        try  
                        {  

                String fname=t.getText();
                File directory = new File(fname);

                boolean isDirectory = directory.isDirectory();

                if (isDirectory) 
                 {
                        // It returns true if directory is a directory.
                    System.out.println("the name you have entered is a directory  : "  +  directory);  
                        //It returns the absolutepath of a directory.
                        System.out.println("the path is "  +  directory.getAbsolutePath());
                 }
                else
                {
                        // It returns false if directory is a file.
                    System.out.println("the name you have entered is a file  : " + directory);
                        //It returns the absolute path of a file.
                        System.out.println("the path is "  + directory.getAbsolutePath());
                }
                    String s=directory.getAbsolutePath();

                    s=s.replace("\\","/") ;

                        FileInputStream fis=new FileInputStream(s);  
                        final Player playMp3=new Player(fis);  

                        playMp3.close(); 
            }
            catch(Exception e){
                System.out.println(e);}
            }//end actionPerformed
          }//end ActionListener
        );//end addActionListener()

        }


            public static void main(String[]args)  
            {  
            Play2 f=new Play2();
            f.awt();    
        }

    }
View Answers









Related Tutorials/Questions & Answers:
How to run ActionListenters in two different thread for the following code...
How to run ActionListenters in two different thread for the following code...  The ActionListeners here are not running concurrently... import java.io.*; import javax.swing.*; import java.awt.event.*; import
How to run ActionListenters in two different thread for the following code...
How to run ActionListenters in two different thread for the following code...  The ActionListeners here are not running concurrently... import java.io.*; import javax.swing.*; import java.awt.event.*; import
Advertisements
How to run ActionListenters in two different thread for the following code...
How to run ActionListenters in two different thread for the following code...  The ActionListeners here are not running concurrently... import java.io.*; import javax.swing.*; import java.awt.event.*; import
How to run ActionListenters in two different thread for the following code...
How to run ActionListenters in two different thread for the following code...  The ActionListeners here are not running concurrently... import java.io.*; import javax.swing.*; import java.awt.event.*; import
How to Explain different way of using thread?
How to Explain different way of using thread?  Hi, How to explain how to using different thread in Java program
How to Explain different way of using thread?
How to Explain different way of using thread?  Hi, How to explain how to using different thread in Java program........   Hi, There are different types Thread in Java program. Here is the explain how to using thread
How to read text file to two different name array
How to read text file to two different name array   I have those numbers:12,4,9,5 numbers:19,12,1,1 how to put it in two different name array in text file to java
How to read text file to two different name array
How to read text file to two different name array   I have those numbers:12,4,9,5 numbers:19,12,1,1 how to put it in two different name array in text file to java
how to store array values into two different tables in java?
how to store array values into two different tables in java?  I have... and now I want to store these values in two different tables(i.e store 2 array values in one table and remaining two values in another table
How to write the junit test code for the following controller code
How to write the junit test code for the following controller code  //Controller Code package com.payoda.springs; import java.util.ArrayList... "Volumereturn"; } } // Mock test code package com.payoda.test
PHP related - how to explot a string with commas and store into two different variables?
PHP related - how to explot a string with commas and store into two different variables?  Hi, I have a string and is like this '[tubelist 123456,54321,56789,98765]'. I would like to extract the first value after the tubelist
How to update record to database? I have trouble with the following code
How to update record to database? I have trouble with the following code  I have written the update statement but it still not work to update the record,what is the missing of the following code ?I need help,thankyou <?php
Java code for following
Java code for following  Create a function that returns day difference between two dates (inclusive), without using any function provided by the platform or external library. The function must work for all dates in the range of 1
Java Thread : run() method
Java Thread : run() method In this section we are going to describe run() method with example in java thread. Thread run() : All the execution code... public void run() : By extending the Thread class, run() method is overridden
Merging Two Arrays Of Different Lengths
Merging Two Arrays Of Different Lengths  I have two arrays of different lengths and wants to have merged values into third. The only condition is, I want unique values in it(third array). Thanks In Advance
How to read and compare content of two different text file
Description: In the given example you will see how a two text file's content are compared. The BufferedReader class allow us to read a file... as string.. Code: import java.io.*; import 
source code for the following question
source code for the following question  source code for the fuzzy c-means
how to get values for same column name from two different tables in SQL
how to get values for same column name from two different tables in SQL  how to get values for same column name from two different tables in SQL???? column name is emp_id loacated in these two tables company,employee
Expain the following code ?
Expain the following code ?  please explain the following line of code clearly? <html:link href="user.do?parameter=create">Create User</html:link>
Need the Following MobileApplication Related Code
: and one Daemon Thread class need's to run while doing the above operations and if you...Need the Following MobileApplication Related Code  Hi, I need java coding for the following requirements in Collections.. Mobile Subscriber name
Run a simple EJB code
Run a simple EJB code  I found the code this. However, as I have no idea with EJB, I can't understand how to run it. Can anybody help me by giving steps (by giving snapshots or writing full procedure)how to run it (any platform
Run a simple EJB code
Run a simple EJB code  I found the code this. However, as I have no idea with EJB, I can't understand how to run it. Can anybody help me by giving steps (by giving snapshots or writing full procedure)how to run it (any platform
run php code online
run php code online  Is it possible to run PHP Code online
java code for swaping two number
java code for swaping two number  how to code for swaping two number without taking third variables
validate jtextfield in two different class use keylistener
validate jtextfield in two different class use keylistener  validate jtextfield in java swing will use two class, design part in one class and method calling in one class will use Keylisteners or change listeners
core java code for following program
core java code for following program  We are hosting the Olympic... should generate the following reports a. A medal tally b. For a given country.... The following are the guidelines while writing this program Only command line based
How to Differenciate Main Thread and Child Thread in Java
How to Differenciate Main Thread and Child Thread in Java  hi...({});   Hi, There are two types of Thread used in Java Programming... Main Thread and Java Child Thread. Please Suggest any example or online link
Thread Priorities
the execution schedule of threads . Thread gets the ready-to-run state according... one of them to run according to their round of time-slice. Thread Scheduler... void run(){     for(int i=0;i<3;i++){       Thread cur
Run this code..plzz - Java Beginners
Run this code..plzz  Hi Friend... ERROR: Exception in thread "main...;Hi friend, I am sending code according to your requirement but you are defined in this example what you want to do please explain and send me full code
Thread
Thread  What is multi-threading? Explain different states of a thread.... At this point, the thread is considered not alive. Runnable (Ready-to-run) state... ? A thread can be considered dead when its run() method completes. If any thread comes
different output trying to execute same java code
different output trying to execute same java code  i am using net beans 7 ide and java 6 to develop my java projects. i used the following coding...; InputStream inputStream; SerialPort serialPort; Thread readThread; public static
different output trying to execute same java code
different output trying to execute same java code  i am using net beans 7 ide and java 6 to develop my java projects. i used the following coding...; InputStream inputStream; SerialPort serialPort; Thread readThread; public static
different output trying to execute same java code
there is different output trying to execute same java code...different output trying to execute same java code  i am using net beans 7 ide and java 6 to develop my java projects. i used the following coding
how to get following output
how to get following output  input 123456 output 1 2 3 4 5 6
how to get following output
how to get following output  input 123456 output 1 2 3 4 5 6
how to print the following pattern
how to print the following pattern  Hello hEllo heLlo helLo hellO pls reply soon its an emergency   class StringPattern { public static void main(String[] args) { String st="hello
J2ME Thread Processing Example
;  In the given example, you will learn about the thread and how thread works in J2ME application. An application can run multiple activities simultaneously using thread. Here we have defined different states of thread
how to destroy java thread
how to destroy java thread  how to destroy java thread?   This will help .. Shutting Down the Java Thread
doubt in the following code of java - Java Beginners
doubt in the following code of java  Hi frends, actually i want to display the following calculated matrix a[][] in the table format..... but the following program code is only helping when iam giving size of matrix as 3
sir, how to read empty cell in excel file using poi and how to add this empty cell to arraay list and the following is my code
sir, how to read empty cell in excel file using poi and how to add this empty cell to arraay list and the following is my code   //here my file nameis sample.xls and this file contain some blanks cells how to read and how
thread is a sequential path of code execution within a program.
thread is a sequential path of code execution within a program.   thread is a sequential path of code execution within a program. what is the meaning if sequential path of code execution? please explain me
thread is a sequential path of code execution within a program.
thread is a sequential path of code execution within a program.   thread is a sequential path of code execution within a program. what is the meaning if sequential path of code execution? please explain me
thread is a sequential path of code execution within a program.
thread is a sequential path of code execution within a program.   thread is a sequential path of code execution within a program. what is the meaning if sequential path of code execution? please explain me
thread is a sequential path of code execution within a program.
thread is a sequential path of code execution within a program.   thread is a sequential path of code execution within a program. what is the meaning if sequential path of code execution? please explain me
thread is a sequential path of code execution within a program.
thread is a sequential path of code execution within a program.   thread is a sequential path of code execution within a program. what is the meaning if sequential path of code execution? please explain me
thread is a sequential path of code execution within a program.
thread is a sequential path of code execution within a program.   thread is a sequential path of code execution within a program. what is the meaning if sequential path of code execution? please explain me
thread is a sequential path of code execution within a program.
thread is a sequential path of code execution within a program.   thread is a sequential path of code execution within a program. what is the meaning if sequential path of code execution? please explain me
thread is a sequential path of code execution within a program.
thread is a sequential path of code execution within a program.   thread is a sequential path of code execution within a program. what is the meaning if sequential path of code execution? please explain me
thread is a sequential path of code execution within a program.
thread is a sequential path of code execution within a program.   thread is a sequential path of code execution within a program. what is the meaning if sequential path of code execution? please explain me
Interrupting a thread.
to interrupt the current thread. If current thread is blocked by wait(), join... and InterrrupedException. Interrupting a thread that is not alive have no effect. Code: class MyThread1 implements 

Ads