kozla13
kozla13

Reputation: 1942

show applet from JUnit test

How to show an applet from a JUnit test(like Eclipse run it as Applet).

example code:

public class AppletTest {
    @Test
    public void test() throws InterruptedException {

        JustOneCircle applet=new JustOneCircle();
        applet.init();
        applet.start();
        applet.setVisible(true);
        TimeUnit.HOURS.sleep(2);

    }

}

no results.

Upvotes: 0

Views: 388

Answers (1)

SubOptimal
SubOptimal

Reputation: 22993

The Applet needs a container to be drawn. For example a JFrame.

Even I could not think about any reason why you want to do that. Find an example below.

@Test
public void showJustOneCircle() throws InterruptedException {
    JFrame frame = new JFrame("JustOneCircle");
    JustOneCircle oneCircle = new JustOneCircle();
    frame.add(oneCircle);
    frame.setSize(200, 200);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    oneCircle.init();
    oneCircle.start();
    // the applet will be closed after 5 seconds
    TimeUnit.SECONDS.sleep(5);
}

Upvotes: 1

Related Questions