Quelltext in Lotto

java86

Neues Mitglied
Hallo,
ich schaffe es nicht den Quelltext ohne das es Fehler gibt zu programmieren. Woran diese Fehler liegen erkenne ich nicht. Bei meinem ersten Fehler bei A="Geben Sie ihren "+j+"ten Tipp ab kommt die Nachricht incompatible types required: lotto.Auswertung und found:java.lang.String.
Der Zweite Fehler bei A="Sie haben+Z.getRes etc. lautet die selbe Nachricht wie beim ersten Fehler nur noch `;`expected.
Fehler 3 ist wieder incompatible types und required: lotto.Toto found: java.lang.String. Der Fehler 4 ist connot find symbol symbol: method sort(java.lang.String) location: class java.util.Arrays. Fehler 5 ist incompatible types required: lotto.Toto found: java.lang.String und array required but java.lang.String found.
Ich hoffe ihr könnt mir helfen ich vezweifle an diesen Fehlermeldungen.
Vielen Dank im Vorraus

Java:
package lotto;

import java.awt.Component;
import java.util.Arrays;
import java.awt.Graphics;
import java.util.*;
import javax.swing.*;
public class Lotto3 extends javax.swing.JDialog {
    private int i;
    private String j;


    /** Creates new form Lotto3 */
    public Lotto3(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        P1 = new javax.swing.JOptionPane();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        P1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                P1MouseClicked(evt);
            }
        });

        jButton1.setText("Start");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(67, 67, 67)
                        .addComponent(P1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(158, 158, 158)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(71, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addComponent(P1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(67, 67, 67)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(70, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        


        public void paintIcon(Component c, Graphics g, int x, int y) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public int getIconWidth() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public int getIconHeight() {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    Icon ic=new ImageIcon ("C:\\Lotto.jpg");
    private void P1MouseClicked(java.awt.event.MouseEvent evt) {                                
    String res,b,m,n;
    String []Zahlen;
    int j = 0;
    int n1=Integer.parseInt(JOptionPane.showInputDialog(P1,"Geben Sie die Gesamtzahl der Kugeln an!","Gesamtanzahl der Kugeln",
            P1.INFORMATION_MESSAGE));
    Zahlen=new String[n1];
    Arrays.fill(Zahlen,"");
    int m1=Integer.parseInt(P1.showInputDialog(P1,"Geben Sie die Gesamtzahl der gezogenen Kugeln an!","Gesamtanzahl der gezogenen Kugeln",
            P1.INFORMATION_MESSAGE));
    Z=new Toto(n1,m1);
        int[] tipp = new int[m1];
    for (int i=0; i<m1; i++){
    int i=i+1;
    A="Geben Sie ihren"+j+"ten Tipp ab!";
    b=(String)P1.showInputDialog(P1,A,"Wäheln Sie",P1.PLAIN_MESSAGE,ic,Zahlen,Zahlen[0]);

        P1.showMessageDialog(P1,"Wählen Sie nocheinmal!");}
    
    A="Sie haben"+Z.getRes()"Richtig!";
    int k=Integer.parseInt(P1.showInputDialog(P1,A, "Tippen!",P1.INFORMATION_MESSAGE));
    tipp[i]=k;

    A= new Auswertung (n1,m1);
    Z="Es wurden gezogen";
    Arrays.sort(A.getPrice());
    for (int i=0, i, i<m1, i++);{
    Z=Z+""+A.getPrice()[i];
    }
    P1.showMessageDialog(P1,Z,"Ziehungsergebnis",P1.PLAIN_MESSAGE);

A="Sie haben"+Z.getRes()+"Richtige";
P1.showMessageDialog(P1,A,"Glückwunsch",P1.PLAIN_MESSAGE);
    }                               

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {                                      
        // TODO add your handling code here:
    }                                     

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                Lotto3 dialog = new Lotto3(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    Toto Z;
    Auswertung A;
    // Variables declaration - do not modify                     
    private javax.swing.JOptionPane P1;
    private javax.swing.JButton jButton1;
    // End of variables declaration                   

}
 
Zuletzt bearbeitet von einem Moderator:

Final_Striker

Top Contributor
A="Geben Sie ihren"+j+"ten Tipp ab!";

du hast ein Objekt vom Typ Auswertung und versucht dort einen String rein zu schreiben

A="Sie haben"+Z.getRes()"Richtig!";

fehlt ein + Zeichen.

A="Sie haben"+Z.getRes() + "Richtig!";
 

java86

Neues Mitglied
vielen Dank für die schnelle Antwort. Ich hab gemerkt das ich ganz schön viele Flüchtigkeitsfehler gemacht habe z.B das mit dem + ich habe den Lotto Quelltext nocheinmal überarbeitet. Jetzt habe ich wenigstens nur noch 4 Fehler. Der Erste Fehler ist den ich nicht verstehe j=i+1; ich habe doch das j oben mit int deklariert? Es erscheint die Fehlermeldung incompatible types required: int[] und found: int. Der Zweite Fehler ist bei for(int i=0;i<m;i++) kommt die Meldung i is already defined in jButton 1MouseClicked aber ich weis nicht genau ob ich das einfach umbennen kann. Der Dritte Fehler ist bei Ziehungsauswertung da erscheint connot find symbol symbol:class Ziehungsauswertung und location: class lotto.Lotto4.Der Vierte Fehler ist A="Sie haben"+Z.getRes()+ da erscheint als Fehlermeldung cannot find symbol Symbol: method getRes() location:class java.lang.String.
Vielen Dank für die Hilfe im Vorraus!!!
Java:
 private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {                                      
    String res, T,A,s,b;
    String[]Zahlen;
    int[]tipp;
    int[]j;
    Icon ic=new ImageIcon("C:\\Lotto.jpg");


    int n=Integer.parseInt(P1.showInputDialog
            (P1,"Geben Sie die Gesamzahl der Kugeln an!","Gesamtzahl der Kugeln!",
            P1.INFORMATION_MESSAGE));
    int m=Integer.parseInt(P1.showInputDialog
            (P1,"Geben Sie die Gesamtzahl der gezogenen Kugeln an!","Gesamtzahl der gezogenen Kugeln",
            P1.INFORMATION_MESSAGE));
    tipp=new int[m];
    for(int i=0;i<m; i++){
        j=i+1;
        T="Geben Sie Ihren"+j+"ten Tipp ab!";
        b=(String)P1.showInputDialog(P1,T."Wählen Sie",P1.PLAIN_MESSAGE,Zahlen,Zahlen[0]);
        P1.showInputDialog(P1,"Wählen Sie nochmal!");
        i=i-1;

        int k=Integer.parseInt(P1.showInputDialog
                (P1,T,"Tippen Sie!",P1.INFORMATION_MESSAGE));
        tipp[i]=k;

        L=new Toto(n,m);
        s="Es wurde gezogen";
        Arrays.sort(L.getPrice());
        for(int i=0;i<m;i++){
        s=s+""+L.getPrice()[i];

        P1.showMessageDialog(P1,s,"Ziehungsergebnis",P1.PLAIN_MESSAGE,ic);
        Z=new Ziehungsauswertung(tipp,L.getPrice());
        A="Sie haben"+Z.getRes()+"Richtig";
        P1.showMessageDialog(P1,A,"Glückwunsch",P1.PLAIN_MESSAGE,ic);
        }
    }

    }                                     

    private void P1MouseClicked(java.awt.event.MouseEvent evt) {                                
        // TODO add your handling code here:
    }                               

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Lotto4().setVisible(true);
            }
        });
    }
Toto T;
Auswertung Z;
    // Variables declaration - do not modify                     
    private javax.swing.JOptionPane P1;
    private javax.swing.JButton jButton1;
    // End of variables declaration
 

eRaaaa

Top Contributor
Der Erste Fehler ist den ich nicht verstehe j=i+1; ich habe doch das j oben mit int deklariert?
Dein j ist ein int-Array! :arrow: j[INDEX] = ....
Der Zweite Fehler ist bei for(int i=0;i<m;i++) kommt die Meldung i is already defined in jButton 1MouseClicked aber ich weis nicht genau ob ich das einfach umbennen kann.
Klar, die Schleifenvariable kannst du nennen wie du magst, gewöhnlich nimmt man nach i dann einfach :arrow: (j),k,...
 
Zuletzt bearbeitet:

Oben