开发者

Trying to write a little text game

Hey guys I am trying to write a little text game in my free time and I have started with this code.

import java.applet.*;
import ja开发者_开发问答va.awt.*;
import java.util.*;
public class game extends Applet{
public void paint (Graphics g){
    Scanner input = new Scanner(System.in);
    System.out.println("What is your name?:\t");
    String x = input.nextLine();
    g.drawString("Hello, " + x, 50, 25);
}
}

What I want to do is have the applet open right away and then have it ask the questions from within the applet. Also I want the user to be able to input the questions to the applet. Any quick way to be able to do this?


I think the simplest solution for a little game is to work in a console, from a runnable class with a main function. You will then be able to read and display from the console.

You can even have a look at JCurse or other libraries to have a cooler text design (color,...)

If you nevertheless want to work in an applet, then I think you will have to construct a AWT [edit: AWT, not SWT, that was a mistake!] text area control from which to read inputs and send results.

Anyway enjoy yourself designing your game :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜