This site requires JavaScript, please enable it in your browser!
Greenfoot back
dimas_ant
dimas_ant wrote ...

2013/10/2

reading and displaying information

dimas_ant dimas_ant

2013/10/2

#
hello, my name is Dimas, I am a Brazilian student and I am starting to use the greenfoot, I'm trying to develop a program that can read numbers from the keyboard and then display the program. In the forum I saw people using System.out.println mutas, but the program opens a window and repeat several times the text, like a loop when I try to get some data I use but he nextInt display msg and naum receive texts. I would ask if anyone has any tips, also when I have several actors have as I move the program from one to the other?   (Excuse the text, translation google translator)
danpost danpost

2013/10/2

#
To read characters into your program, use the method 'getKey' from the Greenfoot class API. To display the characters, use 'drawString' to draw the characters on a GreenfootImage object that is being displayed or create a new GreenfootImage of the character and use 'drawImage' to draw the image on a displayed image, or create a new image and a new object and have that object display the image. Look over the classes provided within the greenfoot package -- particularly in the Greenfoot and GreenfootImage classes. You do not have to memorize everything; just familiarize yourself with what constructors and methods are available and know how to reference them when needed.
dimas_ant dimas_ant

2013/10/6

#
thanks for the tip, tried to do so, but it did not work. I tried to do the following: I made a variable h = 0, and when you press button 1 h sum. when tightening t, the total should appear h. I though the code appears random numbers attached the following code: (And once again sorry for the english google) import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; import java.awt.Font; /** * Write a description of class Exit here. * * @author (your name) * @version (a version number or a date) */ public class Exit extends Actor { private int h=0; /** * Act - do whatever the Exit wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if (Greenfoot.isKeyDown ("h")){ h++; } if (Greenfoot.isKeyDown ("t")) { GreenfootImage img = new GreenfootImage(200, 300); img.setColor(Color.BLACK); float fontSize = 35.0f; Font font = img.getFont(); font = font.deriveFont(fontSize); img.setFont(font); img.setFont(font); img.drawString("o total é " + h, 30, 20); setImage(img); } } }
danpost danpost

2013/10/6

#
Use:
String key = Greenfoot.getKey();
if ("h".equals(key)) h++;
if ("t".equals(key)) {
    // rest of code
dimas_ant dimas_ant

2013/10/7

#
Use this code where? in place of which part?
dimas_ant dimas_ant

2013/10/7

#
thank you so much, I could do if you want to place a button is click on a certain object how to do?
You need to login to post a reply.