runnable in jframe? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

runnable in jframe?

lwiqlwiq Posts: 15Member
how do i implement the runnable into a jframe application? i will use a start and a run method? like in applet? why doesnt work if il implement this method just like i do when i write an applet? ty

Comments

  • zibadianzibadian Posts: 6,349Member
    : how do i implement the runnable into a jframe application? i will
    : use a start and a run method? like in applet? why doesnt work if il
    : implement this method just like i do when i write an applet? ty

    To implement a Runnable you only need to write a run() method. Then you can create a new Thread object and call its start, which will call the run() of the Runnable.
    Example:
    [code]
    public class RunnableFrame extends JFrame implements Runnable {

    public void run() {
    // Some lengthy implementation
    }

    public RunnableFrame() {
    super();
    new Thread(this).start(); // start the run() method in a new thread
    setVisible(true); // show the frame
    }

    }
    [/code]
    The frame is shown, while the run is executing. If the frame includes controls, then the user can still use them to enter values, press buttons, etc.
Sign In or Register to comment.