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

 
 


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

}
View Answers









Related Pages:
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 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
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
Thread
Thread   there are two threads running at a time.. when am updating a values in database. both thread halt and stop for moment till it get updated.... You can't skip the update and run the code blow. If you you provide us more
Thread Creation
Interface, override the run() method  to define the code executed by thread...( ) method in the subclass from the Thread class to define the code executed.... The following program demonstrates a single thread creation extending 
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
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
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
Thread
to the thread constructor eventhough we had created only one thread and if you say we have added to point to the current thread then why we have not added this in the following line "s=s1" Pls reply...... class MyThread extends Thread { Thread
Thread
some code like this: class A extends Thread { public void run...Thread  will this code work..? class A extends Thread { public... = new thread(a); t.start(); } } Is it possible to run above program with out
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 Priorities
schedule of threads . Thread gets the ready-to-run state according... usually applies one of the two following strategies: Preemptive scheduling... :Thread[My Thread 1,1,main] In this program two
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
Inter Thread Communication
between two threads. In this process, a thread outside the critical section is tried to run inside the critical section where a thread is already running... is how a thread outside the critical region can know that it can execute inside
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
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
thread class - Java Beginners
the following code: class Incrementor extends Thread{ int cnt1 = 0; boolean...thread class  Create 2 Thread classes.One Thread is Incrementor... value of cnt1 by 1 each time. The other thread is Decrementor which has variable
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
Thread concept
Thread concept  Everytime when i run a multithread program it gives...(this,name); System.out.println("New thread: "+t); t.start(); } public void run...("Thread One is alive: "+ob1.t.isAlive()); System.out.println("Thread Two is alive
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
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
if i run this prog, i got exeption in thread "main" java.lang.ArrayIndexOutOfBoundsException:0 at Maxof2.main(Maxof2.java:9), whats the resolution for ths?
with run command. Run your code with the following statement: java Maxof2 5 6...if i run this prog, i got exeption in thread "main... then you can try the following code also. import java.util.*; class Maxof2
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
Event Dispatcher Thread
in milliseconds. Following code selects a random sequence determined by the current time... with different shades. Here is the code of EventDispatcherThread.java import... Event Dispatcher Thread   
Exception in Thread
Exception in Thread    i am developing a rmi application in eclipse use genady rmi plugin and server side code run effeciently but when i run client and generate connection with server i have following exception
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 
Event Dispatcher Thread
in milliseconds. Following code selects a random sequence determined by the current time... Event Dispatcher Thread       In the tutorial Java Event Dispatcher thread in Graphics
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
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
thread related - Java Interview Questions
thread related  Hi, Plz tell me how two thread will communicate with each other. plz tell me with code. Thanks Narendra   Hi friend, Two threads can communicate with each other using the wait() and notify
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 RUN JDBC PRORAM ON JDK1.5.0
HOW TO RUN JDBC PRORAM ON JDK1.5.0  import java.sql.*; import... then it compiled successfully ,but when i run it ,it gives following error->... driver specified i want to know what is the problem? and how can i run
Applet run with appletviewer but not in browser, any code problem.
Applet run with appletviewer but not in browser, any code problem.  ... fine but not run from the browser as http://localhost:8080/ProgressoApplication... the 52 cards will be show in browser as by "appletviewer" and run as "java applet" I
Daemon thread - Java Beginners
thread which run in background. like garbadge collection thread. Thanks ... information, visit the following link: http://www.roseindia.net/java/thread...Daemon thread  Hi, What is a daemon thread? Please provide me
Java Thread : getState() Example
Java Thread : getState() Example This section explains how to get state... display the different states of the thread. class ThreadGetState implements Runnable { Thread thread; @Override public void run() { Thread.State
error occured in following page ... how to resolve it?
error occured in following page ... how to resolve it?  // to convert image into thumbnail i used following code. But netbeans has given me following....... error is:::: Exception in thread "main" java.lang.IllegalArgumentException
Spring supports remoting for six different RPC models:
to the RMI using the following code, <bean id="serviceimpl"... Window and run the client code by giving the argument f:\springdemo>java... in the implementation code. Also we can direcly run the client. No run to run
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 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
Get Current Thread
, This thread refers to two or more thread running simultaneously within a program. The thread in java is created and controlled by the java.lang.Threadclass. Two... to describe you a code that helps you in understanding Get Current Thread. For this we
Use of "following" in XPath
of different persons. Here is the full source code for persons.xml file as follows... Use of "following" in XPath       In this section you will learn how to use "
Thread Deadlocks - Java Tutorials
Thread Deadlock Detection in Java Thread deadlock relates to the multitasking. When two threads have circular dependency on a synchronized, deadlock is possible. In other words, a situation where a thread is waiting for an object
java pages run
java pages run  how do we run jsp file in the browser. do we need to install server. could it be run on the xamp server   You need Apache Tomcat Server to run the jsp code over it. Follow these steps to run the simple
Thread
Thread  Explain two ways of creating thread in java. Explain at three methods of thread class.   Java Create Thread There are two main... Create Thread There are two main ways of creating a thread. The first is to extend

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.