简体   繁体   中英

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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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