如何从JUnit测试中显示applet(比如Eclipse将其作为Applet运行)。
示例代码:
public class AppletTest {
@Test
public void test() throws InterruptedException {
JustOneCircle applet=new JustOneCircle();
applet.init();
applet.start();
applet.setVisible(true);
TimeUnit.HOURS.sleep(2);
}
}
没有结果。
答案 0 :(得分:1)
Applet需要绘制一个容器。例如JFrame
。
即使我想不出你想要这样做的任何理由。在下面找一个例子。
@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);
}