1

I'm new to java: When i'm studying package, there are lots of packages available in java platform.

This is my code:

package day1.examples;
import java.applet.*;
import java.awt.*;
public class HelloWorld extends Applet {
    public void paint(Graphics g) {
        g.drawString("Hello world!", 50, 25);
    }
}

When i run this code, it shows this warning :"The import java.applet is never used"

My page look like this:

enter image description here

Can anyone help me?

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
  • 1
    it is not error. it is just warning. the code should work fine – Adem Dec 13 '14 at 11:53
  • @adem: how to view the output.. i mean,, how to add println? or how to fix the warning/ –  Dec 13 '14 at 11:54
  • right click on the code, select "run as" -> "Java Applet" – Adem Dec 13 '14 at 11:55
  • I have only "run as" -> "Run configurations.." –  Dec 13 '14 at 11:56
  • eclipse should detect your class is an applet. but, if not, select "run configurations" and then select "Java Applet" on new window. but, I am almost sure eclipse should be able to detect it is an applet. are you sure you are doing this when your applet code is open ? – Adem Dec 13 '14 at 11:58
  • My class is HelloWorld.java –  Dec 13 '14 at 12:00
  • 1
    are you trying to extend `java.applet.Applet` or your `Applet` class in your package. – Johny Dec 13 '14 at 12:01
  • @johny you are right. sss has another class that named Applet. try to extend java.applet.Applet , or remove your Applet class – Adem Dec 13 '14 at 12:03

1 Answers1

2

You are extending the Applet class in your package. To use the java.applet.Applet you have to either remove Applet from your package or do the following

import java.awt.*;
public class HelloWorld extends java.applet.Applet {
   public void paint(Graphics g) {
      g.drawString("Hello world!", 50, 25);
   }
}
Johny
  • 2,128
  • 3
  • 20
  • 33
  • i got the warning Warning: Can't read AppletViewer properties file: C:\Documents and Settings\Ephrem\.hotjava\properties Using defaults. and what is the problem if i use "import java.applet.*;" –  Dec 13 '14 at 12:09
  • @sss check this link http://stackoverflow.com/questions/5703078/cant-read-appletviewer-properties-file-applet – Johny Dec 13 '14 at 12:12
  • `g.drawString("Hello world!", 50, 25)` prints `Hello world!` at the coordinate (50,25). – Johny Dec 13 '14 at 12:20
  • sorry, what is that name(technically), in this program, and what is Graphis g? Thanks. –  Dec 13 '14 at 12:27
  • Graphics is a class which has different methods used for displaying image, text, etc.. inside your applet. – Johny Dec 13 '14 at 12:32