Ratespiel

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Hallo liebe Community,

    Bin ganz neu hier und habe logischerweise ein Problem ^^

    Im Info Unterricht machen wir grad Programmieren mit Java und eigentlich hatte ich da auch kein Problem mit.

    Ist ja ein bisschen wie bei Javascript (mit zusätzlichem Konstruktor etc..) und das hat auch immer geklappt.

    Jedenfalls ging es jetzt erstmal darum ein Ratespiel zu machen, wie das gelöst wird, ist jedem selbst überlassen.

    Hier ist der Quellcode der main-Klasse(n)

    Quellcode

    1. class RateSpiel {
    2. int computerZahl;
    3. int spielerZahl;
    4. boolean weiterSpielen;
    5. int wievielteRunde;
    6. int unterGrenze;
    7. int obgerGrenze;
    8. int maxVersuche;
    9. ConInput eingabe = new ConInput();
    10. RateSpiel(int uG, int oG, int maxV){
    11. this.unterGrenze = uG;
    12. this.obgerGrenze = oG;
    13. if (uG > oG) {
    14. this.unterGrenze = oG;
    15. this.obgerGrenze = uG;
    16. }
    17. else {
    18. this.unterGrenze = uG;
    19. this.obgerGrenze = oG;
    20. }
    21. if (maxV > 1) this.maxVersuche = maxV;
    22. else this.maxVersuche = 3;
    23. this.weiterSpielen = true;
    24. this.wievielteRunde = 0;
    25. }
    26. public void run(){
    27. this.wievielteRunde = 0;
    28. this.computerZahl = (int) (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    29. // System.out.println(this.computerZahl);
    30. while (this.wievielteRunde < this.maxVersuche){
    31. this.wievielteRunde++;
    32. this.spielerZahl = eingabe.eingabeInt("Dein Tipp: ");
    33. if (this.spielerZahl == this.computerZahl){
    34. System.out.println("Richtig geraten!");
    35. break;
    36. }
    37. else
    38. if (this.spielerZahl < this.computerZahl){
    39. System.out.println("Falsch, Deine Zahl war zu klein! Noch " + (maxVersuche - wievielteRunde) + " Versuch(e)");
    40. }
    41. else System.out.println("Falsch, Deine Zahl war zu groß! Noch " + (maxVersuche - wievielteRunde) + " Versuch(e)");
    42. }
    43. }
    44. public void hauptSchleife(){
    45. do{
    46. this.run();
    47. this.weiterSpielen = eingabe.eingabeBoolean("Willst Du nochmal spielen? (ja/nein)");
    48. }
    49. while (this.weiterSpielen);
    50. }
    51. }
    Alles anzeigen






    Und hier ein kleines Programm zum Testen davon:

    Quellcode

    1. class SpielTest {
    2. public static void main(String[] args) {
    3. RateSpiel spiel = new RateSpiel(20, 40, 4);
    4. spiel.hauptSchleife();
    5. }
    6. }


    Allerdings lässt sich das Programm nichtmal Kompilieren....

    Hier der Auszug aus dem Compiler vom Java-Editor:

    Quellcode

    1. Compiliere C:\Users\FoX\Desktop\ratespiel\RateSpiel.java mit Java-Compiler
    2. RateSpiel.java:10:7: cannot find symbol
    3. symbol : class ConInput
    4. location: class RateSpiel
    5. ConInput eingabe = new ConInput();
    6. ^
    7. RateSpiel.java:10:30: cannot find symbol
    8. symbol : class ConInput
    9. location: class RateSpiel
    10. ConInput eingabe = new ConInput();
    11. ^
    12. RateSpiel.java:34:53: cannot find symbol
    13. symbol : variable oberGrenze
    14. location: class RateSpiel
    15. this.computerZahl = (int) (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    16. ^
    17. 3 errors
    18. Compiliere C:\Users\FoX\Desktop\ratespiel\SpielTest.java mit Java-Compiler
    19. .\RateSpiel.java:10:7: cannot find symbol
    20. symbol : class ConInput
    21. location: class RateSpiel
    22. ConInput eingabe = new ConInput();
    23. ^
    24. .\RateSpiel.java:10:30: cannot find symbol
    25. symbol : class ConInput
    26. location: class RateSpiel
    27. ConInput eingabe = new ConInput();
    28. ^
    29. .\RateSpiel.java:34:53: cannot find symbol
    30. symbol : variable oberGrenze
    31. location: class RateSpiel
    32. this.computerZahl = (int) (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    33. ^
    34. 3 errors
    Alles anzeigen




    Ich bin nun mittlerweile etwas ratlos, da ich davon ausging, dass das einfach so funktioniert.

    Mit Java an sich hatte ich auch keine Probleme, ich wollte mich jetzt auch primär auf die grafische Oberfläche stürzen und nur schnell ein kleines Programm dafür schreiben.

    Ich sehe meinen Fehler echt nicht, allerdings bin ich mir mit dem ConInput noch nicht sicher, aber dazu finde ich auch bei google irgendwie nichts ...


    Es wäre sehr nett, wenn mir jemand erläutern könnte, WO und WARUM der Fehler da ist. :)

    Desweiteren wäre eine Einleitung in die grafische Oberfläche mit Swing echt nützlich, ich kann zwar mit dem Java-Editor ein Grundgerüst aufrufen, aber weiß noch nicht, wie ich mein Programm dort einfüge.
    Außerdem müssten so Sachen wie die Eingabe des Benutzers in Text-Felder gelegt werden und ein Button zum starten wäre auch nicht verkehrt.

    mfg
    foxxx

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von foxxx ()

  • Compiliere C:\Users\FoX\Desktop\ratespiel\RateSpiel.java mit Java-Compiler
    RateSpiel.java:10:7: cannot find symbol
    symbol : class ConInput
    location: class RateSpiel
    ConInput eingabe = new ConInput();


    Du musst die Klasse auch importieren, wenn sie sich nicht im selben Package befindet.

    RateSpiel.java:34:53: cannot find symbol
    symbol : variable oberGrenze
    location: class RateSpiel
    this.computerZahl = (int) (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);


    Deine Variable heißt nicht oberGrenze sonder obgerGrenze.

    Dann noch so ein paar allgemeine Sachen.
    1. So wie du Variablen definierst sind sie IMMER public - Heißt in der Konsequenz, jeder kann drauf zu greifen und sie manipulieren. Später kannst du ewig und drei Jahre nach Fehlern suche, weil irgendweine Klasse die Werte ändert. Sofer du es nicht anders brauchst, würde ich vor der Variablendefinition noch ein private setzen.
    2.

    Quellcode

    1. else {
    2. this.unterGrenze = uG;
    3. this.obgerGrenze = oG;
    4. }


    is unnötig, da du das ja oben schon machst.
  • Ich bin jetzt schon etwas weiter, das Programm läuft schonmal :D

    funktionierender Quellcode:

    Quellcode

    1. import java.io.*;
    2. class RateSpiel {
    3. int computerZahl;
    4. String spielerEingabe;
    5. String spielen;
    6. int spielerZahl;
    7. boolean weiterSpielen;
    8. int wievielteRunde;
    9. int unterGrenze;
    10. int oberGrenze;
    11. int maxVersuche;
    12. BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
    13. RateSpiel(int uG, int oG, int maxV){
    14. this.unterGrenze = uG;
    15. this.oberGrenze = oG;
    16. if (uG > oG) {
    17. this.unterGrenze = oG;
    18. this.oberGrenze = uG;
    19. }
    20. else {
    21. this.unterGrenze = uG;
    22. this.oberGrenze = oG;
    23. }
    24. if (maxV > 1) this.maxVersuche = maxV;
    25. else this.maxVersuche = 3;
    26. this.weiterSpielen = true;
    27. this.wievielteRunde = 0;
    28. }
    29. public void run(){
    30. this.wievielteRunde = 0;
    31. this.computerZahl = (int) (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    32. // System.out.println(this.computerZahl);
    33. while (this.wievielteRunde < this.maxVersuche){
    34. this.wievielteRunde++;
    35. System.out.print("Dein Tipp: ");
    36. String spielerEingabe = null;
    37. try {
    38. spielerEingabe = console.readLine();
    39. }
    40. catch (IOException e) {
    41. // Sollte eigentlich nie passieren
    42. e.printStackTrace();
    43. }
    44. spielerZahl = Integer.parseInt(spielerEingabe);
    45. //System.out.println("Dein Tipp lautet: " + spielerZahl);
    46. if (this.spielerZahl == this.computerZahl){
    47. System.out.println("Richtig geraten!");
    48. break;
    49. }
    50. else
    51. if (this.spielerZahl < this.computerZahl){
    52. System.out.println("Falsch, Deine Zahl war zu klein! Noch " + (maxVersuche - wievielteRunde) + " Versuch(e)");
    53. }
    54. else System.out.println("Falsch, Deine Zahl war zu groß! Noch " + (maxVersuche - wievielteRunde) + " Versuch(e)");
    55. }
    56. }
    57. public void hauptSchleife(){
    58. do{
    59. this.run();
    60. System.out.println("Willst Du nochmal spielen? (ja/nein)");
    61. String spielen = null;
    62. try {
    63. spielen = console.readLine();
    64. }
    65. catch (IOException e) {
    66. // Sollte eigentlich nie passieren
    67. e.printStackTrace();
    68. }
    69. //System.out.println(spielen.toLowerCase().equals("ja"));
    70. this.weiterSpielen = spielen.toLowerCase().equals("ja");
    71. }
    72. while (this.weiterSpielen);
    73. }
    74. }
    Alles anzeigen




    Start-Programm:

    Quellcode

    1. class SpielTest {
    2. public static void main(String[] args) {
    3. RateSpiel spiel = new RateSpiel(10, 20, 3);
    4. spiel.hauptSchleife();
    5. }
    6. }



    In der ersten Version waren noch einige Tippfehler, die ich einfach nicht gesehen hab, naja jetzt sind sie weg :)

    Jetzt bin ich gerade dabei, die grafische Oberfläche zu machen.

    Aktuell sieht es jetzt so aus:

    [Blockierte Grafik: http://www.abload.de/thumb/swing_versuch1zhuz.jpg]


    Ich weiß aber nicht, ob das so intelligent gelöst ist...

    Außerdem habe ich die Objekte alle nur platziert und mal halbwegs sinnvoll benannt.

    Es fehlt nocht jegliche Einbindung und Verknüpfung in mein Ratespiel.

    Da habe ich nun kein Plan und muss nochmal suchen, ob ich da eine vernünftige Anleitung finde.

    mfg
    foxxx
  • Ich komm noch immer nicht weiter, ich hab leider keine brauchbare Anleitung für Swing gefunden ...

    Bei "Java ist auch eine Insel" hab ich auch geguckt, aber das hilft mir auch nicht weiter.

    Elemente sind wie gesagt alle platziert, aber müssen noch verknüpft werden, ich weiß nur noch nicht wie ...

    mfg
    foxxx
  • Habe noch nie mit dem "Java-Editor" gearbeitet, aber der sieht so aus, als ob er alles automatisch machen würde ;)

    Kannst du nicht einfach per Doppelklick auf Vergleichen schonmal eine Funktion aufrufen.
    Schritt1: Textkonsolen Ausgage
    Schritt2: Inputfeld mit Text überschreiben. (vermutllich information.setText("text"))
    Schritt3: Logik implementieren.. Array mit Fragen anlegen, ... zählervariable bei jeder korrekten Antwort erhöhen, ...
  • Die ganzen Felder etc erstellt er in der Datei automatisch, das ist richtig.


    Ich brauche jetzt:

    Verknüpfung Untergrenze-Eingabefeld mit der Variable uG
    Verknüpfung Obergrenze-Eingabefeld mit der Variable oG
    Verknüpfung Versuche-Eingabefeld mit der Variable maxV

    Desweiteren muss nach jedem Klick auf "Vergleichen !" die Ausgabe in das große Textfeld gegeben werden. Das ist schon von mir als unveränderlich eingestellt, dort steht dann der Text "Falsch. Deine Zahl war zu klein. < Noch 2 Versuch >"

    Usw...

    Nach jedem Klick muss man eine neue Zahl eingeben können (bei Dein Tipp) und beim Klick auf Vergleichen kommt dann o.g. text.

    Ich bräuchte jetzt etwas Hilfe, wie ich das zu realisieren habe ...

    Wenn jemand nochmal 30-60 Minuten in ICQ/Skype/MSN hätte und mir das erklären könnte und bei Nachfragen direkt reagieren kann, so wie BennyBunny gestern (Danke nochmal), wäre ich echt sehr dankbar!

    mfg
    foxxx
  • Das mag sein, ich bräuchte das Programm nur zu morgen fertig ....

    Wenn mir jemand direkten Support gibt, bis das dann funktioniert wäre ich sehr dankbar.

    Danach ist es natürlich kein Problem für mich, die Lösung mit Begründungen und Zwischenschritten hier nochmal reinzuschreiben, damit andere auch etwas davon haben ;)

    Nur bei mir geht es jetzt primär um den Zeitmangel....

    Und ich komm einfach nicht weiter, ich hab versucht, die Funktion auf den Button zu legen, aber ich weiß nicht, wie ich aus den Textfeldern lese ...

    Ich probier jetzt noch weiter rum..

    Hier meine ICQ-Nummer, falls sich noch jemand durch ringen kann: 293058761

    mfg
    foxxx
  • Hab noch etwas weiter probiert, bekomme jetzt aber zig Fehler beim Kompilieren....

    RateSpiel.java:

    rafb.net/p/EsnNe725.html



    Und hier mein eigentliches "Programm" mit den ganzen grafischen Eingabefeldern etc...


    grafix.java:

    rafb.net/p/aawFe992.html


    Fehlermeldungen:

    Quellcode

    1. Compiliere C:\Users\FoX\Desktop\ratespiel\grafix.java mit Java-Compiler
    2. grafix.java:114:13: cannot find symbol
    3. symbol : variable wievielteRunde
    4. location: class grafix
    5. this.wievielteRunde = 0;
    6. ^
    7. grafix.java:115:13: cannot find symbol
    8. symbol : variable computerZahl
    9. location: class grafix
    10. this.computerZahl = (int) (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    11. ^
    12. grafix.java:115:53: cannot find symbol
    13. symbol : variable oberGrenze
    14. location: class grafix
    15. this.computerZahl = (int) (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    16. ^
    17. grafix.java:115:66: cannot find symbol
    18. symbol : variable unterGrenze
    19. location: class grafix
    20. this.computerZahl = (int) (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    21. ^
    22. grafix.java:115:81: cannot find symbol
    23. symbol : variable unterGrenze
    24. location: class grafix
    25. this.computerZahl = (int) (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    26. ^
    27. grafix.java:115:50: operator + cannot be applied to double,unterGrenze
    28. this.computerZahl = (int) (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    29. ^
    30. grafix.java:115:35: inconvertible types
    31. found : <nulltype>
    32. required: int
    33. this.computerZahl = (int) (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    34. ^
    35. grafix.java:117:20: cannot find symbol
    36. symbol : variable wievielteRunde
    37. location: class grafix
    38. while (this.wievielteRunde < this.maxVersuche){
    39. ^
    40. grafix.java:117:42: cannot find symbol
    41. symbol : variable maxVersuche
    42. location: class grafix
    43. while (this.wievielteRunde < this.maxVersuche){
    44. ^
    45. grafix.java:118:15: cannot find symbol
    46. symbol : variable wievielteRunde
    47. location: class grafix
    48. this.wievielteRunde++;
    49. ^
    50. grafix.java:120:11: cannot find symbol
    51. symbol : variable spielerZahl
    52. location: class grafix
    53. spielerZahl = Integer.parseInt(sTipp.getAccessibleContext(sTipp));
    54. ^
    55. grafix.java:120:47: cannot find symbol
    56. symbol : method getAccessibleContext(javax.swing.JTextField)
    57. location: class javax.swing.JTextField
    58. spielerZahl = Integer.parseInt(sTipp.getAccessibleContext(sTipp));
    59. ^
    60. grafix.java:125:19: cannot find symbol
    61. symbol : variable spielerZahl
    62. location: class grafix
    63. if (this.spielerZahl == this.computerZahl){
    64. ^
    65. grafix.java:125:39: cannot find symbol
    66. symbol : variable computerZahl
    67. location: class grafix
    68. if (this.spielerZahl == this.computerZahl){
    69. ^
    70. grafix.java:130:19: cannot find symbol
    71. symbol : variable spielerZahl
    72. location: class grafix
    73. if (this.spielerZahl < this.computerZahl){
    74. ^
    75. grafix.java:130:38: cannot find symbol
    76. symbol : variable computerZahl
    77. location: class grafix
    78. if (this.spielerZahl < this.computerZahl){
    79. ^
    80. grafix.java:131:73: cannot find symbol
    81. symbol : variable maxVersuche
    82. location: class grafix
    83. ausgabe.setText("Falsch, Deine Zahl war zu klein! Noch " + (maxVersuche - wievielteRunde) + " Versuch(e)");
    84. ^
    85. grafix.java:131:87: cannot find symbol
    86. symbol : variable wievielteRunde
    87. location: class grafix
    88. ausgabe.setText("Falsch, Deine Zahl war zu klein! Noch " + (maxVersuche - wievielteRunde) + " Versuch(e)");
    89. ^
    90. grafix.java:133:75: cannot find symbol
    91. symbol : variable maxVersuche
    92. location: class grafix
    93. else ausgabe.setText("Falsch, Deine Zahl war zu groß! Noch " + (maxVersuche - wievielteRunde) + " Versuch(e)");
    94. ^
    95. grafix.java:133:89: cannot find symbol
    96. symbol : variable wievielteRunde
    97. location: class grafix
    98. else ausgabe.setText("Falsch, Deine Zahl war zu groß! Noch " + (maxVersuche - wievielteRunde) + " Versuch(e)");
    99. ^
    100. grafix.java:143:26: cannot find symbol
    101. symbol : method getAccessibleContext(javax.swing.JTextField)
    102. location: class javax.swing.JTextField
    103. spielen = again.getAccessibleContext(again);
    104. ^
    105. grafix.java:145:15: cannot find symbol
    106. symbol : variable weiterSpielen
    107. location: class grafix
    108. this.weiterSpielen = spielen.toLowerCase().equals("ja");
    109. ^
    110. grafix.java:156:26: cannot find symbol
    111. symbol : method getAccessibleContext(javax.swing.JTextField)
    112. location: class javax.swing.JTextField
    113. spielen = again.getAccessibleContext(again);
    114. ^
    115. grafix.java:158:15: cannot find symbol
    116. symbol : variable weiterSpielen
    117. location: class grafix
    118. this.weiterSpielen = spielen.toLowerCase().equals("ja");
    119. ^
    120. 24 errors
    Alles anzeigen





    Ich hab das mal etwas veruscht anzupassen, aber irgendwo mach ich noch was falsch, oder übersehe etwas.

    PLS HELP ! :(

    mfg
    foxxx
  • Version 2:

    rafb.net/p/pVsGoz76.html


    Funktioniert ebenfalls nicht:

    Quellcode

    1. Compiliere C:\Users\FoX\Desktop\ratespiel\grafix.java mit Java-Compiler
    2. grafix.java:114:9: cannot find symbol
    3. symbol : variable maxV
    4. location: class grafix
    5. maxV = Integer.parseInt(eingabe3.getAccessibleContext(eingabe3));
    6. ^
    7. grafix.java:114:41: cannot find symbol
    8. symbol : method getAccessibleContext(javax.swing.JTextField)
    9. location: class javax.swing.JTextField
    10. maxV = Integer.parseInt(eingabe3.getAccessibleContext(eingabe3));
    11. ^
    12. grafix.java:115:9: cannot find symbol
    13. symbol : variable wievielteRunde
    14. location: class grafix
    15. wievielteRunde = 0;
    16. ^
    17. grafix.java:116:9: cannot find symbol
    18. symbol : variable computerZahl
    19. location: class grafix
    20. computerZahl = (int) (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    21. ^
    22. grafix.java:116:48: cannot find symbol
    23. symbol : variable oberGrenze
    24. location: class grafix
    25. computerZahl = (int) (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    26. ^
    27. grafix.java:116:61: cannot find symbol
    28. symbol : variable unterGrenze
    29. location: class grafix
    30. computerZahl = (int) (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    31. ^
    32. grafix.java:116:76: cannot find symbol
    33. symbol : variable unterGrenze
    34. location: class grafix
    35. computerZahl = (int) (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    36. ^
    37. grafix.java:116:45: operator + cannot be applied to double,unterGrenze
    38. computerZahl = (int) (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    39. ^
    40. grafix.java:116:30: inconvertible types
    41. found : <nulltype>
    42. required: int
    43. computerZahl = (int) (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    44. ^
    45. grafix.java:118:16: cannot find symbol
    46. symbol : variable wievielteRunde
    47. location: class grafix
    48. while (wievielteRunde < maxVersuche){
    49. ^
    50. grafix.java:118:33: cannot find symbol
    51. symbol : variable maxVersuche
    52. location: class grafix
    53. while (wievielteRunde < maxVersuche){
    54. ^
    55. grafix.java:119:11: cannot find symbol
    56. symbol : variable wievielteRunde
    57. location: class grafix
    58. wievielteRunde++;
    59. ^
    60. grafix.java:121:11: cannot find symbol
    61. symbol : variable spielerZahl
    62. location: class grafix
    63. spielerZahl = Integer.parseInt(sTipp.getAccessibleContext(sTipp));
    64. ^
    65. grafix.java:121:47: cannot find symbol
    66. symbol : method getAccessibleContext(javax.swing.JTextField)
    67. location: class javax.swing.JTextField
    68. spielerZahl = Integer.parseInt(sTipp.getAccessibleContext(sTipp));
    69. ^
    70. grafix.java:126:15: cannot find symbol
    71. symbol : variable spielerZahl
    72. location: class grafix
    73. if (spielerZahl == computerZahl){
    74. ^
    75. grafix.java:126:30: cannot find symbol
    76. symbol : variable computerZahl
    77. location: class grafix
    78. if (spielerZahl == computerZahl){
    79. ^
    80. grafix.java:131:15: cannot find symbol
    81. symbol : variable spielerZahl
    82. location: class grafix
    83. if (spielerZahl < computerZahl){
    84. ^
    85. grafix.java:131:29: cannot find symbol
    86. symbol : variable computerZahl
    87. location: class grafix
    88. if (spielerZahl < computerZahl){
    89. ^
    90. grafix.java:132:73: cannot find symbol
    91. symbol : variable maxVersuche
    92. location: class grafix
    93. ausgabe.setText("Falsch, Deine Zahl war zu klein! Noch " + (maxVersuche - wievielteRunde) + " Versuch(e)");
    94. ^
    95. grafix.java:132:87: cannot find symbol
    96. symbol : variable wievielteRunde
    97. location: class grafix
    98. ausgabe.setText("Falsch, Deine Zahl war zu klein! Noch " + (maxVersuche - wievielteRunde) + " Versuch(e)");
    99. ^
    100. grafix.java:134:75: cannot find symbol
    101. symbol : variable maxVersuche
    102. location: class grafix
    103. else ausgabe.setText("Falsch, Deine Zahl war zu groß! Noch " + (maxVersuche - wievielteRunde) + " Versuch(e)");
    104. ^
    105. grafix.java:134:89: cannot find symbol
    106. symbol : variable wievielteRunde
    107. location: class grafix
    108. else ausgabe.setText("Falsch, Deine Zahl war zu groß! Noch " + (maxVersuche - wievielteRunde) + " Versuch(e)");
    109. ^
    110. grafix.java:144:26: cannot find symbol
    111. symbol : method getAccessibleContext(javax.swing.JTextField)
    112. location: class javax.swing.JTextField
    113. spielen = again.getAccessibleContext(again);
    114. ^
    115. grafix.java:146:11: cannot find symbol
    116. symbol : variable weiterSpielen
    117. location: class grafix
    118. weiterSpielen = spielen.toLowerCase().equals("ja");
    119. ^
    120. grafix.java:157:26: cannot find symbol
    121. symbol : method getAccessibleContext(javax.swing.JTextField)
    122. location: class javax.swing.JTextField
    123. spielen = again.getAccessibleContext(again);
    124. ^
    125. grafix.java:159:11: cannot find symbol
    126. symbol : variable weiterSpielen
    127. location: class grafix
    128. weiterSpielen = spielen.toLowerCase().equals("ja");
    129. ^
    130. 26 errors
    Alles anzeigen




    ?( ?( ;( :?:
  • Lol stimmt, ok, hab das mal angepasst...

    Neuer Quellcode:

    rafb.net/p/zuDYvP39.html


    Neue Fehler:

    Quellcode

    1. Compiliere C:\Users\FoX\Desktop\ratespiel\grafix.java mit Java-Compiler
    2. grafix.java:114:45: cannot find symbol
    3. symbol : method getAccessibleContext(javax.swing.JTextField)
    4. location: class javax.swing.JTextField
    5. int maxV = Integer.parseInt(eingabe3.getAccessibleContext(eingabe3));
    6. ^
    7. grafix.java:116:52: cannot find symbol
    8. symbol : variable oberGrenze
    9. location: class grafix
    10. int computerZahl = (int) (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    11. ^
    12. grafix.java:116:65: cannot find symbol
    13. symbol : variable unterGrenze
    14. location: class grafix
    15. int computerZahl = (int) (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    16. ^
    17. grafix.java:116:80: cannot find symbol
    18. symbol : variable unterGrenze
    19. location: class grafix
    20. int computerZahl = (int) (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    21. ^
    22. grafix.java:116:49: operator + cannot be applied to double,unterGrenze
    23. int computerZahl = (int) (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    24. ^
    25. grafix.java:116:34: inconvertible types
    26. found : <nulltype>
    27. required: int
    28. int computerZahl = (int) (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    29. ^
    30. grafix.java:118:33: cannot find symbol
    31. symbol : variable maxVersuche
    32. location: class grafix
    33. while (wievielteRunde < maxVersuche){
    34. ^
    35. grafix.java:121:51: cannot find symbol
    36. symbol : method getAccessibleContext(javax.swing.JTextField)
    37. location: class javax.swing.JTextField
    38. int spielerZahl = Integer.parseInt(sTipp.getAccessibleContext(sTipp));
    39. ^
    40. grafix.java:132:73: cannot find symbol
    41. symbol : variable maxVersuche
    42. location: class grafix
    43. ausgabe.setText("Falsch, Deine Zahl war zu klein! Noch " + (maxVersuche - wievielteRunde) + " Versuch(e)");
    44. ^
    45. grafix.java:134:75: cannot find symbol
    46. symbol : variable maxVersuche
    47. location: class grafix
    48. else ausgabe.setText("Falsch, Deine Zahl war zu groß! Noch " + (maxVersuche - wievielteRunde) + " Versuch(e)");
    49. ^
    50. grafix.java:144:26: cannot find symbol
    51. symbol : method getAccessibleContext(javax.swing.JTextField)
    52. location: class javax.swing.JTextField
    53. spielen = again.getAccessibleContext(again);
    54. ^
    55. grafix.java:146:62: incompatible types
    56. found : boolean
    57. required: java.lang.String
    58. String weiterSpielen = spielen.toLowerCase().equals("ja");
    59. ^
    60. grafix.java:157:26: cannot find symbol
    61. symbol : method getAccessibleContext(javax.swing.JTextField)
    62. location: class javax.swing.JTextField
    63. spielen = again.getAccessibleContext(again);
    64. ^
    65. grafix.java:159:62: incompatible types
    66. found : boolean
    67. required: java.lang.String
    68. String weiterSpielen = spielen.toLowerCase().equals("ja");
    69. ^
    70. 14 errors
    Alles anzeigen



    mfg
    foxxx

    ps: Ich denke mit einem Instant-Messenger wäre die Sache in 30min gegessen, das würde mir einen Haufen Zeit ersparen. Es wäre wirklich sehr sehr nett, wenn sich jemand kurz Zeit für mich nehmen könnte.
    Danach folgt natürlich eine Lösung des Problems / der Probleme in diesem Thread :)
  • Quellcode

    1. public void run(){
    2. int maxV = Integer.parseInt(eingabe3.getAccessibleContext());
    3. int wievielteRunde = 0;
    4. int computerZahl = (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    5. int oberGrenze = Integer.parseInt(eingabe2.getAccessibleContext());
    6. int unterGrenze = Integer.parseInt(eingabe1.getAccessibleContext());
    7. // System.out.println(this.computerZahl);
    8. while (wievielteRunde < maxV){
    9. wievielteRunde++;
    10. int spielerZahl = Integer.parseInt(sTipp.getAccessibleContext());
    11. //System.out.println("Dein Tipp lautet: " + spielerZahl);
    12. if (spielerZahl == computerZahl){
    13. ausgabe.setText("Richtig geraten!");
    14. break;
    15. }
    16. else
    17. if (spielerZahl < computerZahl){
    18. ausgabe.setText("Falsch, Deine Zahl war zu klein! Noch " + (maxV - wievielteRunde) + " Versuch(e)");
    19. }
    20. else ausgabe.setText("Falsch, Deine Zahl war zu groß! Noch " + (maxV - wievielteRunde) + " Versuch(e)");
    21. }
    22. }
    Alles anzeigen



    So sieht die Stelle aktuell aus....

    Variablen hab ich alle angelegt, allerdings weiß ich auch nicht, wie ich das getAccessibleContent() benutzen muss bzw. ob das überhaupt die richtige Funktion zum Auslesen ist.... hab da schon mehrere Sachen probiert...

    Warum findet er die Variablen nicht ?

    Hier der komplette Quellcode:

    rafb.net/p/akpE8S20.html

    Und hier die Fehlermeldungen:

    Quellcode

    1. Compiliere C:\Users\FoX\Desktop\ratespiel\grafix.java mit Java-Compiler
    2. grafix.java:114:27: cannot find symbol
    3. symbol : method parseInt(javax.accessibility.AccessibleContext)
    4. location: class java.lang.Integer
    5. int maxV = Integer.parseInt(eingabe3.getAccessibleContext());
    6. ^
    7. grafix.java:116:46: cannot find symbol
    8. symbol : variable oberGrenze
    9. location: class grafix
    10. int computerZahl = (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    11. ^
    12. grafix.java:116:59: cannot find symbol
    13. symbol : variable unterGrenze
    14. location: class grafix
    15. int computerZahl = (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    16. ^
    17. grafix.java:116:74: cannot find symbol
    18. symbol : variable unterGrenze
    19. location: class grafix
    20. int computerZahl = (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    21. ^
    22. grafix.java:116:43: operator + cannot be applied to double,unterGrenze
    23. int computerZahl = (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    24. ^
    25. grafix.java:116:72: incompatible types
    26. found : <nulltype>
    27. required: int
    28. int computerZahl = (Math.random() * (oberGrenze - unterGrenze) + unterGrenze);
    29. ^
    30. grafix.java:117:33: cannot find symbol
    31. symbol : method parseInt(javax.accessibility.AccessibleContext)
    32. location: class java.lang.Integer
    33. int oberGrenze = Integer.parseInt(eingabe2.getAccessibleContext());
    34. ^
    35. grafix.java:118:34: cannot find symbol
    36. symbol : method parseInt(javax.accessibility.AccessibleContext)
    37. location: class java.lang.Integer
    38. int unterGrenze = Integer.parseInt(eingabe1.getAccessibleContext());
    39. ^
    40. grafix.java:123:36: cannot find symbol
    41. symbol : method parseInt(javax.accessibility.AccessibleContext)
    42. location: class java.lang.Integer
    43. int spielerZahl = Integer.parseInt(sTipp.getAccessibleContext());
    44. ^
    45. grafix.java:146:26: cannot find symbol
    46. symbol : method getAccessibleContext(javax.swing.JTextField)
    47. location: class javax.swing.JTextField
    48. spielen = again.getAccessibleContext(again);
    49. ^
    50. grafix.java:148:62: incompatible types
    51. found : boolean
    52. required: java.lang.String
    53. String weiterSpielen = spielen.toLowerCase().equals("ja");
    54. ^
    55. grafix.java:159:26: cannot find symbol
    56. symbol : method getAccessibleContext(javax.swing.JTextField)
    57. location: class javax.swing.JTextField
    58. spielen = again.getAccessibleContext(again);
    59. ^
    60. grafix.java:161:62: incompatible types
    61. found : boolean
    62. required: java.lang.String
    63. String weiterSpielen = spielen.toLowerCase().equals("ja");
    64. ^
    65. 13 errors
    Alles anzeigen



    mfg
    foxxx

    ps: Niemand Lust/Zeit per ICQ zu helfen ? :(
  • Jau danke ;)

    BennyBunny war nochmal so frei und hat mir im ICQ geholfen (THX!)

    Ich hatte noch einige Denkfehler drin, weil ich Sachen nicht abrufen konnte, einige falsch deklariert waren, usw.

    Jetzt funktioniert das ding auch schon einigermaßen, aber man hat nur einen Versuch 8|

    rafb.net/p/1UCLrd78.html

    Jetzt muss ich das noch so hinbekommen, dass dort Zwischenschritte sind.

    Beim zweiten Druck auf Vergleichen muss er die computerZahl noch drin haben ...

    Wie das genau geht, weiß ich jetzt nicht.

    Auf alle Fälle startet das Ding jetzt und hat ne grafische Oberfläche zum klicken.

    1 Versuch hat man jeweils, also ist es schon möglich zu gewinnen ^^

    Mal schaun was mein Lehrer morgen dazu sagt, er kann mir dann sicherlich auch noch etwas helfen.

    mfg
    foxxx