Computerhilfen.de Logo
Forum
Tipps
News
Frage stellen

Java Quiz mit GUI int to String Problem

Also ich versuche ein Quiz zu schreiben und zwar mit Java. Es soll nicht riesig sein oder so was und es ist eingentlich fast fertig. Ich schaffe es aber nicht einen integer: currentQuestionIndex, in einen String: strI, umzuwandeln. Kann mir da jemand helfen? Ich post hier den gesamten code.
Der Fehler tritt bei der letzten Methode auf und lautet: incompatible types: java.lang.Integer cannot be converted to java.lang.String

Ich habe auch alle anderen möglichkeiten zum convertieren oder parsen ausprobiert. Kann mir jemand sagen wie ich currentQuestionIndex also einen int in den String strI schreiben kann damit die nächste frage geladen wird wie es vorgesehen ist und auch der checker in den Knöpfen weiß welche frage zu Überprüfung steht.
Danke!!

/**
 * Die Klasse DasQuiz wurde automatisch erstellt:
 *
 * @author Marc Blaesche
 * @version 4.12.2014
 */

import sum.komponenten.*;
import sum.werkzeuge.*;
import sum.ereignis.*;
import sum.multimedia.Bild;

public class DasQuiz extends EBAnwendung
{
    // Objekte

    private Etikett hatEtikettHeader;

    private Knopf hatKnopfAnswerA;

    private Knopf hatKnopfExit;

    private Knopf hatKnopfAnswerB;

    private Knopf hatKnopfAnswerC;

    private Zeichenbereich hatZeichenbereichQuestion;

    private Etikett hatEtikett2;

    private Etikett hatEtikett3;

    private Etikett hatEtikett4;

    private Etikett hatEtikettTeamOne;

    private Etikett hatEtikettTemaTwo;

    private Etikett hatEtikettPunkte1;

    private Etikett hatEtikettPunkte2;

    private Knopf hatKnopfGo;

    private String[] frage1 = new String[]{"What is traditionally hidden in a Christmas pudding?", "A Coin", "A Watch", "A pair of dice", "A"};

    private String[] frage2 = new String[]{"How many days are there on a traditional advent calendar?", "12", "24", "30", "B"};

    private String[] frage3 = new String[]{"____pull Santa's sleigh", "Guniea Pigs", "Cats", "Reindeers", "C"};

    private String[] frage4 = new String[]{"According to the song, how many days of Christmas are there?", "11", "12", "13", "B"};

    private String[] frage5 = new String[]{"Why do we shorten Christmas to Xmas?", "X is the first letter of the Greek word for Christ", "X looks like a snowflake", "X looks like a star", "A"};

    private String[] frage6 = new String[]{"What is the last day of Christmas called?", "Advent", "Twelfth Night", "Boxing Day", "B"};

    private String[] frage7 = new String[]{"Are used to make traditional Christingles", "Peaches", "Pears", "Oranges", "C"};

    private String[] frage8 = new String[]{"Charles _____ wrote the book A Christmas Carol", "Dahl", "Rowling", "Dickens", "C"}; 

    private String[] frage9 = new String[]{"Which royal couple started off the fashion for Christmas trees in Britain?", "King Henry adn Anne Boleyn", "Queen Victoria adn Prince Albert", "Prince William and kate Middleton", "B"};

    private String[] frage10 = new String[]{"Which of these plants is traditionally connected with Christmas?", "Daisy", "Daffodil", "Poinsettia", "C"};

    private String [][] questions = {frage1, frage2, frage3, frage4, frage5, frage6, frage7, frage8, frage9, frage10};

    public int currentQuestionIndex = 0;

    private String[] question = new String [currentQuestionIndex];

    private Bild hatSchnee;
   
    private int currentQuestion;
   
    private String strI;
   
    StringBuilder transform = new StringBuilder();
    // Attribute
    /**
     * Konstruktor
     */
    public DasQuiz()
    {
        //Initialisierung der Oberklasse
        super(1255, 876);
        hatSchnee = new Bild(0, 0, 0, 0,  "C:/Users/Timbo/Documents/Schule/Englisch/WeihnachtsquizEnglisch/rot.jpg");

        boolean ok = hatSchnee.ladeBild();
        hatEtikettHeader = new Etikett(468, 57, 225, 25, "Christmas Quiz LK English by Marc Blaesche");
        // Ausrichtung
        hatEtikettHeader.setzeAusrichtung(Ausrichtung.LINKS);
        hatKnopfAnswerA = new Knopf(289, 472, 100, 25, "Answer A");
        hatKnopfAnswerA.setzeBearbeiterGeklickt("hatKnopfAnswerAGeklickt");
        hatKnopfExit = new Knopf(1078, 810, 100, 25, "Exit");
        hatKnopfExit.setzeBearbeiterGeklickt("hatKnopfExitGeklickt");
        hatKnopfAnswerB = new Knopf(514, 472, 100, 25, "Answer B");
        hatKnopfAnswerB.setzeBearbeiterGeklickt("hatKnopfAnswerBGeklickt");
        hatKnopfGo = new Knopf (514, 397, 100, 25, "GOGO");
        hatKnopfGo.setzeBearbeiterGeklickt("hatKnopfGoGeklickt");
        hatKnopfAnswerC = new Knopf(755, 472, 100, 25, "Answer C");
        hatKnopfAnswerC.setzeBearbeiterGeklickt("hatKnopfAnswerCGeklickt");
        hatZeichenbereichQuestion = new Zeichenbereich(288, 143, 566, 143, "");
        hatEtikett2 = new Etikett(289, 300, 566, 25, "");
        // Ausrichtung
        hatEtikett2.setzeAusrichtung(Ausrichtung.LINKS);
        hatEtikett3 = new Etikett(289, 340, 566, 25, "");
        // Ausrichtung
        hatEtikett3.setzeAusrichtung(Ausrichtung.LINKS);
        hatEtikett4 = new Etikett(289, 380, 566, 25, "");
        // Ausrichtung
        hatEtikett4.setzeAusrichtung(Ausrichtung.LINKS);
        hatEtikettTeamOne = new Etikett(72, 585, 100, 25, "Elfs");
        // Ausrichtung
        hatEtikettTeamOne.setzeAusrichtung(Ausrichtung.LINKS);
        hatEtikettTemaTwo = new Etikett(356, 586, 100, 25, "Reindeers");
        // Ausrichtung
        hatEtikettTemaTwo.setzeAusrichtung(Ausrichtung.LINKS);
        hatEtikettPunkte1 = new Etikett(72, 671, 100, 141, "");
        // Ausrichtung
        hatEtikettPunkte1.setzeAusrichtung(Ausrichtung.LINKS);
        hatEtikettPunkte2 = new Etikett(355, 669, 96, 141, "");
        // Ausrichtung
        hatEtikettPunkte2.setzeAusrichtung(Ausrichtung.LINKS);
            System.out.println(currentQuestionIndex);

    }


    public void hatKnopfAnswerAGeklickt()
    {
        currentQuestion = getCurrentQuestion();
        if(questions[currentQuestion].equals("A"))
        {           
            System.out.println("Correct");
            nextQuestion();
        }
        else
        {
            System.out.println("Wrong");
        }
    }

    public void hatKnopfExitGeklickt()
    {
        System.exit(0);
    }

   
    public void hatKnopfAnswerBGeklickt()
    {

        currentQuestion = getCurrentQuestion();
        if(questions[currentQuestion].equals("B"))
        {           
            System.out.println("Correct");
            nextQuestion();
        }
        else
        {
            System.out.println("Wrong");
        }

    }

    public void hatKnopfAnswerCGeklickt()
    {

        currentQuestion = getCurrentQuestion();
        if(questions[currentQuestion].equals("C"))
        {           
            System.out.println("Correct");
            nextQuestion();
        }
        else
        {
            System.out.println("Wrong");
        }

    }

    public void hatKnopfGoGeklickt()
    {
        nextQuestion();
    }

    public void nextQuestion()
    {
        String[] currentQuestion = questions[currentQuestionIndex];

        hatZeichenbereichQuestion.setzeInhalt(" ");
        hatEtikett2.setzeInhalt(" ");
        hatEtikett3.setzeInhalt(" ");
        hatEtikett4.setzeInhalt(" ");

        hatZeichenbereichQuestion.setzeInhalt(currentQuestion[0]);
        hatEtikett2.setzeInhalt(currentQuestion[1]);
        hatEtikett3.setzeInhalt(currentQuestion[2]);
        hatEtikett4.setzeInhalt(currentQuestion[3]);
        currentQuestionIndex++;

    }

    public int getCurrentQuestion()
    {
        strI = Integer.valueOf(currentQuestionIndex);
        return questions[strI];
    }
   
}


Antworten zu Java Quiz mit GUI int to String Problem:

Hier schon fertig?

Hat dir diese Antwort geholfen?

Danke ButtonHilfreiche Antwort Button

War mein Fehler in der Form der ansprache eines 2D String Array's und der Rückgabe Werte des Dienstes. Hier für alle einmal die Fertige und Funktionale Version des Codes. Kann gerne Weiter benutz werden und ich schicke auch gerne die gesammte BlueJ dateu rum bei Anfragen.


import sum.komponenten.*;
import sum.werkzeuge.*;
import sum.ereignis.*;
import sum.multimedia.Bild;

public class DasQuiz extends EBAnwendung
{
    // Objekte

    private Etikett hatEtikettHeader;

    private Knopf hatKnopfAnswerA;

    private Knopf hatKnopfExit;

    private Knopf hatKnopfAnswerB;

    private Knopf hatKnopfAnswerC;

    private Zeichenbereich hatZeichenbereichQuestion;

    private Etikett hatEtikett2;

    private Etikett hatEtikett3;

    private Etikett hatEtikett4;

    private Etikett hatEtikettTeamOne;

    private Etikett hatEtikettTemaTwo;

    private Etikett hatEtikettPunkte1;

    private Etikett hatEtikettPunkte2;

    private Knopf hatKnopfGo;

    private String[] frage1 = new String[]{"What is traditionally hidden in a Christmas pudding?", "A Coin", "A Watch", "A pair of dice", "A"};

    private String[] frage2 = new String[]{"How many days are there on a traditional advent calendar?", "12", "24", "30", "B"};

    private String[] frage3 = new String[]{"____pull Santa's sleigh", "Guniea Pigs", "Cats", "Reindeers", "C"};

    private String[] frage4 = new String[]{"According to the song, how many days of Christmas are there?", "11", "12", "13", "B"};

    private String[] frage5 = new String[]{"Why do we shorten Christmas to Xmas?", "X is the first letter of the Greek word for Christ", "X looks like a snowflake", "X looks like a star", "A"};

    private String[] frage6 = new String[]{"What is the last day of Christmas called?", "Advent", "Twelfth Night", "Boxing Day", "B"};

    private String[] frage7 = new String[]{"Are used to make traditional Christingles", "Peaches", "Pears", "Oranges", "C"};

    private String[] frage8 = new String[]{"Charles _____ wrote the book A Christmas Carol", "Dahl", "Darwin", "Dickens", "C"}; 

    private String[] frage9 = new String[]{"Which royal couple started off the fashion for Christmas trees in Britain?", "King Henry and Anne Boleyn", "Queen Victoria and Prince Albert", "Prince William and kate Middleton", "B"};

    private String[] frage10 = new String[]{"Which of these plants is traditionally connected with Christmas?", "Daisy", "Daffodil", "Poinsettia", "C"};

    private String[] frage11 = new String[] {"Counting Rudolph, how many reindeers does Santa Santa Clause have?", "Nine", "Eight", "Six", "A" };

    private String[] frage12 = new String[] {"During Christmas, people traditionally exchange kisses under what object?", "Chrimas Tree", "Star", "Misseletoe", "C"};

    private String[] frage13 = new String[] {"What snack do people leave out for Santa?", "Coffee and Cookies", "Milk and Cookies", "Tea and Chocolate", "B"};

    private String[] frage14 = new String[] {"What are the two most popular objects to go atop Christmas trees?", "Star and Bell", "Bell and Angel", "Star and Angel", "C"};

    private String[] frage15 = new String[] {"What is the name of the popular ballet performed around Christmas time each year?", "The Nut* bitte keine illegalen Tipps *er", "Black Swan", "Christmas Carrol", "A"};

    private String[] frage16 = new String[] {"What was the first state to recognize Christmas as an official holiday?", "Minnesota", "Alabama", "California", "B"};

    private String[] frage17 = new String[] {"Which State produces the most of the nations Christmas Trees?", "Texas", "Florida", "Oregon", "C"};

    private String[] frage18 = new String[] {"In what year did Hallmark introduce its first Christmas cards?", "1915", "1920", "1935", "A"};

    private String[] frage19 = new String[] {"Why is Santa Clause red and white?", "Because Rudolphs nose is red and the snow is white", "Because of the Coca Cola Companies Colors", "Because he is from Denmark", "B"};

    private String[] frage20 = new String[] {"Why are sugar canes J-shaped?", "to allow it to hang on the tree", "a coir master wanted to remember the kids of the shepards using crooks", "to make it easier to eat", "B"};

    private String[] frage21 = new String[]{"By whom and when was the first chritsmas card invented?", "Sir Henry Cole 1843", "Mr Warner Bros 1786", "Sir Walter White 1729", "A"};

    private String[] frage22 = new String[]{"What does Advent mean?", "Anticipation", "Happiness", "Coming", "C"};

    private String [][] questions = {frage1, frage2, frage3, frage4, frage5, frage6, frage7, frage8, frage9, frage10, frage11, frage12, frage13, frage14, frage15, frage16, frage17, frage18, frage19, frage20, frage21, frage22};

    public int currentQuestionIndex = 0;

    private String[] question = new String [currentQuestionIndex];

    private Bild hatSchnee;

    private String currentQuestion;

    private int currentQuestionI = 1;

    // Attribute
    /**
     * Konstruktor
     */
    public DasQuiz()
    {
        //Initialisierung der Oberklasse
        super(1024,768);
      //  hatSchnee = new Bild(0, 0, 0, 0,  "bilder\\rot.jpg");

        hatEtikettHeader = new Etikett(468, 57, 225, 25, "Frankie's Christmas Quiz");
        // Ausrichtung
        hatEtikettHeader.setzeAusrichtung(Ausrichtung.LINKS);
        hatKnopfAnswerA = new Knopf(289, 472, 100, 25, "Answer A");
        hatKnopfAnswerA.setzeBearbeiterGeklickt("hatKnopfAnswerAGeklickt");
        hatKnopfExit = new Knopf(875, 580, 100, 25, "Exit");
        hatKnopfExit.setzeBearbeiterGeklickt("hatKnopfExitGeklickt");
        hatKnopfAnswerB = new Knopf(514, 472, 100, 25, "Answer B");
        hatKnopfAnswerB.setzeBearbeiterGeklickt("hatKnopfAnswerBGeklickt");
        hatKnopfGo = new Knopf (514, 397, 100, 25, "GOGO");
        hatKnopfGo.setzeBearbeiterGeklickt("hatKnopfGoGeklickt");
        hatKnopfAnswerC = new Knopf(755, 472, 100, 25, "Answer C");
        hatKnopfAnswerC.setzeBearbeiterGeklickt("hatKnopfAnswerCGeklickt");
        hatZeichenbereichQuestion = new Zeichenbereich(288, 143, 566, 143, "");
        hatEtikett2 = new Etikett(289, 300, 566, 25, "");
        // Ausrichtung
        hatEtikett2.setzeAusrichtung(Ausrichtung.LINKS);
        hatEtikett3 = new Etikett(289, 340, 566, 25, "");
        // Ausrichtung
        hatEtikett3.setzeAusrichtung(Ausrichtung.LINKS);
        hatEtikett4 = new Etikett(289, 380, 566, 25, "");
        // Ausrichtung
        hatEtikett4.setzeAusrichtung(Ausrichtung.LINKS);
        hatEtikettTeamOne = new Etikett(72, 585, 100, 25, "");
        // Ausrichtung
        hatEtikettTeamOne.setzeAusrichtung(Ausrichtung.LINKS);
        hatEtikettTemaTwo = new Etikett(356, 586, 150, 25, "");
        // Ausrichtung
        hatEtikettTemaTwo.setzeAusrichtung(Ausrichtung.LINKS);
        hatEtikettPunkte1 = new Etikett(72, 671, 100, 141, "");
        // Ausrichtung
        hatEtikettPunkte1.setzeAusrichtung(Ausrichtung.LINKS);
        hatEtikettPunkte2 = new Etikett(355, 669, 96, 141, "");
        // Ausrichtung
        hatEtikettPunkte2.setzeAusrichtung(Ausrichtung.LINKS);

    }

    public void hatKnopfAnswerAGeklickt()
    {
        currentQuestion = getCurrentQuestion();
        if(currentQuestion.equalsIgnoreCase("A"))
        {           
            hatEtikettTemaTwo.setzeInhalt("Correct");
            nextQuestion();
            currentQuestionIndex++;
        }
        else
        {
            hatEtikettTemaTwo.setzeInhalt("Wrong next Team");
        }
    }

    public void hatKnopfExitGeklickt()
    {
        System.exit(0);
    }

    public void hatKnopfAnswerBGeklickt()
    {

        currentQuestion = getCurrentQuestion();
        if(currentQuestion.equalsIgnoreCase("B"))
        {           
            hatEtikettTemaTwo.setzeInhalt("Correct");
            nextQuestion();
            currentQuestionIndex++;
        }
        else
        {
            hatEtikettTemaTwo.setzeInhalt("Wrong next Team");
        }

    }

    public void hatKnopfAnswerCGeklickt()
    {

        currentQuestion = getCurrentQuestion();
        if(currentQuestion.equalsIgnoreCase("C"))
        {           
            hatEtikettTemaTwo.setzeInhalt("Correct");
            nextQuestion();
            currentQuestionIndex++;
        }
        else
        {
            hatEtikettTemaTwo.setzeInhalt("Wrong next Team");
        }

    }

    public void hatKnopfGoGeklickt()
    {
        hatZeichenbereichQuestion.setzeInhalt(frage1[0]);
        hatEtikett2.setzeInhalt(frage1[1]);
        hatEtikett3.setzeInhalt(frage1[2]);
        hatEtikett4.setzeInhalt(frage1[3]);
    }

    public void nextQuestion()
    {
        String[] currentQuestion = questions[currentQuestionIndex +1];

        hatZeichenbereichQuestion.setzeInhalt(" ");
        hatEtikett2.setzeInhalt(" ");
        hatEtikett3.setzeInhalt(" ");
        hatEtikett4.setzeInhalt(" ");

        hatZeichenbereichQuestion.setzeInhalt(currentQuestion[0]);
        hatEtikett2.setzeInhalt(currentQuestion[1]);
        hatEtikett3.setzeInhalt(currentQuestion[2]);
        hatEtikett4.setzeInhalt(currentQuestion[3]);

    }

    public String getCurrentQuestion()
    {
        return questions[currentQuestionIndex][4];
    }

}


« Programm zur Erfassung von Kohlensäureflaschen mit MietberechnungVisual Studio Express/Community-Version 2008 - 2013 zum Download »
 

Schnelle Hilfe: Hier nach ähnlichen Fragen und passenden Tipps suchen!

Fremdwörter? Erklärungen im Lexikon!
Java
Java ist eine von der Firma SUN entwickelte Programmiersprache. Da Java unabhängig vom Betriebssystem läuft, kann ein einmal geschriebenes Programm auf allen Ja...

Javascript
JavaScript ist eine weit verbreitete Skriptsprache, die ursprünglich von Netscape für das DOM-Scripting für Webseiten entwickelt wurde. Sie hat sich seitde...

Account
Ein Account, im Deutschen auch als Benutzerkonto bezeichnet, ist ein digitales Profil, das einem Nutzer Zugang zu bestimmten Diensten, Plattformen oder Geräten gew&a...