简体   繁体   English

Applet错误Java打印控制台

[英]Applet Error Java Print Console

Okay, so I have this applet I wrote in eclipse, and it draws a circle, then prints "YEAH" in the console. 好的,所以我有这个用eclipse编写的applet,它绘制了一个圆圈,然后在控制台中显示“ YEAH”。 The first part (drawing the circle) works. 第一部分(画圆)起作用。 However, the program prints nothing to the console. 但是,该程序不会向控制台输出任何内容。

Any ideas why? 有什么想法吗? Oh, and here's the code, should you need it: 哦,这是代码,您是否需要它:

 import javax.swing.JApplet;
 import java.awt.*;

 public class Tuna extends JApplet{
  public static void main(String[] args){
      System.out.println("Yeah!");
  }
 final int radius = 25;

  public void paint ( Graphics gr )
  { 
    gr.setColor( Color.white );
    gr.fillRect( 0, 0, 150, 150 );
    gr.setColor( Color.black );

    gr.drawOval( (150/2 - radius), (150/2 - radius), radius*2, radius*2 );
   }


 }

Applets don't use a static main() method. Applet不使用静态main()方法。 Their lifecycle has been given a more-detailed structure of interaction with their container. 他们的生命周期具有与容器交互的更详细的结构。

Lifecycle interaction with their container, goes thru these four methods: 生命周期与其容器的交互通过以下四种方法进行:

public void init();
public void start();
public void stop();
public void destroy();

Plus: 加:

public void paint (Graphics gr);

Overriding start() or init() , should do what you want. 覆盖start()init() ,应该做您想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM