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

2021/6/27

How can I add a picture

Jhoffi Jhoffi

2021/6/27

#
I´m working on a quiz game and wan´t to add pictures when you see the questions and remove the pictures, when you see the answers. Both setImage and addObject don´t seem to work. Does somebody know?
 questions = new ArrayList<Question>();
// here i want to add a picture
        String questionText = "Benenne?";
        ArrayList<Answer> answers = new ArrayList<Answer>();  
        answers.add(new Answer("Pentensäure", false));
        answers.add(new Answer("Butansäure", false));
        answers.add(new Answer("Pentansäure", true));
        answers.add(new Answer("Methan", false));
        Collections.shuffle(answers);
        Question question = new Question(questionText, answers);
        String explanation = "Die richtige Antwort war Pentansäure. ";
        question.setExplanation(explanation);
        questions.add(question);
        Collections.shuffle(questions);
// here are more questions but its basically the same code 
        
RcCookie RcCookie

2021/6/27

#
What have you tried? What means „don’t seem to work“? Show some code please. How did you create the image you want to set with setImage() in the first place?
danpost danpost

2021/6/27

#
To set an image to a question, do it the same way as you did questionText or explanation. Use String filename of image. The code given above is only for construction. It has nothing to do with the actual asking and answering of the questions (it only provides the contents of each question). So, setImage and addObject are not used in that block of code.
You need to login to post a reply.