First Applet

Hello
I just started a Java programming class and this is my first post
I tried running this Applet from our book but get the error "java.lang.NoSuchMethodError:
main Exception in thread "main".
// Fig. 3.9: WelcomeApplet2.java
// Displaying multiple strings in an applet.
// Java packages
import java.awt.Graphics; // import class Graphics
import javax.swing.JApplet; // import class JApplet
public class WelcomeApplet2 extends JApplet {
// draw text on applet�s background
public void paint( Graphics g )
// call superclass version of method paint
super.paint( g );
// draw two Strings at different locations
g.drawString( "Welcome to", 25, 25 );
g.drawString( "Java Programming!", 25, 40 );
} // end method paint
} // end class WelcomeApplet2
The book talks about needing an applet viewer which it has in the book cd. I didn't wish
to install the sdk from the book as it wants to unload the version already installed. So my
programs may uninstall with it. But nonetheless the error persists.
Any ideas?
Steve Brock

Hi
I'm not 100% sure whether that what you wanted but anyway ill show it to you :)
// Fig. 3.9: WelcomeApplet2.java
// Displaying multiple strings in an applet.
// Java packages
import java.awt.Graphics; // import class Graphics
import javax.swing.JApplet; // import class JApplet
import javax.swing.*;
import java.awt.*;
public class WelcomeApplet2 extends JApplet
JFrame frame = new JFrame(); //creating a Frame so you can use paint()
// to learn more about this go to java tutorials Swing
public void createFrame()
JFrame.setDefaultLookAndFeelDecorated(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setupFrame(frame.getContentPane());
frame.pack();
frame.setSize(100,100);
frame.setVisible(true);
public void setupFrame(Container pane)
pane.add(new Panel());
public class Panel extends JPanel
// draw text on appletys background
public void paint( Graphics g )
// call superclass version of method paint
// super.paint( g );
// draw two Strings at different locations
g.drawString( "Welcome to", 25, 25 );
g.drawString( "Java Programming!", 25, 40 );
public static void main(String[] args) // always in java code
WelcomeApplet2 newObj = new WelcomeApplet2(); //creating an instance of this class
newObj.createFrame();
ok this code will work... and yours wasn't because you have to have main method, because after you have compiled your code, JVM searches class for this method to execute the program.

Similar Messages

  • Help needed in doing a first applet !

    Dear People,
    My goals are humble. Only to do a first applet
    my MyFirstApplet.html and MyFirstApplet.java are below
    If I try to open the html document in the web browser
    I see a grey rectangle which indicates I think that
    the applet capability has not been enabled for the browser.
    Yet I did download the plugin .
    thank you in advance
    Stan
    import javax.swing.JApplet;
    import java.awt.Graphics;
    public classMyFirstApplet extends JApplet
    public void paint(Graphics g)
    g.drawString("To climb a ladder, start at the bottom rung",20,90);
    <html>
    <head>
    <title> MyFirstApplet
    </title>
    <body>
    <applet code = "MyFirstApplet.class" width = 300 height = 200 >
    </applet>
    </body>
    </html>

    I would try to color the background to see if it is even getting addd to the applet.
    import javax.swing.JApplet;
    import java.awt.Graphics;
    public classMyFirstApplet extends JApplet
    punlic void init(){
    this.setSize(300,300);//setst the size
    this.setbackground(Color.red);//sets the color of the background
    public void paint(Graphics g)
    g.setForeground(Color.black);//sets the color of the text
    g.drawString("To climb a ladder, start at the bottom rung",20,90);
    thy that and let me know if it worked,.
    steve

  • How to call an applet from a first applet

    Hi,
    I need to call an applet from a first applet, but I want that the called applet doesn't execute in the same AppletContext than the first one, is it possible?
    If it is, what is the solution?
    Thanks

    Yes, it is possible. One way would be to use static variables.
    class A1 extends Applet
       public static A2 TheOther;
       public A1()
          A2.TheOther = this;
       public void callA2()
          TheOther.doSomething();
    class A2 extends Applet
       public static A1 TheOther;
       public A2()
          A1.TheOther = this;
       public void doSomething()

  • How to pass first applet value to second applet

    please help ,
    can anyone knows how to send first applet parameter to second applet,
    here is the code
    //<applet code="firstapplet.class" height="200" width="300"></applet>
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class firstapplet extends JApplet
    JPanel pn;JTextField txt;JButton btn;
    public void init()
    pn = new JPanel();
    getContentPane().add(pn);
    txt = new JTextField(20);
    pn.add(txt);
    btn = new JButton("submit");
    pn.add(btn);
    on the click of button i want to pass the textfield value to second applet

    I don't know what exactly you mean by "sending first
    parameter", but using Applet.getContext() you can
    gain access to the other applets on that page, if
    that's what you need. Refer to the API docs for more
    info.thanks for the reply,
    but i want to get the first applet textfield value and show on second applet
    can you help me on this

  • Plug-In very slow to load (first) applet - is IPv6 the problem?

    G'day,
    I've previously reported a similar [problem on Windows 2000|http://forums.sun.com/thread.jspa] which is also affecting Vista (though not as extreme).
    Each time the Plug-In is launched there is a long delay before the applet is started - during this period I simply see the animated Java logo, no change to its (empty) progress bar and no chatter on the Java Console (trace-level 5).
    There is no delay starting the applet when reloading the page or when subsequently visiting other web-pages hosting applets. With the "next generation" Plug-In the JPI is sometimes shutdown and then later relaunched. The delay occurs each time the Plug-In is relaunched.
    For example, when I visit [http://www.java.com/en/download/help/testvm.xml] the delay is 90 seconds on Vista (JRE6.0_12, IE7 & FF3) versus only 20 seconds on Linux (JRE6.0_12, FF3).
    When I dump the running threads in the Console during the delay I noticed an IPv6 method call (stack trace shown at end) is always running - could it be the culprit?
    I'll also try jstack as suggested in the other thread and report back.
    Thanks,
    Chris.
    "thread applet-testvmDynamicJavaComPopUp819.class-1" prio=4 tid=0x043b8800 nid=0x1460 runnable [0x0587e000..0x0587fa68]
       java.lang.Thread.State: RUNNABLE
         at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
         at java.net.InetAddress$1.lookupAllHostAddr(Unknown Source)
         at java.net.InetAddress.getAddressFromNameService(Unknown Source)
         at java.net.InetAddress.getAllByName0(Unknown Source)
         at java.net.InetAddress.getAllByName0(Unknown Source)
         at java.net.SocketPermission.getIP(Unknown Source)
         at java.net.SocketPermission.getCanonName(Unknown Source)
         at java.net.SocketPermission.impliesIgnoreMask(Unknown Source)
         at java.net.SocketPermission.implies(Unknown Source)
         at java.security.CodeSource.matchLocation(Unknown Source)
         at java.security.CodeSource.implies(Unknown Source)
         at sun.security.provider.PolicyFile$8.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at sun.security.provider.PolicyFile.addPermissions(Unknown Source)
         at sun.security.provider.PolicyFile.getPermissions(Unknown Source)
         at sun.security.provider.PolicyFile.getPermissions(Unknown Source)
         at sun.security.provider.PolicyFile.getPermissions(Unknown Source)
         at sun.plugin2.applet.Plugin2ClassLoader.getPermissions(Unknown Source)
         at java.security.SecureClassLoader.getProtectionDomain(Unknown Source)
         - locked <0x2428f658> (a java.util.HashMap)
         at java.security.SecureClassLoader.defineClass(Unknown Source)
         at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         - locked <0x2427b178> (a sun.plugin2.applet.Applet2ClassLoader)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
         at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
         at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)

    Thanks SoCalGuy...I've been going nutzoid over this problem with the new Firefox 5 and later. Searched the internet and no credible solutions available. I've installed Firefox 6 beta 2 and same problem. Every time I shut down my computer and reboot, Firefox 5 (and higher) takes an eternity to start. No such issue with IE9 or Chrome. Been a long time fan of F/F but this has really tested my patience - no apparent fix and what has been suggested on the internet is a load of goobledygook. Hate to say it but unless F/F addresses this issue I might have to head north. Sob...

  • First Applet Game

    I was trying to write snake. After discovering the Timer class, i was able to get the snake to move properly. However, i cant get it to turn. I think I did something wrong with the key listener.
    import javax.swing.Timer;
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    public class Snake extends Applet implements KeyListener
        private int length,dir; //for dir, 2=down, 4=left, 8=up, 6=right
        private int[] snakeX=new int[99];
        private int[] snakeY=new int[99];
        public void init()
            addKeyListener(this);
            length=5;
            dir=6;
            for (int c=0;c<length;c++)
                snakeX[c]=150-20*c;
                snakeY[c]=150;
         * Called by the browser or applet viewer to inform this Applet that it
         * should start its execution. It is called after the init method and
         * each time the Applet is revisited in a Web page.
        public void start()
            int delay = 1000; //milliseconds
            ActionListener taskPerformer = new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                     move();
             new Timer(delay, taskPerformer).start();
        public void update(Graphics g) {
            // Redefine update so it doesn't erase the applet before calling
            // paint().
          paint(g);
         * This may be the most important method in your applet: Here, the
         * drawing of the applet gets done. "paint" gets called everytime the
         * applet should be drawn on the screen. So put the code here that
         * shows the applet.
         * @param  g   the Graphics object for this applet
        public void paint(Graphics g)
            //field
            g.setColor(Color.white);
            g.fillRect(0, 0, 500, 500);
            //snake
            g.setColor(Color.blue);
            for (int c=0;c<length;c++)
                g.fillRect(snakeX[c] ,snakeY[c], 20, 20);
         public void changeDir(int direction)
             dir=direction;
         public void keyTyped(KeyEvent evt) {
             int key = evt.getKeyCode();  // keyboard code for the key that was pressed
             if (key == KeyEvent.VK_LEFT)
                changeDir(4);
             else if (key == KeyEvent.VK_RIGHT)
                changeDir(6);
             else if (key == KeyEvent.VK_UP)
                changeDir(8);
             else if (key == KeyEvent.VK_DOWN)
                changeDir(2);
         public void keyReleased(KeyEvent e) {
         public void keyPressed(KeyEvent e) {                       
        public void move()
            int x=snakeX[0];
            int y=snakeY[0];
            int xChange=0;
            int yChange=0;
            for (int c=length-1;c>0;c--)
                snakeX[c]=snakeX[c-1];
                snakeY[c]=snakeY[c-1];
            switch (dir)
                case 8: yChange=-20; break;
                case 4: xChange=-20; break;
                case 6: xChange=20; break;
                case 2: yChange=20; break;
            snakeX[0]=x+xChange;
            snakeY[0]=y+yChange;
            repaint();
        public boolean isAlive()
            if (snakeX[0]<0 || snakeX[0]>280 || snakeY[0]<0 || snakeY[0]>280)
                return false;
            for (int c=1;c<length;c++)
                if (snakeX[0]==snakeX[c] && snakeY[0]==snakeY[c])
                    return false;
            return true;
         * Called by the browser or applet viewer to inform this Applet that
         * it should stop its execution. It is called when the Web page that
         * contains this Applet has been replaced by another page, and also
         * just before the Applet is to be destroyed. If you do not have any
         * resources that you need to release (such as threads that you may
         * want to stop) you can remove this method.
        public void stop()
            // provide any code that needs to be run when page
            // is replaced by another page or before Applet is destroyed
         * Called by the browser or applet viewer to inform this Applet that it
         * is being reclaimed and that it should destroy any resources that it
         * has allocated. The stop method will always be called before destroy.
         * If you do not have any resources that you need to release you can
         * remove this method.
        public void destroy()
            // provide code to be run when Applet is about to be destroyed.
    }The Timer creates new thread. I think i need to get the Key Listener into that thread, but Im not sure how to. Please help me do this. (Btw, i know the delay is too long)

    this is the code, same with your code but keyTyped is moved to keyPressed, and it is an applet-application game
    if playing as applet, be sure to click in the applet area to have it focus
    and one thing, there's nothing wrong with the thread
    import javax.swing.Timer;
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    public class Snake extends Applet implements KeyListener{
         private int length,dir; //for dir, 2=down, 4=left, 8=up, 6=right
         private int[] snakeX=new int[99];
         private int[] snakeY=new int[99];
         public void init() {
              addKeyListener(this);
              length=5;
              dir=6;
              for (int c=0;c<length;c++) {
                   snakeX[c]=150-20*c;
                   snakeY[c]=150;
         public void start() {
              int delay = 1000; //milliseconds
              ActionListener taskPerformer = new ActionListener() {
                   public void actionPerformed(ActionEvent evt) {
                        move();
              new Timer(delay, taskPerformer).start();
         public void update(Graphics g) {
              // Redefine update so it doesn't erase the applet before calling
              // paint().
              paint(g);
         public void paint(Graphics g)    {
              //field
              g.setColor(Color.white);
              g.fillRect(0, 0, 500, 500);
              //snake
              g.setColor(Color.blue);
              for (int c=0;c<length;c++) {
                   g.fillRect(snakeX[c] ,snakeY[c], 20, 20);
         public void changeDir(int direction)     {
              dir=direction;
         public void keyTyped(KeyEvent evt) {
              // moved to keyPressed(KeyEvent) method
         public void keyReleased(KeyEvent e) { }
         public void keyPressed(KeyEvent e) {
              int key = e.getKeyCode();   // keyboard code for the key that was pressed
              if (key == KeyEvent.VK_LEFT) {
                  changeDir(4);
              } else if (key == KeyEvent.VK_RIGHT) {
                   changeDir(6);
              } else if (key == KeyEvent.VK_UP) {
                   changeDir(8);
              } else if (key == KeyEvent.VK_DOWN) {
                   changeDir(2);
         public void move()    {
              int x=snakeX[0];
              int y=snakeY[0];
              int xChange=0;
              int yChange=0;
              for (int c=length-1;c>0;c--)        {
                   snakeX[c]=snakeX[c-1];
                   snakeY[c]=snakeY[c-1];
              switch (dir)        {
                   case 8: yChange=-20; break;
                   case 4: xChange=-20; break;
                   case 6: xChange=20; break;
                   case 2: yChange=20; break;
              snakeX[0]=x+xChange;
              snakeY[0]=y+yChange;
              repaint();
         public boolean isAlive()    {
              if (snakeX[0]<0 || snakeX[0]>280 || snakeY[0]<0 || snakeY[0]>280) {
                    return false;
              for (int c=1;c<length;c++) {
                   if (snakeX[0]==snakeX[c] && snakeY[0]==snakeY[c]) {
                        return false;
              return true;
         public static void main(String[] args) {
              Snake game = new Snake();
              game.init();
              Frame f = new Frame();
              f.setSize(500, 530);
              f.add(game);
              f.setVisible(true);
              game.start();
              game.requestFocus();
    }and you might want to see this: http://goldenstudios.uni.cc/contents/products/games/bin/snake.jnlp

  • Java noob needing help - First applet won't compile

    I'm trying to make a simple audio player applet for a web page. The basic way it works is: There are four buttons Play 1, Play 2, Play 3 and Stop, as well as a label for applet credits, a label for music credits and a label for the applet's current status.
    This is the applet so far:
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    public class wifflesaudio extends Applet implements MouseListener {
    add(new Label("(applet credits"));
    add(new Label("(music credits"));
    Label labelDoing = new Label("Stopped");
    Button buttonOne = new Button("Play 1");
    Button buttonTwo = new Button("Play 2");
    Button buttonThree = new Button("Play 3");
    Button buttonStop = new Button("Stop");
    add(buttonOne);
    add(buttonTwo);
    add(buttonThree);
    add(buttonStop);
    addMouseListener(this);
    String clipName[] = {getParameter("clipOne"),
    getParameter("clipTwo"),
    getParameter("clipThree")};
    AudioClip clipOne;
    AudioClip clipTwo;
    AudioClip clipThree;
    int whichIsPlaying = 0;
    public void loadClip(int clipNumber) {
    switch (clipNumber) {
    case 1:
    if (AudioClip.clipOne == null) {
    try {
    labelDoing = "Loading clip 1...";
    clipOne = Applet.newAudioClip(newURL(getCodeBase(), clipName[1]));
    catch (MalformedURLException e) {
    labelDoing = "WARNING: clip 1 didn't load";
    if (clipOne != null) {
    clipTwo.stop();
    clipThree.stop();
    clipOne.loop();
    whichIsPlaying = 1;
    break;
    case 2:
    if (clipTwo == null) {
    try {
    labelDoing = "Loading clip 2...";
    clipTwo = Applet.newAudioClip(newURL(getCodeBase(), clipName[2]));
    catch (MalformedURLException e) {
    labelDoing = "WARNING: clip 2 didn't load";
    if (clipTwo != null) {
    clipOne.stop();
    clipThree.stop();
    clipTwo.loop();
    whichIsPlaying = 2;
    break;
    case 3:
    if (clipThree == null) {
    try {
    labelDoing = "Loading clip 3...";
    clipThree = Applet.newAudioClip(newURL(getCodeBase(), clipName[3]));
    catch (MalformedURLException e) {
    labelDoing = "WARNING: clip 3 didn't load";
    if (clipTwo != null) {
    clipOne.stop();
    clipTwo.stop();
    clipThree.loop();
    whichIsPlaying = 3;
    break;
    public void actionPerformed(ActionEvent evt) {
    Button source = (Button)evt.getSource();
    if (source.getLabel().equals("Play 1")) {
    loadClip(1);
    if (source.getLabel().equals("Play 2")) {
    loadClip(2);
    if (source.getLabel().equals("Play 3")) {
    loadClip(3);
    if (source.getLabel().equals("Stop")) {
    clipOne.stop();
    clipTwo.stop();
    clipThree.stop();
    Naturally, it doesn't work. When I try to compile it with javac I get 21 errors thrown back at me. Being the noob that I am I have absolutely no idea why it isn't working, so I'm turning to all you clever people for some advice. :)

    Think anyone's going to copy your code into their own machine and compile it to see those messages for you? Well I did. Since there are a zillion error messages, I think it's fair to help a little bit:
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    // no need to implement MouseListener
    // see below
    public class wifflesaudio extends Applet {
        Label labelDoing = new Label("Stopped");
        Button buttonOne = new Button("Play 1");
        Button buttonTwo = new Button("Play 2");
        Button buttonThree = new Button("Play 3");
        Button buttonStop = new Button("Stop");
        String[] clipName;
        AudioClip clipOne;
        AudioClip clipTwo;
        AudioClip clipThree;
        int whichIsPlaying = 0;
        // statements in JAVA must be located with methods or constructors
        // here is the default constructor (with no param)
        wifflesaudio() {
            add(new Label("(applet credits"));
            add(new Label("(music credits"));
            add(buttonOne);
            add(buttonTwo);
            add(buttonThree);
            add(buttonStop);
            clipName = new String[3];
            clipName[0] = getParameter("clipOne");
            clipName[1] = getParameter("clipTwo");
            clipName[2] = getParameter("clipThree");
            addMouseListener(new wifflesaudioMouseListener()); // instead of addMouseListener(this)
        public void loadClip(int clipNumber) {
            switch (clipNumber) {
            case 1:
                if (clipOne == null) {
                    try {
                        // To set the text of a label, you must use setText() method.
                        labelDoing.setText("Loading clip 1...");
                        clipOne = newAudioClip(new URL(getCodeBase(), clipName[1])); // 'new URL' instead of 'newURL'
                    } catch (MalformedURLException e) {
                        // To set the text of a label, you must use setText() method.
                        labelDoing.setText("WARNING: clip 1 didn't load");
                if (clipOne != null) {
                    clipTwo.stop();
                    clipThree.stop();
                    clipOne.loop();
                    whichIsPlaying = 1;
                break;
            case 2:
                if (clipTwo == null) {
                    try {
                        // To set the text of a label, you must use setText() method.
                        labelDoing.setText("Loading clip 2...");
                        clipTwo = newAudioClip(new URL(getCodeBase(), clipName[2])); // 'new URL' instead of 'newURL'
                    } catch (MalformedURLException e) {
                        // To set the text of a label, you must use setText() method.
                        labelDoing.setText("WARNING: clip 2 didn't load");
                if (clipTwo != null) {
                    clipOne.stop();
                    clipThree.stop();
                    clipTwo.loop();
                    whichIsPlaying = 2;
                break;
            case 3:
                if (clipThree == null) {
                    try {
                        // To set the text of a label, you must use setText() method.
                        labelDoing.setText("Loading clip 3...");
                        clipThree = newAudioClip(new URL(getCodeBase(), clipName[3])); // 'new URL' instead of 'newURL'
                    } catch (MalformedURLException e) {
                        // To set the text of a label, you must use setText() method.
                        labelDoing.setText("WARNING: clip 3 didn't load");
                if (clipTwo != null) {
                    clipOne.stop();
                    clipTwo.stop();
                    clipThree.loop();
                    whichIsPlaying = 3;
                break;
        public void actionPerformed(ActionEvent evt) {
            Button source = (Button)evt.getSource();
            if (source.getLabel().equals("Play 1")) {
                loadClip(1);
            if (source.getLabel().equals("Play 2")) {
                loadClip(2);
            if (source.getLabel().equals("Play 3")) {
                loadClip(3);
            if (source.getLabel().equals("Stop")) {
                clipOne.stop();
                clipTwo.stop();
                clipThree.stop();
        // Extending MouseAdapter instead of implementing MouseListener
        // allows NOT to code ALL the methods from MouseListener
        // MouseAdapter already implements MouseListener with empty methods
        // You then just code the method(s) that is (are) needed.
        class wifflesaudioMouseListener extends MouseAdapter {
    }Please next time paste your code between code tags exactly like this:
    &#91;code&#93;
    your code
    &#91;/code&#93;
    Thank you

  • JAVA ASSISTANCE NEEDED IN DOING FIRST APPLET !

    Dear People,
    Every time I try to clean up the errors,
    I start a new project and the JBuilder gives each
    new project a new name of course but it also carries over
    the error messages from the previous project to the new
    applet so trying to clean up the error messages is a
    frustrating process.
    The improved coding is below and the remaining messages
    Thank you for your advice
    Stan
    package stan_event_makebox;
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import objectdraw.*; //imported library
    public class myApplet extends Applet {
    private boolean isStandalone = false;
    //Get a parameter value
    public String getParameter(String key, String def) {
    return isStandalone ? System.getProperty(key, def) :
    (getParameter(key) != null ? getParameter(key) : def);
    //Construct the applet
    public myApplet()
    // Here is the coding that I need to put into the applet template.
    // Change text color depending on whether mouse
    // is up or down
    public class MouseIndicator extends WindowController
    private Text up, down;
    public void begin()
    up = new Text("UP",200,220,canvas);
    down = new Text("DOWN",200,200,canvas);
    up.setColor(Color.red);
    down.setColor(Color.gray);
    public void onMousePress(Location point)
    down.setColor(Color.red);
    up.setColor(Color.gray);
    public void onMouseRelease(Location point)
    up.setColor(Color.red);
    down.setColor(Color.gray);
    //Initialize the applet
    public void init() {
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    //Component initialization
    private void jbInit() throws Exception {
    //Get Applet information
    public String getAppletInfo() {
    return "Applet Information";
    //Get parameter info
    public String[][] getParameterInfo() {
    return null;
    //Here are the error messages (its a mess)
    "Applet3.java": Error #: 204 : illegal start of expression at line 23, column 2
    "Applet3.java": Error #: 207 : not an expression statement at line 17, column 11
    "Applet3.java": Error #: 202 : 'class' or 'interface' expected at line 54, column 11
    "Applet2.java": Error #: 204 : illegal start of expression at line 25, column 2
    "Applet2.java": Error #: 207 : not an expression statement at line 16, column 10
    "Applet2.java": Error #: 204 : illegal start of expression at line 26, column 2
    "Applet2.java": Error #: 206 : malformed expression at line 25, column 2
    "Applet2.java": Error #: 204 : illegal start of expression at line 28, column 2
    "Applet2.java": Error #: 206 : malformed expression at line 26, column 2
    "Applet1.java": Error #: 204 : illegal start of expression at line 23, column 2
    "Applet1.java": Error #: 207 : not an expression statement at line 17, column 11
    "Applet1.java": Error #: 202 : 'class' or 'interface' expected at line 54, column 11
    "Applet1.java": Error #: 202 : 'class' or 'interface' expected at line 75, column 1
    "myApplet.java": Error #: 204 : illegal start of expression at line 21, column 1
    "myApplet.java": Error #: 207 : not an expression statement at line 16, column 10

    If you code it yourself, instead of using some massively complexifying IDE, you could probably do it in about 20-30 lines. Heck, I'll do it right here (but watch out for typos, I'm notorious for them):
    import java.awt.*;
    import java.awt.event.*;
    public class ColorChanger
    extends java.applet.Applet
        private Color upC = Color.red;
        private Color downC = Color.blue;
        private Label text = new Label("No input yet");
        private String upT = "UP";
        private String downT = "DOWN";
        public ColorChanger()
            add(text);
            text.setSize(text.getPreferredSize());
            text.addMouseListener(
                new MouseAdapter()
                    public void mousePressed(MouseEvent me)
                        text.setText(downT);
                        text.setForegroundColor(downC);
                    public void mouseReleased(MouseEvent me)
                        text.setText(upT);
                        text.setForegroundColor(upC);
    }The ony reason I did that for you is because I hate IDEs!
    -Tim
    P.S. No guarantees on whether or not it works. I didn't bother to look up the correct method names...

  • First applet help plz

    nothing shows up when i open my html file... here's my code
    import java.awt.Graphics;
    import java.applet.Applet;
    public class applet extends Applet {
    String msg;
    public void init() {
    msg = getParameter("jayrad");
    public void paint (Graphics g) {
    g.drawString(msg, 20, 30);
    if there's anything wrong there plz let me know... it may be my html code too...
    <html>
    <applet code=applet width=300 height=200>
    <param name=message value="still confused">
    </applet>
    </html>
    thanks in advance.

    This is what happens when you use the "code" tags wrong, below is the fixed "code" tags...
    I could be wrong, so don't quote me on this... But, here you are calling for a Parameter named "jayrad" but >in the html portion, you called it "message"...
    msg = getParameter("jayrad");
    <param name=message value="still confused">so the fix should be...
    msg = getParameter("jayrad");
    <param name="jayrad" value="still confused">- MaxxDmg...
    - ' He who never sleeps... '

  • My first Applet gives error (been thru tutorial)

    My HTML code:
    <HTML>
    <HEAD>
    <TITLE> A Simple Program </TITLE>
    </HEAD>
    <BODY>
    Here is the output of my program:
    <APPLET CODE="HelloWorld.class" WIDTH=150 HEIGHT=25>
    </APPLET>
    </BODY>
    </HTML>
    My Applet code:
    import java.applet.Applet;
    import java.awt.Graphics;
    public class HelloWorld extends Applet {
    public void paint(Graphics g) {
    g.drawString("Hello world!", 50, 25);
    Both HelloWorld.html and HelloWorld.class are stored on my desktop.
    My result:
    Here is the output of my program:
    ...this is followed by a 150x25 pixel gray area! I dont see the words "Hello world!" written anywhere.
    where am i going wrong?...all help appreciated!

    all that i have installed is j2sdk1.4.1_01
    i'd appreciate if you cud kindly either direct me to a site which tells me what all i need to run this or briefly list it out here itself
    i have IE version6...I get no exception/error messages on the status bar...where else shall i be looking for an error message?
    On checking the Tools->Internet Options under Microsoft VM, I had "JIT compiler for virtual machine enabled" checked...I have gone ahead and checked "Java Console"
    What do u mean by "Which JVM did you compile with"?...Perhaps by mistake but I did not come across the concept of 'compiling' while going thru the Java Applet tutorial on this site!
    please advise!

  • Second Applet takes time to load

    Hi ,
    I have an application where I try to open two jsp pages with applets. The applet in the first page runs fine and the applet in the second page waits for the first applet to end (Finish what it is doing). This problem occurs when I run tomcat from local machine and open the jsp pages in the same machine.
    Even the init() method is taking time to start and is waiting for the other applet to end.
    When I try to access the jsp pages from a remote machine, they work very fine.
    I was searching many forums on the applet problems but I haven't come across this situation. Any solutions to this problem?
    Thanks,
    Sandeep.

    In IE there is a limit of 2 concurrent http connections to a given server.
    I guess that you are using Http 1.1 so one of the connections is kept open by the browser. So this leaves your 2 Applets with only one connection to utilize which they do serially.
    Just to verify that this is the case, set your browser to use Http 1.0. This should allow your Applets 2 concurrent connections so they can work in parallel. The reason for this is that http 1.0 connections are closed immediatly by the browser.
    Ultimatelly you'll need to rearchitect your solution to use only one Applet.

  • Communication between JApplet and Applet on the same web page

    Hi Freinds
    I have a JSP page containing two applets as follows :-
    <jsp:plugin type="applet" code="TreePageJavaClass.class" codebase="/MYOA" width="200" height="300" name="Applet1">
    </jsp:plugin>
    <jsp:plugin type="applet" code="TreePageJavaClass2.class" codebase="/MYOA" name="Applet2" width="200" height="300">
    </jsp:plugin>
    First applet extends JApplet class and has a tree constructed using swing.
    Second applet extends Applet class.
    Now I want to call a method in second applet on selecting a particular tree node on first applet. I can call method on second applet from first applet when both extends Applet class (not JApplet)
    So please tell me what's the problem here and how it can be solved.
    Thanks

    There is a Middle Eastern version of Adobe Dreamweaver CS4-ME, with full support
    of Hebrew, Arabic, Farsi and other languages,
    see http://www.fontworld.com/me/dreamweaverme.html

  • Problem:Multiple instances of the same applet on a webpage...

    I have an applet which connects to a server to read an XML-file.
    I use Doucument to parse the XML-file like this:
    String xmlurl="http://www.somesite.com/somexmlpage.php";
    Document d =DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xmlurl);
    (...read the XML-file...)
    This works fine.
    However, I need multiple instances of the same applet running at the same time on the same webpage.
    Now, with multiple applets running at the same time the parsing no loger works. If one applet is doing some parsing and a taskswitch takes place to let another applet run, the applet which is interrupted is not able to continue the parsing as it looses its "incoming data" when another applet reads from the server.
    How can different applets affect each other like this?
    And how can I fix the problem?
    Thanks in advance for any help!!

    However, I need multiple instances of the same applet running at the same time on the same webpage.
    Why? But okay.Because the the different applets show information about different items.
    Now, with multiple applets running at the same time the parsing no loger works. If one applet is doing some parsing and a
    taskswitch takes place to let another applet run, the applet which is interrupted is not able to continue the
    parsing as it looses its "incoming data" when another applet reads from the server.
    How did you determine that's what's happening?By printing out debuginformation.
    Each applet prints out a message (System.out.println) when it creates an instance of Document (ie. connects to the server) and the applet also prints out XML-information as the XML-file is processed.
    But, actually, I was a bit quick in my first post; The applet doesen't neccesarily loose its "incoming data", but the parser looses the data it is parsing. I can download the data from the server first, and then start parsing it. If a taskswitch happens while one applet is parsing, it looses its data, even if the data is allready downloaded.
    I see this since I see another applet making a printout, and when first applet starts again, the parser has lost track of its data.
    It works fine if only one applet is running. And everything is fine until the next applets starts; I can see this from the printout.
    Again, the appet prints out data as it parses the document. I see the next applet starting to work, and when the first one continues parsing again the printout shows that data is no longer there. It happens everytime the runtime switches to another applet, and it never happens if just one applet is running.
    Googeling a little tells me that DocumentBuilder.parse() isn't thread-safe, but this shouldn't have anything to do with it, should it?
    Each applet is a separate process, and not different threads in the same process, aren't they? (Not sure how the runtime treats multiple applets...)And secondly, the applets create their own instance of Document anyways.

  • How do I integrate Java Applet and JavaScript?

    Hi:
    This has been asked before, I have read the archives, yet I'm still left with some doubts, and some posts are VERY old and may not apply today. (sorry, some questions might seem stupid, this is my first applet). The purpose is to create a light weight application for managing certificates stored on a smart card, requesting certificate renewal from a server and installing the issued certificate on the card.
    I need to create an applet (signed) to bridge the gab caused by the security limitations of JavaScript in order to access the smart card on the client. The applet will manage certificates on the card and do client-card interaction, while all client-server and user interaction is done by AJAX/JavaScript.
    So, the applet is actually supposed to be an invisible object embedded on the page that is accessed by the JavaScript. How do I go about this?
    - is there any reason to prefer JApplet over Applet?
    - do the JavaScript need to invoke start() or init() or is this done on page load?
    - are there limitations on data exchange with the applet (ie. only string types)?
    - how do I throw exceptions from the applet to the calling script?
    and: will is it better to let JavaScript do all http to keep the applet light, or to let the applet fetch files given a URL (to fetch the new certificate)?
    If the applet is stored in a jar-file, how do I indicate which class/method to invoke? Do the JavaScript have access to public methods only?
    Thanks for your advice and suggestions,
    Erik

    Hi,
    Are you still interested?
    I can work with you over this.
    Adil

  • Urgent: How to run Multiple Applets from a URL

    Hi,
    I am developing an applet that needs memory more than 64MB and I have used -Xmx to set it to 128 MB.
    On my web page, I have 3 applications that use the same JAR file of the applet, but the problem is all applets are opened/loaded in same heap space by JVM. So, when I load first applet, it uses 80 MB and when I start 2nd applet, after using 40 MB, it throws OutOfMemory exception.
    Is there a way to start each applet with fresh 128 MB heap space rather than all applets sharing 128 MB heap space?
    Thanks,
    Ajit

    That's some hefty requirements for an applet. I believe that the only way to do the Xmx thing on the client side is to have them manually add it in the JVM arguments section of the Java Plugin Control Panel.
    The browser/plugin is going to use the same JVM to run all 3 applets in a page. I've never seen a way to tell it to do otherwise. The only separation is the applet contexts, but that is more of a security manager grouping thing.
    Maybe you should look into how you can better manage your data so you don't need so much memory.

Maybe you are looking for

  • [solved] problem with libc and eggdrop

    After the last packages update eggdrop don't work anymore prob with libc.so.6 how can i downgrade to the previous libc version ? edit : tried to downgrade glibc (ver 14 and 13) and same problem Thank you [phoenix@styx eggdrop]$ ./eggdrop Eggdrop v1.8

  • Weird iTunes 10.6.3 missing album artwork issue

    I upgraded to iTunes 10.6.3 yesterday, and I had to restart my Mac for an unrelated issue. This afternoon, I noticed something really weird- all my "Documentary" movies that I purchased through iTunes Store have lost their artwork previews; meaning,

  • Travel workflow problems.

    I apologize in advance for the length of this question. When I travel, I carry a MB Air with OS X 10.9.1 and Aperture 3.5.1. I create managed Libraries on a 500GB EHD (or two). I will certainly do some deleting and minimal editing. When I get home I

  • Please Restore.... Please Restore.... Please Restore

    Hey folks, I know it's been asked but ive read other posts and none of the solutions there are working. I have a 5g 30gb iPod Video and when I plug it into iTunes I get the message: "iTunes has detected an iPod in recovery mode. You must restore this

  • Missing Toshiba recovery partition

    I recovered my laptop using the "0" method and I changed the C partition size and I didnt know it was going to delete my other partitions. Now I want to get back my D partition. Is that possible?