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

2021/12/2

World doesn't display text although code is correct - why?

CodingCowgirl CodingCowgirl

2021/12/2

#
I got a problem with display a specific text in my world. Actually, there should be displaying a question in my world. But for any reason, it doesn’t. Why? The code is correct.
    public firstCategory_questionone()
    {    
           super(1920, 1080, 1); 
         GreenfootImage bg = new GreenfootImage("london-background.png");
         bg.scale(getWidth(), getHeight());
         setBackground(bg);
         firstDescription();
    }
    
    //This shows a simple background for a question
     private void firstDescription() {
        Quiztemplate quiztemplate = new Quiztemplate();
        addObject(quiztemplate, 960, 540);
    }
    
    //should display a text block with the question and its possible answers. The user is able to click on each button for a right or a wrong answer.
    private void firstQuestion() {
        GreenfootImage img = new GreenfootImage (630, 270);
        img.drawString("Frage 1: Wie schreibt sich das Englische Wort für 'Erfahrung'?", 2, 20);
        setBackground(img);
    }
    
    //goes to the next question when user is ready
       public void act() {
         if(Greenfoot.isKeyDown("enter")) {
             Greenfoot.playSound("mouse-click.mp3");
            }
    }
danpost danpost

2021/12/2

#
CodingCowgirl wrote...
I got a problem with display a specific text in my world. Actually, there should be displaying a question in my world. But for any reason, it doesn’t. Why? The code is correct. << Code Omitted >>
The code may compile (being correct in that sense), but it does not appear to be coded to do what you want. I do not see where the firstQuestion method is being called from.
CodingCowgirl CodingCowgirl

2021/12/2

#
@danpost I tried to put it into the first public method. However, the background disappears then and the text appears. Which is something I don't want.
danpost danpost

2021/12/2

#
CodingCowgirl wrote...
@danpost I tried to put it into the first public method. However, the background disappears then and the text appears. Which is something I don't want.
I thought maybe you would put it after line 26.
CodingCowgirl CodingCowgirl

2021/12/2

#
@danpost Can you please explain why to put this in text? I'm a bit confused. Pics work wonderfully without act but this don't?
danpost danpost

2021/12/2

#
CodingCowgirl wrote...
@danpost Can you please explain why to put this in text? I'm a bit confused. Pics work wonderfully without act but this don't?
It is possible that I am confused also. Please provide current codes; explain exactly what you want and how it currently runs differently from what you want. Also, a brief summary of the initial order of progression of what should happen might help.
CodingCowgirl CodingCowgirl

2021/12/3

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Collections;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.awt.*;
/**
 * Write a description of class firstCategory_questionone here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class firstCategory_questionone extends World
{
  
    /**
     * Constructor for objects of class firstCategory_questionone.
     * 
     */
    public firstCategory_questionone()
    {    
           super(1920, 1080, 1); 
         GreenfootImage bg = new GreenfootImage("london-background.png");
         bg.scale(getWidth(), getHeight());
         setBackground(bg);
         firstDescription();
         next_button();
    }
    
    //This shows a simple background for a question
     private void firstDescription() {
        Quiztemplate quiztemplate = new Quiztemplate();
        addObject(quiztemplate, 960, 540);
    }
    
    //should display a text block with the question and its possible answers. The user is able to click on each button for a right or a wrong answer.
    private void firstQuestion() {
        GreenfootImage img = new GreenfootImage (630, 270);
        img.drawString("Frage 1: Wie schreibt sich das Englische Wort für 'Erfahrung'?", 2, 20);
        setBackground(img);
    }
    
    
    
    private void next_button() {
        Next next = new Next();
        addObject(next, 1295, 825);
    }
    
    //goes to the next question when user is ready
       public void act() {
         if(Greenfoot.isKeyDown("enter")) {
             Greenfoot.playSound("mouse-click.mp3");
            }
    }
}
danpost danpost

2021/12/3

#
And what codes do you have in the Next class?
CodingCowgirl CodingCowgirl

2021/12/6

#
@danpost It's a simple button that redirects to the next question.
You need to login to post a reply.