Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Get input from user...
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Neo




PostPosted: Thu Nov 04, 2004 8:17 pm   Post subject: Get input from user...

This is a bit from my program:

code:
import java.awt.*;
import java.applet.*;

public class House extends Applet {
       
 public void init() {
 }
 
  void DrawTree (Graphics g) {
          g.setColor(Color.yellow);
          g.fillRect(308+x,240,15,30);
          g.setColor(Color.green);
          int x2[] = {290+x,317+x,340+x};
          int y2[] = {260,240,260};
          g.fillPolygon(x2,y2,3);
          int x3[] = {295+x,317+x,335+x};
          int y3[] = {250,230,250};
          g.fillPolygon(x3,y3,3);
          int x4[] = {300+x,317+x,330+x};
          int y4[] = {240,220,240};
          g.fillPolygon(x4,y4,3);
 }
 
  public void paint(Graphics g) {
   DrawTree(g);
 }
 
}


What I want to do is get the user to input a value for x which will determine where the tree goes.
This is the code to do so:

code:
    public static void main(String[] args) {
    int x;
    System.out.print("Please type a number: ");
    x= TextIO.getInt();
}


Where do I put this, because wherever I put it in my program it doesnt work. Ive tried to put it at the beginning of the program after the " public void init()" line and it compiles correctly but it does not ask the user to put in a number. Where do I need to put this line to make it work correctly?
Sponsor
Sponsor
Sponsor
sponsor
McKenzie




PostPosted: Thu Nov 04, 2004 9:02 pm   Post subject: (No subject)

your x is going to have to a field of the class (instead of local to paint).
Get its value in the init Method.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: