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

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.