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

Ads

 
 

Share on Google+Share on Google+

Ragavendra Prabhu
How to run ActionListenters in two different thread for the following code...
0 Answer(s)      4 years and 4 months ago
Posted in : Java Beginners
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();    
        }

    }
Ads
View Answers
Ads









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
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 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
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... will write all the code here, which we want to execute. public void run
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
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... as string.. Code: import java.io.*; import ...;} } Output: Download this code
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
source code for the following question
source code for the following question  source code for the fuzzy c-means
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
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
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>
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
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
How to Differenciate Main Thread and Child Thread in Java
How to Differenciate Main Thread and Child Thread in Java  hi... Main Thread and Java Child Thread. Please Suggest any example or online link for references. Thanks,   Hi, There are two types of Thread used
run php code online
run php code online  Is it possible to run PHP Code online
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
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
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
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
how to destroy java thread
how to destroy java thread  how to destroy java thread?   This will help .. Shutting Down the Java Thread
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
Tutorials   
Java Spring Hibernate Struts Training What type of programming language is Java? How do beginners learn about Java? ClassNotFoundException HttpRequestInterceptor java.lang.noclassdeffounderror: org/apache/http/httprequest noclassdeffounderror: org/apache/http/client/methods/httpurirequest java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017

Ads

 
Advertisement null

Ads