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...

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 6 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
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>
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
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
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 php code online
run php code online  Is it possible to run PHP Code online
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
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 destroy java thread
how to destroy java thread  how to destroy java thread?   This will help .. Shutting Down the Java Thread
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 run servlet
how to run servlet  Servlet run procedure for J2EE Software   Hi Friend, Please visit the following links: http://www.roseindia.net/servlets/introductiontoconfigrationservlet.shtml http://www.roseindia.net/servlets
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
how to run rmi program
how to run rmi program  how to run rmi program
how to run - Java Beginners
how to run   how to run java program... brifely  Hi... to execute or run the program. For ex, If you have the following java program... file on the command prompt using: "javac HelloWorld.java". And then run it using
Thread Priorities
the execution schedule of threads . Thread gets the ready-to-run state according... thread for execution. On the other hand, if two threads of the same priority... usually applies one of the two following strategies: Preemptive
how to run applet - Applet
how to run applet   Hi everybody i am using connecting jdbc... how can i execute in browser ? Thanks in advance thanks for seeing my questing   Hi Friend, Please visit the following links: http
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 
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
how to run this program?
how to run this program?  how to run java swing program   Java Swing program runs same as a simple java program. There is no difference... with javac and run with java command, same as a simple java program. Learn Swing
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
How to compile and run the JSP
How to compile and run the JSP  Hi Kindly tell me how to run and compile JSP small Program using Tomcat as webserver. I created small program HELLO JSP in HTML and compile the program but it is saying Class o r interface
Java Exception Thread
Thread is the independent  path of execution run inside the program. Many Thread run concurrently in the program. Multithread are those...,the thread run concurently,synchronous or asynchronous. Advantage of Multithread
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 run java program
how to run java program  i have jar file. in jar i have so many classes.in one of file i want modify .after modifying file i want replce in jar. please help me to how to generate class and how to replace
How to run? - Hibernate
How to run?  Hiiiiiiiiiiiii friend.. i am Magesh... friends are told hibernate is a new entry to Java. so plz try to tell how to use Hibernate code in my application?  Hi friend, Hinernate : Hibernate
to run html code in web browser - JSP-Servlet
to run html code in web browser  how to run jsp file which calls html file on web browser??  Hi Friend, Try the following code: 1)form.jsp: Enter Name: 2)welcome.html: Add Profile Edit
how to run a .exe file in jsp
how to run a .exe file in jsp  i want code for to run a .exe file in jsp
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
Thread Priorities
the execution schedule of threads . Thread gets the ready-to-run state according... thread for execution. On the other hand, if two threads of the same priority...; started to run until either it gets end or another thread of the equal
Advertisements
 

 

 

DMCA.com