0

I want to display a message input by a user on an applet

/**

 * @(#)Hello.java
 *
 * Hello Applet application
 *
 * @author
 * @version 1.00 2011/3/17
 */

import java.awt.*;
import java.applet.*;
import java.io.Console.*;
import java.io.*;

public class Hello extends Applet {

    public void init() {
    }

    public void paint(Graphics g) {

    BufferedReader keyboard;

    String Message;
    try{

        g.drawString("Enter message to be displayed:",0,20);

         keyboard = new BufferedReader(new InputStreamReader(System.in));

          Message=keyboard.readLine();
    }
    catch(IOException e){

        g.drawString("Error reading input!",0,40);
    }

      g.drawString(Message,0,40);


        g.drawString("Hello World!!!", 50, 60 );

    }
}

Edited by Nick Evan: Fixed formatting

3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by ywang
0

when I replace Applet i get errors so i was thinking that you could re-write it and send it back.

0

you are right! your code run ok.

Edited by Nick Evan: Fixed formatting

0

you can display your ide and applet in the same window. Don't min the applet window when you input .Because the applet call 'repaint()' the message is empty !

Edited by Nick Evan: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.