2015-04-01 69 views
0

小程序如何显示从JUnit测试一个小程序(如Eclipse运行小程序)。节目从JUnit测试

示例代码:

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

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

    } 

} 

没有结果。

回答

1

的小程序需要绘制的容器。例如一个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); 
} 
+0

像预期的那样工作。谢谢 – kozla13 2015-04-01 13:29:53