Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners How to run ActionListenters in two different thread for the following code...
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Ragavendra Prabhu
How to run ActionListenters in two different thread for the following code...
0 Answer(s)      a year and 11 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();    
    }

}

Advertisement
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
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
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
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 destroy java thread
how to destroy java thread  how to destroy java thread?   This will help .. Shutting Down the Java Thread
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
 

 

 

DMCA.com