JFrame mit neuem JPanel überschreiben

bluue

Mitglied
Hallo Leute!

Ich bin gerade dabei ein kleines game zu programmieren. Ich habe ein JFrame und auf diesem ein JPanel. Durch klick auf einen JButton wir das Panel durch ein anderes ersetzt. Im 2. JPanel wird mit paintComponent und swing gearbeitet. Ich würde nun wieder durch Drücken eines JButtons (zurück) mein 2.JPanel mit dem ersten überschreiben.

Java:
package sudoku;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

public class game {
	 static JFrame fsudoku = new JFrame();
	JPanel start = new JPanel();
	JButton schnellesspiel = new JButton("Schnelles Spiel");
	paint p = new paint();

	
	
	public game()
	{
		fsudoku.setLayout(new BorderLayout());
//		fsudoku.add(p, BorderLayout.CENTER);
		fsudoku.setSize(410,460);
		fsudoku.setLocation(200,200);
		fsudoku.setVisible(true);
		fsudoku.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		
		
		fsudoku.add(start, BorderLayout.CENTER);
		start.setLayout(null);
		start.add(schnellesspiel);
		schnellesspiel.setLocation(15,15);
		schnellesspiel.setSize(100,100);
		schnellesspiel.addActionListener(startspiel);
	
	}
	
	ActionListener startspiel = new ActionListener()
	{
		public void actionPerformed(ActionEvent p1) {
			
			fsudoku.remove(start);
			fsudoku.add(p, BorderLayout.CENTER);
			fsudoku.repaint();
			fsudoku.setSize(411,460);
			fsudoku.setSize(410,460);

		}
		
	};



	
	public static void main(String[] args){
		
		new game();
		
	}

}

Java:
//setsize

package sudoku;

import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class paint extends JPanel {
	File file = new File("C:\\Users\\---\\Desktop\\stest.txt");
	

	JButton fertig = new JButton("Fertig");
	JButton zurueck = new JButton("zurück");
	JButton neuladen = new JButton("neu Laden");
	
	char [] eingabe = new char[999999];
	String textfieldeingabe;

	
	char [] h = new char[99999];
	
	String falsch ="";
	
	int asdf;
	
	int zufallszahl = (int)((Math.random()) * 4 + 1);
	int forstart;
	int forstop;
	int zahlarray;
	int a;
	int e;

//TEXTFELDER-------------------------------------------------------------------------------------------------------
	JTextField a1 = new JTextField("");
	JTextField a2 = new JTextField();
	JTextField a3 = new JTextField();
	JTextField a4 = new JTextField();
	JTextField a5 = new JTextField();
	JTextField a6 = new JTextField();
	JTextField a7 = new JTextField();
	JTextField a8 = new JTextField();
	JTextField a9 = new JTextField();
	JTextField b1 = new JTextField();
	JTextField b2 = new JTextField();
	JTextField b3 = new JTextField();
	JTextField b4 = new JTextField();
	JTextField b5 = new JTextField();
	JTextField b6 = new JTextField();
	JTextField b7 = new JTextField();
	JTextField b8 = new JTextField();
	JTextField b9 = new JTextField();
	JTextField c1 = new JTextField();
	JTextField c2 = new JTextField();
	JTextField c3 = new JTextField();
	JTextField c4 = new JTextField();
	JTextField c5 = new JTextField();
	JTextField c6 = new JTextField();
	JTextField c7 = new JTextField();
	JTextField c8 = new JTextField();
	JTextField c9 = new JTextField("");
	JTextField d1 = new JTextField("");
	JTextField d2 = new JTextField("");
	JTextField d3 = new JTextField("");
	JTextField d4 = new JTextField("");
	JTextField d5 = new JTextField("");
	JTextField d6 = new JTextField("");
	JTextField d7 = new JTextField("");
	JTextField d8 = new JTextField("");
	JTextField d9 = new JTextField("");
	JTextField e1 = new JTextField("");
	JTextField e2 = new JTextField("");
	JTextField e3 = new JTextField("");
	JTextField e4 = new JTextField("");
	JTextField e5 = new JTextField("");
	JTextField e6 = new JTextField("");
	JTextField e7 = new JTextField("");
	JTextField e8 = new JTextField("");
	JTextField e9 = new JTextField("");
	JTextField f1 = new JTextField("");
	JTextField f2 = new JTextField("");
	JTextField f3 = new JTextField("");
	JTextField f4 = new JTextField("");
	JTextField f5 = new JTextField("");
	JTextField f6 = new JTextField("");
	JTextField f7 = new JTextField("");
	JTextField f8 = new JTextField("");
	JTextField f9 = new JTextField("");
	JTextField g1 = new JTextField("");
	JTextField g21 = new JTextField("");
	JTextField g3 = new JTextField("");
	JTextField g4 = new JTextField("");
	JTextField g5 = new JTextField("");
	JTextField g6 = new JTextField("");
	JTextField g7 = new JTextField("");
	JTextField g8 = new JTextField("");
	JTextField g9 = new JTextField("");
	JTextField h1 = new JTextField("");
	JTextField h2 = new JTextField("");
	JTextField h3 = new JTextField("");
	JTextField h4 = new JTextField("");
	JTextField h5 = new JTextField("");
	JTextField h6 = new JTextField("");
	JTextField h7 = new JTextField("");
	JTextField h8 = new JTextField("");
	JTextField h9 = new JTextField("");
	JTextField i1 = new JTextField("");
	JTextField i2 = new JTextField("");
	JTextField i3 = new JTextField("");
	JTextField i4 = new JTextField("");
	JTextField i5 = new JTextField("");
	JTextField i6 = new JTextField("");
	JTextField i7 = new JTextField("");
	JTextField i8 = new JTextField("");
	JTextField i9 = new JTextField("");
	
	JTextField tfausgabe = new JTextField(" ");

	Graphics2D g2;

	
	public void paintComponent(Graphics g) {
		
		g2 = (Graphics2D) g;	
		
		this.setLayout(null);
		add(fertig);
		fertig.setSize(80,40);
		fertig.setLocation(298,380);
		fertig.addActionListener(ALF);
		
		add(zurueck);
		zurueck.setLocation(15,380);
		zurueck.setSize(80,40);
		zurueck.addActionListener(new ALZ());
		
//		add(neuladen);
//		neuladen.setLocation(15,380);
//		neuladen.addActionListener(ALNeu);
		
		add(tfausgabe);
		tfausgabe.setSize(198,40);
		tfausgabe.setLocation(98,380);
		
		
		System.out.println(zufallszahl);

		
		
//	SPIELFELD---------------------------------------------------------------------------------------------------------

		g2.setStroke(new BasicStroke(3));
		g2.setColor(Color.black);
		
		 
		//					breite	länge
		g2.drawRect(15, 15, 360, 360);
		

		//vertical
		g2.drawLine(135, 15, 135, 375);
		g2.drawLine(255, 15, 255, 375);
		//horizontal
		g2.drawLine(15, 135, 375, 135);
		g2.drawLine(15, 255, 375, 255);	
	
		
		g2.setStroke(new BasicStroke(1));				
		int line = 55;
		
		for ( int i = 1; i < 9; i++)
		{
			//vertical
			g2.drawLine(line, 15, line, 375);
			//horizontal
			g2.drawLine(15, line, 375, line);
			line = line + 40;	
			

		}
		

		
	
		
//	EINLESEN---------------------------------------------------------------------------------------------------------

		StringBuffer sb = new StringBuffer();
		
		BufferedReader fr = null;
		try {
			fr = new BufferedReader(new FileReader(new File("sudoku\\stest.txt")));
			} 
		
		
		catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
			
		int anz = 0;
		
		try {
			while((anz = fr.read(h)) >= 0)
			    for(int i = 0; i < anz; i++)
			        sb.append(h[i]);
		} 
		
		
		catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		String diesIstDerKompletteText = sb.toString();
		System.out.println(diesIstDerKompletteText);	
		
//		g2.drawChars(h, 0, 5, 12, 12);

		
//	SPIELFELS BESCHREIBEN---------------------------------------------------------------------------------------------------------
		
		auswahl(zufallszahl);
		
		
		int x = 35;
		int y = 40;
		int y1 = 40;
		int y2 = 40;
		int y3 = 40;
		int y4 = 40;
		int y5 = 40;
		int y6 = 40;
		int y7 = 40;
		int y8 = 40;
		for (e = forstart; e < forstop; e++)
		{
				if( e <= zahlarray)
				{	
					if (h[e] == '0')
					{
						if (e == a){
							a1.setLocation(x-15,y-19);
							a1.setSize(32,32);
							a1.setHorizontalAlignment(JTextField.CENTER);
							this.add(a1);}
						if (e == (a+1)){
							a2.setLocation(x-15,y-19);
							a2.setSize(32,32);
							a2.setHorizontalAlignment(JTextField.CENTER);
							this.add(a2);}
						if (e == (a+2)){
							a3.setLocation(x-15,y-19);
							a3.setSize(32,32);
							a3.setHorizontalAlignment(JTextField.CENTER);
							this.add(a3);}
						if (e == (a+3)){
							a4.setLocation(x-15,y-19);
							a4.setSize(32,32);
							a4.setHorizontalAlignment(JTextField.CENTER);
							this.add(a4);}
						if (e == (a+4)){
							a5.setLocation(x-15,y-19);
							a5.setSize(32,32);
							a5.setHorizontalAlignment(JTextField.CENTER);
							this.add(a5);}
						if (e == (a+5)){
							a6.setLocation(x-15,y-19);
							a6.setSize(32,32);
							a6.setHorizontalAlignment(JTextField.CENTER);
							this.add(a6);}
						if (e == (a+6)){
							a7.setLocation(x-15,y-19);
							a7.setSize(32,32);
							a7.setHorizontalAlignment(JTextField.CENTER);
							this.add(a7);}
						if (e == (a+7)){
							a8.setLocation(x-15,y-19);
							a8.setSize(32,32);
							a8.setHorizontalAlignment(JTextField.CENTER);
							this.add(a8);}
						if (e == (a+8)){
							a9.setLocation(x-15,y-19);
							a9.setSize(32,32);
							a9.setHorizontalAlignment(JTextField.CENTER);
							this.add(a9);}						
						
					}
					else{g2.drawChars(h, e, 1, x, y);}	
					y = y+40;
				}
.
.
.
.
		
}

In diesem bereich sollte das 2.Panel mit dem 1. überschrieben werden.
Java:
package sudoku;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ALZ extends game implements ActionListener  {

	@Override
	public void actionPerformed(ActionEvent alz) {
		fsudoku.remove( p );
		fsudoku.validate(); // <--- ******
		fsudoku.removeAll();
		fsudoku.setVisible(false);
		fsudoku.setVisible(true);
		new game();

	}

}
 
Zuletzt bearbeitet:
Für sowas gibts [JAPI]CardLayout[/JAPI]. Du kannst damit mehrere JPanels übereinander stapeln und anzeigen. Nur das oberste ist dabei sichtbar.
In der FAQ gibts einen Beitrag/Link zum CardLayout.
 
nur mal so als Randbemerkung...meinst du nicht, dass man diesen Codeteil etwas geschickter proggen könnte???

[java=49] JTextField a1 = new JTextField("");
JTextField a2 = new JTextField();
JTextField a3 = new JTextField();
JTextField a4 = new JTextField();
JTextField a5 = new JTextField();
JTextField a6 = new JTextField();
JTextField a7 = new JTextField();
JTextField a8 = new JTextField();
JTextField a9 = new JTextField();
JTextField b1 = new JTextField();
JTextField b2 = new JTextField();
JTextField b3 = new JTextField();
JTextField b4 = new JTextField();
JTextField b5 = new JTextField();
JTextField b6 = new JTextField();
JTextField b7 = new JTextField();
JTextField b8 = new JTextField();
JTextField b9 = new JTextField();
JTextField c1 = new JTextField();
JTextField c2 = new JTextField();
JTextField c3 = new JTextField();
JTextField c4 = new JTextField();
JTextField c5 = new JTextField();
JTextField c6 = new JTextField();
JTextField c7 = new JTextField();
JTextField c8 = new JTextField();
JTextField c9 = new JTextField("");
JTextField d1 = new JTextField("");
JTextField d2 = new JTextField("");
JTextField d3 = new JTextField("");
JTextField d4 = new JTextField("");
JTextField d5 = new JTextField("");
JTextField d6 = new JTextField("");
JTextField d7 = new JTextField("");
JTextField d8 = new JTextField("");
JTextField d9 = new JTextField("");
JTextField e1 = new JTextField("");
JTextField e2 = new JTextField("");
JTextField e3 = new JTextField("");
JTextField e4 = new JTextField("");
JTextField e5 = new JTextField("");
JTextField e6 = new JTextField("");
JTextField e7 = new JTextField("");
JTextField e8 = new JTextField("");
JTextField e9 = new JTextField("");
JTextField f1 = new JTextField("");
JTextField f2 = new JTextField("");
JTextField f3 = new JTextField("");
JTextField f4 = new JTextField("");
JTextField f5 = new JTextField("");
JTextField f6 = new JTextField("");
JTextField f7 = new JTextField("");
JTextField f8 = new JTextField("");
JTextField f9 = new JTextField("");
JTextField g1 = new JTextField("");
JTextField g21 = new JTextField("");
JTextField g3 = new JTextField("");
JTextField g4 = new JTextField("");
JTextField g5 = new JTextField("");
JTextField g6 = new JTextField("");
JTextField g7 = new JTextField("");
JTextField g8 = new JTextField("");
JTextField g9 = new JTextField("");
JTextField h1 = new JTextField("");
JTextField h2 = new JTextField("");
JTextField h3 = new JTextField("");
JTextField h4 = new JTextField("");
JTextField h5 = new JTextField("");
JTextField h6 = new JTextField("");
JTextField h7 = new JTextField("");
JTextField h8 = new JTextField("");
JTextField h9 = new JTextField("");
JTextField i1 = new JTextField("");
JTextField i2 = new JTextField("");
JTextField i3 = new JTextField("");
JTextField i4 = new JTextField("");
JTextField i5 = new JTextField("");
JTextField i6 = new JTextField("");
JTextField i7 = new JTextField("");
JTextField i8 = new JTextField("");
JTextField i9 = new JTextField("");[/code]
 
Moin,

mal 'ne dumme Frage:
[OT]
ich habe jetzt zu den beiden letzten Beiträgen jeweils eine E-Mail-Benachrichtigung bekommen, so als hätte ich hier einen Beitrag geschrieben!

Weiß jemand warum das so ist ???:L
[/OT]

Gruß
Klaus

[EDIT]
Hi Klaus,
Du hast einen Beitrag mit einem Zitat geschrieben.
Der TO hat aber Code zu seinem Beitrag hinzugefügt und so hatte dein Beitrag keinen Kontext mehr und hätte nur für Verwirrung gesorgt. Er wurde von mir daher gelöscht.

L-ectron-X [/EDIT]
 
Zuletzt bearbeitet von einem Moderator:
Ich hab das nun so verändert es funktioniert jedoch trotzdem nicht

Java:
package sudoku;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

public class game {
	static JFrame fsudoku = new JFrame();
	JPanel start = new JPanel();
	JButton schnellesspiel = new JButton("Schnelles Spiel");
	paint p = new paint();
	
	CardLayout cardlayout = new CardLayout();
	JPanel cardPanel = new JPanel();

	
	
	public game()
	{
	
		fsudoku.setSize(410,460);
		fsudoku.setLocation(200,200);
		fsudoku.setVisible(true);
		fsudoku.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		fsudoku.add(cardPanel);
		
		cardPanel.setLayout(cardlayout);
		cardPanel.add(start, "home");
		cardPanel.add(p, "raetsel");
		
		start.setLayout(null);
		start.add(schnellesspiel);
		schnellesspiel.setLocation(15,15);
		schnellesspiel.setSize(100,100);
		schnellesspiel.addActionListener(startspiel);
	
	}
	
	ActionListener startspiel = new ActionListener()
	{
		public void actionPerformed(ActionEvent p1) {
			
			cardlayout.show(cardPanel, "raetsel");

		}
		
	};



	
	public static void main(String[] args){
		
		new game();
		
	}

}

Java:
package sudoku;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ALZ extends game implements ActionListener  {

	@Override
	public void actionPerformed(ActionEvent alz) {
		
		cardlayout.show(cardPanel, "home");

	}

}

jah ich würde es lieber anders machen
aber ich hab noch keine lösung gefunden
hättest duh einen vorschlag

dieses prog ist momentan nur ein entwurf
 
Ich hab das nun so verändert es funktioniert jedoch trotzdem nicht
Das ist irgendwie keine sehr exakte Fehlerbeschreibung. Was heisst denn "es funktioniert nicht" genau?

Wozu soll das gut sein bzw. wo kommt das zum Einsatz?
Java:
package sudoku;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ALZ extends game implements ActionListener  {

	@Override
	public void actionPerformed(ActionEvent alz) {
		
		cardlayout.show(cardPanel, "home");

	}

}

Klassennamen schreibt man gross, also Game anstatt game. Und beim JFrame kommt das setVisible erst ganz zum Schluss.
 
also beim ausführen des codes wird das panel nicht gewechselt es bleibt das 1.panel (home) erhalten

diesen ActionListener wird aus dem 2.Code (oben), für den zurückbutton verwendet.
 
Java:
//setsize

package sudoku;

import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class paint extends JPanel {
	File file = new File("C:\\Users\\---\\Desktop\\stest.txt");
	

	JButton fertig = new JButton("Fertig");
	JButton zurueck = new JButton("zurück");
	JButton neuladen = new JButton("neu Laden");
	
	char [] eingabe = new char[999999];
	String textfieldeingabe;

	
	char [] h = new char[99999];
	
	String falsch ="";
	
	int asdf;
	
	int zufallszahl = (int)((Math.random()) * 4 + 1);
	int forstart;
	int forstop;
	int zahlarray;
	int a;
	int e;

//TEXTFELDER-------------------------------------------------------------------------------------------------------
	JTextField a1 = new JTextField("");
	JTextField a2 = new JTextField();
	JTextField a3 = new JTextField();
	JTextField a4 = new JTextField();
	JTextField a5 = new JTextField();
	JTextField a6 = new JTextField();
	JTextField a7 = new JTextField();
	JTextField a8 = new JTextField();
	JTextField a9 = new JTextField();
	JTextField b1 = new JTextField();
	JTextField b2 = new JTextField();
	JTextField b3 = new JTextField();
	JTextField b4 = new JTextField();
	JTextField b5 = new JTextField();
	JTextField b6 = new JTextField();
	JTextField b7 = new JTextField();
	JTextField b8 = new JTextField();
	JTextField b9 = new JTextField();
	JTextField c1 = new JTextField();
	JTextField c2 = new JTextField();
	JTextField c3 = new JTextField();
	JTextField c4 = new JTextField();
	JTextField c5 = new JTextField();
	JTextField c6 = new JTextField();
	JTextField c7 = new JTextField();
	JTextField c8 = new JTextField();
	JTextField c9 = new JTextField("");
	JTextField d1 = new JTextField("");
	JTextField d2 = new JTextField("");
	JTextField d3 = new JTextField("");
	JTextField d4 = new JTextField("");
	JTextField d5 = new JTextField("");
	JTextField d6 = new JTextField("");
	JTextField d7 = new JTextField("");
	JTextField d8 = new JTextField("");
	JTextField d9 = new JTextField("");
	JTextField e1 = new JTextField("");
	JTextField e2 = new JTextField("");
	JTextField e3 = new JTextField("");
	JTextField e4 = new JTextField("");
	JTextField e5 = new JTextField("");
	JTextField e6 = new JTextField("");
	JTextField e7 = new JTextField("");
	JTextField e8 = new JTextField("");
	JTextField e9 = new JTextField("");
	JTextField f1 = new JTextField("");
	JTextField f2 = new JTextField("");
	JTextField f3 = new JTextField("");
	JTextField f4 = new JTextField("");
	JTextField f5 = new JTextField("");
	JTextField f6 = new JTextField("");
	JTextField f7 = new JTextField("");
	JTextField f8 = new JTextField("");
	JTextField f9 = new JTextField("");
	JTextField g1 = new JTextField("");
	JTextField g21 = new JTextField("");
	JTextField g3 = new JTextField("");
	JTextField g4 = new JTextField("");
	JTextField g5 = new JTextField("");
	JTextField g6 = new JTextField("");
	JTextField g7 = new JTextField("");
	JTextField g8 = new JTextField("");
	JTextField g9 = new JTextField("");
	JTextField h1 = new JTextField("");
	JTextField h2 = new JTextField("");
	JTextField h3 = new JTextField("");
	JTextField h4 = new JTextField("");
	JTextField h5 = new JTextField("");
	JTextField h6 = new JTextField("");
	JTextField h7 = new JTextField("");
	JTextField h8 = new JTextField("");
	JTextField h9 = new JTextField("");
	JTextField i1 = new JTextField("");
	JTextField i2 = new JTextField("");
	JTextField i3 = new JTextField("");
	JTextField i4 = new JTextField("");
	JTextField i5 = new JTextField("");
	JTextField i6 = new JTextField("");
	JTextField i7 = new JTextField("");
	JTextField i8 = new JTextField("");
	JTextField i9 = new JTextField("");
	
	JTextField tfausgabe = new JTextField(" ");

	Graphics2D g2;

	
	public void paintComponent(Graphics g) {
		
		g2 = (Graphics2D) g;	
		
		this.setLayout(null);
		add(fertig);
		fertig.setSize(80,40);
		fertig.setLocation(298,380);
		fertig.addActionListener(ALF);
		
		add(zurueck);
		zurueck.setLocation(15,380);
		zurueck.setSize(80,40);
		zurueck.addActionListener(new ALZ());
		
//		add(neuladen);
//		neuladen.setLocation(15,380);
//		neuladen.addActionListener(ALNeu);
		
		add(tfausgabe);
		tfausgabe.setSize(198,40);
		tfausgabe.setLocation(98,380);
		
		
		System.out.println(zufallszahl);

		
		
//	SPIELFELD---------------------------------------------------------------------------------------------------------

		g2.setStroke(new BasicStroke(3));
		g2.setColor(Color.black);
		
		 
		//					breite	länge
		g2.drawRect(15, 15, 360, 360);
		

		//vertical
		g2.drawLine(135, 15, 135, 375);
		g2.drawLine(255, 15, 255, 375);
		//horizontal
		g2.drawLine(15, 135, 375, 135);
		g2.drawLine(15, 255, 375, 255);	
	
		
		g2.setStroke(new BasicStroke(1));				
		int line = 55;
		
		for ( int i = 1; i < 9; i++)
		{
			//vertical
			g2.drawLine(line, 15, line, 375);
			//horizontal
			g2.drawLine(15, line, 375, line);
			line = line + 40;	
			

		}
		

		
	
		
//	EINLESEN---------------------------------------------------------------------------------------------------------

		StringBuffer sb = new StringBuffer();
		
		BufferedReader fr = null;
		try {
			fr = new BufferedReader(new FileReader(new File("sudoku\\stest.txt")));
			} 
		
		
		catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
			
		int anz = 0;
		
		try {
			while((anz = fr.read(h)) >= 0)
			    for(int i = 0; i < anz; i++)
			        sb.append(h[i]);
		} 
		
		
		catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		String diesIstDerKompletteText = sb.toString();
		System.out.println(diesIstDerKompletteText);	
		
//		g2.drawChars(h, 0, 5, 12, 12);
 
Mach doch mal in dem oberen Code anstatt:
Java:
schnellesspiel.addActionListener(startspiel);
    
    }
    
    ActionListener startspiel = new ActionListener()
    {
        public void actionPerformed(ActionEvent p1) {
            
            cardlayout.show(cardPanel, "raetsel");
 
        }
        
    };
sowas:
Java:
schnellesspiel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent p1) {
            cardlayout.show(cardPanel, "raetsel");
        }   
});

2.Teil des codes
Java:
/
		
		auswahl(zufallszahl);
		int x = 35;
		int y = 40;
		int y1 = 40;
		int y2 = 40;
		int y3 = 40;
		int y4 = 40;
		int y5 = 40;
		int y6 = 40;
		int y7 = 40;
		int y8 = 40;
		for (e = forstart; e < forstop; e++)
		{
				if( e <= zahlarray)
				{	
					if (h[e] == '0')
					{
						if (e == a){
							a1.setLocation(x-15,y-19);
							a1.setSize(32,32);
							a1.setHorizontalAlignment(JTextField.CENTER);
							this.add(a1);}
						if (e == (a+1)){
							a2.setLocation(x-15,y-19);
							a2.setSize(32,32);
							a2.setHorizontalAlignment(JTextField.CENTER);
							this.add(a2);}
						if (e == (a+2)){
							a3.setLocation(x-15,y-19);
							a3.setSize(32,32);
							a3.setHorizontalAlignment(JTextField.CENTER);
							this.add(a3);}
						if (e == (a+3)){
							a4.setLocation(x-15,y-19);
							a4.setSize(32,32);
							a4.setHorizontalAlignment(JTextField.CENTER);
							this.add(a4);}
						if (e == (a+4)){
							a5.setLocation(x-15,y-19);
							a5.setSize(32,32);
							a5.setHorizontalAlignment(JTextField.CENTER);
							this.add(a5);}
						if (e == (a+5)){
							a6.setLocation(x-15,y-19);
							a6.setSize(32,32);
							a6.setHorizontalAlignment(JTextField.CENTER);
							this.add(a6);}
						if (e == (a+6)){
							a7.setLocation(x-15,y-19);
							a7.setSize(32,32);
							a7.setHorizontalAlignment(JTextField.CENTER);
							this.add(a7);}
						if (e == (a+7)){
							a8.setLocation(x-15,y-19);
							a8.setSize(32,32);
							a8.setHorizontalAlignment(JTextField.CENTER);
							this.add(a8);}
						if (e == (a+8)){
							a9.setLocation(x-15,y-19);
							a9.setSize(32,32);
							a9.setHorizontalAlignment(JTextField.CENTER);
							this.add(a9);}						
						
					}
					else{g2.drawChars(h, e, 1, x, y);}	
					y = y+40;
				}
			else{
				if ( e <= (zahlarray+9))
				{
					if (h[e] == '0')
					{
						if (e == (a+9)){
							b1.setLocation(75-15,y1-19);
							b1.setSize(32,32);
							b1.setHorizontalAlignment(JTextField.CENTER);
							this.add(b1);}
						if (e == (a+10)){ 
							b2.setLocation(75-15,y1-19);
							b2.setSize(32,32);
							b2.setHorizontalAlignment(JTextField.CENTER);
							this.add(b2);}
						if (e == (a+11)){
							b3.setLocation(75-15,y1-19);
							b3.setSize(32,32);
							b3.setHorizontalAlignment(JTextField.CENTER);
							this.add(b3);}
						if (e == (a+12)){
							b4.setLocation(75-15,y1-19);
							b4.setSize(32,32);
							b4.setHorizontalAlignment(JTextField.CENTER);
							this.add(b4);}
						if (e == (a+13)){
							b5.setLocation(75-15,y1-19);
							b5.setSize(32,32);
							b5.setHorizontalAlignment(JTextField.CENTER);
							this.add(b5);}
						if (e == (a+14)){
							b6.setLocation(75-15,y1-19);
							b6.setSize(32,32);
							b6.setHorizontalAlignment(JTextField.CENTER);
							this.add(b6);}
						if (e == (a+15)){
							b7.setLocation(75-15,y1-19);
							b7.setSize(32,32);
							b7.setHorizontalAlignment(JTextField.CENTER);
							this.add(b7);}
						if (e == (a+16)){
							b8.setLocation(75-15,y1-19);
							b8.setSize(32,32);
							b8.setHorizontalAlignment(JTextField.CENTER);
							this.add(b8);}
						if (e == (a+17)){
							b9.setLocation(75-15,y1-19);
							b9.setSize(32,32);
							b9.setHorizontalAlignment(JTextField.CENTER);
							this.add(b9);}												
					}		
					else{g2.drawChars(h, e, 1, 75, y1);}
					y1 = y1+ 40;
				}				
			else 
				{
				if (e<=(zahlarray+18))
				{
					if (h[e] == '0')
					{
						if (e == (a+18)){
							c1.setLocation(115-15,y2-19);
							c1.setSize(32,32);
							c1.setHorizontalAlignment(JTextField.CENTER);
							this.add(c1);}
						if (e == (a+19)){ 
							c2.setLocation(115-15,y2-19);
							c2.setSize(32,32);
							c2.setHorizontalAlignment(JTextField.CENTER);
							this.add(c2);}
						if (e == (a+20)){
							c3.setLocation(115-15,y2-19);
							c3.setSize(32,32);
							c3.setHorizontalAlignment(JTextField.CENTER);
							this.add(c3);}
						if (e == (a+21)){
							c4.setLocation(115-15,y2-19);
							c4.setSize(32,32);
							c4.setHorizontalAlignment(JTextField.CENTER);
							this.add(c4);}
						if (e == (a+22)){
							c5.setLocation(115-15,y2-19);
							c5.setSize(32,32);
							c5.setHorizontalAlignment(JTextField.CENTER);
							this.add(c5);}
						if (e == (a+23)){
							c6.setLocation(115-15,y2-19);
							c6.setSize(32,32);
							c6.setHorizontalAlignment(JTextField.CENTER);
							this.add(c6);}
						if (e == (a+24)){
							c7.setLocation(115-15,y2-19);
							c7.setSize(32,32);
							c7.setHorizontalAlignment(JTextField.CENTER);
							this.add(c7);}
						if (e == (a+25)){
							c8.setLocation(115-15,y2-19);
							c8.setSize(32,32);
							c8.setHorizontalAlignment(JTextField.CENTER);
							this.add(c8);}
						if (e == (a+26)){
							c9.setLocation(115-15,y2-19);
							c9.setSize(32,32);
							c9.setHorizontalAlignment(JTextField.CENTER);
							this.add(c9);}											
					}		
					else{g2.drawChars(h, e, 1, 115, y2);}
					y2 = y2+ 40;
				}
			else
				{
				if (e<=(zahlarray+27))
				{
					if (h[e] == '0')
					{

						if (e == (a+27)){
							d1.setLocation(155-15,y3-19);
							d1.setSize(32,32);
							d1.setHorizontalAlignment(JTextField.CENTER);
							this.add(d1);}
						if (e == (a+28)){ 
							d2.setLocation(155-15,y3-19);
							d2.setSize(32,32);
							d2.setHorizontalAlignment(JTextField.CENTER);
							this.add(d2);}
						if (e == (a+29)){ 
							d3.setLocation(155-15,y3-19);
							d3.setSize(32,32);
							d3.setHorizontalAlignment(JTextField.CENTER);
							this.add(d3);}
						if (e == (a+30)){
							d4.setLocation(155-15,y3-19);
							d4.setSize(32,32);
							d4.setHorizontalAlignment(JTextField.CENTER);
							this.add(d4);}
						if (e == (a+31)){
							d5.setLocation(155-15,y3-19);
							d5.setSize(32,32);
							d5.setHorizontalAlignment(JTextField.CENTER);
							this.add(d5);}
						if (e == (a+32)){
							d6.setLocation(155-15,y3-19);
							d6.setSize(32,32);
							d6.setHorizontalAlignment(JTextField.CENTER);
							this.add(d6);}
						if (e == (a+33)){
							d7.setLocation(155-15,y3-19);
							d7.setSize(32,32);
							d7.setHorizontalAlignment(JTextField.CENTER);
							this.add(d7);}
						if (e == (a+34)){
							d8.setLocation(155-15,y3-19);
							d8.setSize(32,32);
							d8.setHorizontalAlignment(JTextField.CENTER);
							this.add(d8);}
						if (e == (a+35)){
							d9.setLocation(155-15,y3-19);
							d9.setSize(32,32);
							d9.setHorizontalAlignment(JTextField.CENTER);
							this.add(d9);}																
					}		
					else{g2.drawChars(h, e, 1, 155, y3);}
					y3 = y3+ 40;
				}
			else
				{
				if (e<=(zahlarray+36))
				{
					if (h[e] == '0')
					{
						if (e == (a+36)){
							e1.setLocation(195-15,y4-19);
							e1.setSize(32,32);
							e1.setHorizontalAlignment(JTextField.CENTER);
							this.add(e1);}
						if (e == (a+37)){ 
							e2.setLocation(195-15,y4-19);
							e2.setSize(32,32);
							e2.setHorizontalAlignment(JTextField.CENTER);
							this.add(e2);}
						if (e == (a+38)){ 
							e3.setLocation(195-15,y4-19);
							e3.setSize(32,32);
							e3.setHorizontalAlignment(JTextField.CENTER);
							this.add(e3);}
						if (e == (a+39)){ 
							e4.setLocation(195-15,y4-19);
							e4.setSize(32,32);
							e4.setHorizontalAlignment(JTextField.CENTER);
							this.add(e4);}
						if (e == (a+40)){
							e5.setLocation(195-15,y4-19);
							e5.setSize(32,32);
							e5.setHorizontalAlignment(JTextField.CENTER);
							this.add(e5);}
						if (e == (a+41)){
							e6.setLocation(195-15,y4-19);
							e6.setSize(32,32);
							e6.setHorizontalAlignment(JTextField.CENTER);
							this.add(e6);}
						if (e == (a+42)){
							e7.setLocation(195-15,y4-19);
							e7.setSize(32,32);
							e7.setHorizontalAlignment(JTextField.CENTER);
							this.add(e7);}
						if (e == (a+43)){
							e8.setLocation(195-15,y4-19);
							e8.setSize(32,32);
							e8.setHorizontalAlignment(JTextField.CENTER);
							this.add(e8);}
						if (e == (a+44)){
							e9.setLocation(195-15,y4-19);
							e9.setSize(32,32);
							e9.setHorizontalAlignment(JTextField.CENTER);
							this.add(e9);}								
					}
					else{g2.drawChars(h, e, 1, 195, y4);}
					y4 = y4+ 40;
				}
				
			else
				{
				if (e<=(zahlarray+45))
				{
					if (h[e] == '0')
					{
						if (e == (a+45)){
							f1.setLocation(235-15,y5-19);
							f1.setSize(32,32);
							f1.setHorizontalAlignment(JTextField.CENTER);
							this.add(f1);}
						if (e == (a+46)){ 
							f2.setLocation(235-15,y5-19);
							f2.setSize(32,32);
							f2.setHorizontalAlignment(JTextField.CENTER);
							this.add(f2);}
						if (e == (a+47)){ 
							f3.setLocation(235-15,y5-19);
							f3.setSize(32,32);
							f3.setHorizontalAlignment(JTextField.CENTER);
							this.add(f3);}
						if (e == (a+48)){ 
							f4.setLocation(235-15,y5-19);
							f4.setSize(32,32);
							f4.setHorizontalAlignment(JTextField.CENTER);
							this.add(f4);}
						if (e == (a+49)){
							f5.setLocation(235-15,y5-19);
							f5.setSize(32,32);
							f5.setHorizontalAlignment(JTextField.CENTER);
							this.add(f5);}
						if (e == (a+50)){
							f6.setLocation(235-15,y5-19);
							f6.setSize(32,32);
							f6.setHorizontalAlignment(JTextField.CENTER);
							this.add(f6);}
						if (e == (a+51)){
							f7.setLocation(235-15,y5-19);
							f7.setSize(32,32);
							f7.setHorizontalAlignment(JTextField.CENTER);
							this.add(f7);}
						if (e == (a+52)){
							f8.setLocation(235-15,y5-19);
							f8.setSize(32,32);
							f8.setHorizontalAlignment(JTextField.CENTER);
							this.add(f8);}
						if (e == (a+53)){
							f9.setLocation(235-15,y5-19);
							f9.setSize(32,32);
							f9.setHorizontalAlignment(JTextField.CENTER);
							this.add(f9);}							
					}
					else{g2.drawChars(h, e, 1, 235, y5);}
					y5 = y5+ 40;
				}		
			else
				{
				if (e<=(zahlarray+54))
				{
					if (h[e] == '0')
					{
						if (e == (a+54)){
							g1.setLocation(275-15,y6-19);
							g1.setSize(32,32);
							g1.setHorizontalAlignment(JTextField.CENTER);
							this.add(g1);}
						if (e == (a+55)){ 
							g21.setLocation(275-15,y6-19);
							g21.setSize(32,32);
							g21.setHorizontalAlignment(JTextField.CENTER);
							this.add(g21);}
						if (e == (a+56)){
							g3.setLocation(275-15,y6-19);
							g3.setSize(32,32);
							g3.setHorizontalAlignment(JTextField.CENTER);
							this.add(g3);}
						if (e == (a+57)){ 
							g4.setLocation(275-15,y6-19);
							g4.setSize(32,32);
							g4.setHorizontalAlignment(JTextField.CENTER);
							this.add(g4);}
						if (e == (a+58)){
							g5.setLocation(275-15,y6-19);
							g5.setSize(32,32);
							g5.setHorizontalAlignment(JTextField.CENTER);
							this.add(g5);}
						if (e == (a+59)){
							g6.setLocation(275-15,y6-19);
							g6.setSize(32,32);
							g6.setHorizontalAlignment(JTextField.CENTER);
							this.add(g6);}
						if (e == (a+60)){
							g7.setLocation(275-15,y6-19);
							g7.setSize(32,32);
							g7.setHorizontalAlignment(JTextField.CENTER);
							this.add(g7);}
						if (e == (a+61)){
							g8.setLocation(275-15,y6-19);
							g8.setSize(32,32);
							g8.setHorizontalAlignment(JTextField.CENTER);
							this.add(g8);}
						if (e == (a+62)){
							g9.setLocation(275-15,y6-19);
							g9.setSize(32,32);
							g9.setHorizontalAlignment(JTextField.CENTER);
							this.add(g9);}							
					}
					else{g2.drawChars(h, e, 1, 275, y6);}
					y6 = y6+ 40;
				}
			else
				{
				if (e<=(zahlarray+63))
				{
					if (h[e] == '0')
					{
						if (e == (a+63)){ 
							h1.setLocation(315-15,y7-19);
							h1.setSize(32,32);
							h1.setHorizontalAlignment(JTextField.CENTER);
							this.add(h1);}
						if (e == (a+64)){
							h2.setLocation(315-15,y7-19);
							h2.setSize(32,32);
							h2.setHorizontalAlignment(JTextField.CENTER);
							this.add(h2);}
						if (e == (a+65)){
							h3.setLocation(315-15,y7-19);
							h3.setSize(32,32);
							h3.setHorizontalAlignment(JTextField.CENTER);
							this.add(h3);}
						if (e == (a+66)){ 
							h4.setLocation(315-15,y7-19);
							h4.setSize(32,32);
							h4.setHorizontalAlignment(JTextField.CENTER);
							this.add(h4);}
						if (e == (a+67)){
							h5.setLocation(315-15,y7-19);
							h5.setSize(32,32);
							h5.setHorizontalAlignment(JTextField.CENTER);
							this.add(h5);}
						if (e == (a+68)){
							h6.setLocation(315-15,y7-19);
							h6.setSize(32,32);
							h6.setHorizontalAlignment(JTextField.CENTER);
							this.add(h6);}
						if (e == (a+69)){
							h7.setLocation(315-15,y7-19);
							h7.setSize(32,32);
							h7.setHorizontalAlignment(JTextField.CENTER);
							this.add(h7);}
						if (e == (a+70)){
							h8.setLocation(315-15,y7-19);
							h8.setSize(32,32);
							h8.setHorizontalAlignment(JTextField.CENTER);
							this.add(h8);}
						if (e == (a+71)){
							h9.setLocation(315-15,y7-19);
							h9.setSize(32,32);
							h9.setHorizontalAlignment(JTextField.CENTER);
							this.add(h9);}				
					}
					else{g2.drawChars(h, e, 1, 315, y7);}
					y7 = y7+ 40;
				}
			else
				{
				if (e<=(zahlarray+72))
				{
					if (h[e] == '0')
					{
						if (e == (a+72)){ 
							i1.setLocation(355-15,y8-19);
							i1.setSize(32,32);
							i1.setHorizontalAlignment(JTextField.CENTER);
							this.add(i1);}
						if (e == (a+73)){
							i2.setLocation(355-15,y8-19);
							i2.setSize(32,32);
							i2.setHorizontalAlignment(JTextField.CENTER);
							this.add(i2);}
						if (e == (a+74)){ 
							i3.setLocation(355-15,y8-19);
							i3.setSize(32,32);
							i3.setHorizontalAlignment(JTextField.CENTER);
							this.add(i3);}
						if (e == (a+75)){
							i4.setLocation(355-15,y8-19);
							i4.setSize(32,32);
							i4.setHorizontalAlignment(JTextField.CENTER);
							this.add(i4);}
						if (e == (a+76)){
							i5.setLocation(355-15,y8-19);
							i5.setSize(32,32);
							i5.setHorizontalAlignment(JTextField.CENTER);
							this.add(i5);}
						if (e == (a+77)){
							i6.setLocation(355-15,y8-19);
							i6.setSize(32,32);
							i6.setHorizontalAlignment(JTextField.CENTER);
							this.add(i6);}
						if (e == (a+78)){
							i7.setLocation(355-15,y8-19);
							i7.setSize(32,32);
							i7.setHorizontalAlignment(JTextField.CENTER);
							this.add(i7);}
						if (e == (a+79)){
							i8.setLocation(355-15,y8-19);
							i8.setSize(32,32);
							i8.setHorizontalAlignment(JTextField.CENTER);
							this.add(i8);}
						if (e == (a+80)){
							i9.setLocation(355-15,y8-19);
							i9.setSize(32,32);
							i9.setHorizontalAlignment(JTextField.CENTER);
							this.add(i9);}					
					}
					else{g2.drawChars(h, e, 1, 355, y8);}
					y8 = y8+ 40;
				
				}
				
			}}}}}}}}
				

				
		
		}	
		System.out.println(e);
	}
	
	ActionListener ALF = new ActionListener()  {
		public void actionPerformed(ActionEvent e) {
			
			textfieldeingabe = a1.getText() + a2.getText() + a3.getText() + a4.getText() + a5.getText() + a6.getText() + a7.getText() + a8.getText() + a9.getText()
					 + b1.getText() + b2.getText() + b3.getText() + b4.getText() + b5.getText() + b6.getText() + b7.getText() + b8.getText() + b9.getText()
					  + c1.getText() + c2.getText() + c3.getText() + c4.getText() + c5.getText() + c6.getText() + c7.getText() + c8.getText() + c9.getText()
					  + d1.getText() + d2.getText() + d3.getText() + d4.getText() + d5.getText() + d6.getText() + d7.getText() + d8.getText() + d8.getText()
					  + e1.getText() + e2.getText() + e3.getText() + e4.getText() + e5.getText() + e6.getText() + e7.getText() + e8.getText() + e9.getText()
					  + f1.getText() + f2.getText() + f3.getText() + f4.getText() + f5.getText() + f6.getText() + f7.getText() + f8.getText() + f9.getText()
					  + g1.getText() + g21.getText() + g3.getText() + g4.getText() + g5.getText() + g6.getText() + g7.getText() + g8.getText() + g9.getText()
					  + h1.getText() + h2.getText() + h3.getText() + h4.getText() + h5.getText() + h6.getText() + h7.getText() + h8.getText() + h9.getText()
					  + i1.getText() + i2.getText() + i3.getText() + i4.getText() + i5.getText() + i6.getText() + i7.getText() + i8.getText() + i9.getText();
			eingabe = textfieldeingabe.toCharArray();
			

			

			
			
			
//			System.out.println(eingabe);
		

////////////////////////////////////////////////////////////////////
			
			ueberpruefung(5,6,7,8,9,10,11,12,13);
			ueberpruefung(14,15,16,17,18,19,20,21,22);
			ueberpruefung(23,24,25,26,27,28,29,30,31);
			ueberpruefung(32,33,34,35,36,37,38,39,40);
			ueberpruefung(41,42,43,44,45,46,47,48,49);
			ueberpruefung(50,51,52,53,54,55,56,57,58);
			ueberpruefung(59,60,61,62,63,64,65,66,67);
			ueberpruefung(68,69,70,71,72,73,74,75,76);
			ueberpruefung(77,78,79,80,81,82,83,84,85);
			
			ueberpruefung(5,14,23,32,41,50,59,68,77);
			ueberpruefung(6,15,24,33,42,51,60,69,78);
			ueberpruefung(7,16,25,34,43,52,61,70,79);
			ueberpruefung(8,17,26,35,44,53,62,71,80);
			ueberpruefung(9,18,27,36,45,54,63,72,81);
			ueberpruefung(10,19,28,37,46,55,64,73,82);
			ueberpruefung(11,20,29,38,47,56,65,74,83);
			ueberpruefung(12,21,30,39,48,57,66,75,84);
			ueberpruefung(13,22,31,40,49,58,67,76,85);
			
			ausgabe();
			
		}		
	};

	public void ueberpruefung (int zahl1, int zahl2, int zahl3, int zahl4, int zahl5, int zahl6, int zahl7, int zahl8, int zahl9)
	{
		int probiernfor1 = 0;


		for(int ergfor = 5; ergfor <= zahl9; ergfor++)
		{

			if(ergfor == zahl1 || ergfor == zahl2 ||ergfor == zahl3 ||ergfor == zahl4 ||ergfor == zahl5
					||ergfor == zahl6 ||ergfor == zahl7 ||ergfor == zahl8 ||ergfor == zahl9)
			{
			

			int probiernfor = h[ergfor] -48;

			
			probiernfor1 = probiernfor1 + probiernfor;
			
// 48 weil 0 laut ASCII Code = 30h = 48Dezimal!
			if((h[ergfor]) == 48){
				
				int check;

				switch(ergfor){
				case 5:   check = Integer.parseInt(a1.getText());probiernfor1 = probiernfor1 + check;break;
				case 6:   check = Integer.parseInt(a2.getText());probiernfor1 = probiernfor1 + check;break;
				case 7:   check = Integer.parseInt(a3.getText());probiernfor1 = probiernfor1 + check;break;
				case 8:   check = Integer.parseInt(a4.getText());probiernfor1 = probiernfor1 + check;break;
				case 9:   check = Integer.parseInt(a5.getText());probiernfor1 = probiernfor1 + check;break;
				case 10:  check = Integer.parseInt(a6.getText());probiernfor1 = probiernfor1 + check;break;
				case 11:  check = Integer.parseInt(a7.getText());probiernfor1 = probiernfor1 + check;break;
				case 12:  check = Integer.parseInt(a8.getText());probiernfor1 = probiernfor1 + check;break;
				case 13:  check = Integer.parseInt(a9.getText());probiernfor1 = probiernfor1 + check;break;
				case 14:  check = Integer.parseInt(b1.getText());probiernfor1 = probiernfor1 + check;break;
				case 15:  check = Integer.parseInt(b2.getText());probiernfor1 = probiernfor1 + check;break;
				case 16:  check = Integer.parseInt(b3.getText());probiernfor1 = probiernfor1 + check;break;
				case 17:  check = Integer.parseInt(b4.getText());probiernfor1 = probiernfor1 + check;break;
				case 18:  check = Integer.parseInt(b5.getText());probiernfor1 = probiernfor1 + check;break;
				case 19:   check = Integer.parseInt(b6.getText());probiernfor1 = probiernfor1 + check;break;
				case 20:   check = Integer.parseInt(b7.getText());probiernfor1 = probiernfor1 + check;break;
				case 21:   check = Integer.parseInt(b8.getText());probiernfor1 = probiernfor1 + check;break;
				case 22:   check = Integer.parseInt(b9.getText());probiernfor1 = probiernfor1 + check;break;
				case 23:   check = Integer.parseInt(c1.getText());probiernfor1 = probiernfor1 + check;break;
				case 24:   check = Integer.parseInt(c2.getText());probiernfor1 = probiernfor1 + check;break;
				case 25:   check = Integer.parseInt(c3.getText());probiernfor1 = probiernfor1 + check;break;
				case 26:   check = Integer.parseInt(c4.getText());probiernfor1 = probiernfor1 + check;break;
				case 27:   check = Integer.parseInt(c5.getText());probiernfor1 = probiernfor1 + check;break;
				case 28:   check = Integer.parseInt(c6.getText());probiernfor1 = probiernfor1 + check;break;
				case 29:   check = Integer.parseInt(c7.getText());probiernfor1 = probiernfor1 + check;break;
				case 30:   check = Integer.parseInt(c8.getText());probiernfor1 = probiernfor1 


					}
				}
			
			}
			

		}
		System.out.println(probiernfor1);
		asdf=probiernfor1;
		
	}
		
	public void ausgabe ()
	{


		if(asdf == 45){
			
			
			tfausgabe.setText("Sudoku wurde richtig gelöst!");
		}
		else{
			
			
			tfausgabe.setText("Sudoku nicht richtig gelöst!");
			
			
			
		}
		
	}
	
	public void auswahl (int i)

	{
		if (i == 1)
		{
			forstart = 5;
			forstop = 87;
			zahlarray = 13;
			a=5;
			System.out.println("a ist gleich" +a);
		}
		else
		{
			forstart =5+ (86*(i-1));
			forstop =87+ (86*(i-1));
			zahlarray =  13+ (86*(i-1));
			a= 5+ (86*(i-1));
			System.out.println("a ist gleich" +a);


		}
		
	}

		

		
		
}
 
Äääh, wozu ist diese Masse an Code jetzt gedacht? Was hat das mit dem CardLayout-Problem zu tun? Ich versteh nur noch Bahnhof. Vor allem: versuch mal den Code sinnvoll zu verkürzen, dann wird es bestimmt übersichtlicher und verständlicher.
 
das funktioniert leider auch nicht ganz.

das problem ist, dass des Panels wird ausgeführt, die Gui jedoch nicht richtig aufgebaut. wenn ich mit der maus über die Frame klicke werden die einzellnen textfields sichtbar

Java:
public class game {
	static JFrame fsudoku = new JFrame();
	JPanel start = new JPanel();
	JButton schnellesspiel = new JButton("Schnelles Spiel");
	paint p = new paint();
	
	CardLayout cardlayout = new CardLayout();
	JPanel cardPanel = new JPanel();

	
	
	public game()
	{
	
		fsudoku.setSize(410,460);
		fsudoku.setLocation(200,200);
		fsudoku.setVisible(true);
		fsudoku.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		fsudoku.add(cardPanel);
		
		cardPanel.setLayout(cardlayout);
		cardPanel.add(start, "home");
		cardPanel.add(p, "raetsel");
		
		start.setLayout(null);
		start.add(schnellesspiel);
		schnellesspiel.setLocation(15,15);
		schnellesspiel.setSize(100,100);
		schnellesspiel.addActionListener(new ActionListener() {
	        public void actionPerformed(ActionEvent p1) {
	            cardlayout.show(cardPanel, "raetsel");
	        }   
	});
	
	}


	
	public static void main(String[] args){
		
		new game();
		
	}

}

Java:
public class paint extends JPanel {
public void paintComponent(Graphics g) {
		
		g2 = (Graphics2D) g;	
		
		this.setLayout(null);
		add(fertig);
		fertig.setSize(80,40);
		fertig.setLocation(298,380);
		fertig.addActionListener(ALF);
		
		add(zurueck);
		zurueck.setLocation(15,380);
		zurueck.setSize(80,40);
		zurueck.addActionListener(new ALZ());

Java:
public class ALZ extends game implements ActionListener  {

	@Override
	public void actionPerformed(ActionEvent alz) {
		
		
		cardlayout.show(cardPanel, "home");

	}

}

sry nun habe ich den code gekürtzt
 
Bist du dir überhaupt sicher, was du da tust? Vielleicht solltest du nochmal klein und einfach mit der GUI anfangen und dann nach und nach um Komponenten erweitern, aber am besten gleich sinnvoll strukturieren und nicht so viele Sachen mehrfach schreiben. Das lässt sich sehr verkürzen. Und glaub mir, danach wird es übersichtlicher. Und ich weiss ehrlich gesagt nicht, was dies mit der Ausgangsfrage zu tun hat, wo es noch um CardLayout und Buttonklicks (ActionListener) ging.

Nochmal: schreib die Klassennamen vorne mit einem Grossbuchstaben (Game) und beim JFrame das setVisible(true) nicht irgendwo mittendrin, sondern erst zum Schluss. Weil du sonst den Frame schon sichtbar machst, obwohl noch garnnicht alle Komponenten hinzugefügt wurden.
 

Zurück
Oben