G
Guest
Gast
Hi,
ich versuche mich grade an einem Sudoku Spiel.. Das Aussehen hab ich schon alles so hinbekommen wie es in etwa sein sollte.. nun hab ich aber ein kleines Problem.. (ich weiß ist viel Code aber ich wüsste nicht wo ich noch was kürzen kann). Also ich versuche mal kurz zu erklären was ich da mache.. Ich habe ne SField Klasse die ein Feld das eine Zahl des Spiels beinhaltet darstellt.. dann ne STile Klasse die ein 3x3 Feld aus SFields darstellt und zuguterletzt ne SBoard Klasse die 3x3 STiles darstellt. SMainFrame ist einfach nur der Frame in dem das Board dann dargestellt wird.
Wenn ich jetzt aber in der Main Klasse oder in irgendeiner andern Klasse die ich da noch so brauche
aufrufe passiert garnichts.. Kommt auch kein Fehler.. es wird einfach nur nix angezeigt. Wenn ich aber z.B. im Constructor von SBoard
aufrufe wird die Zahl so wie sie sollte angezeigt.. Also ab SMainFrame geht das irgendwie nicht mehr.. nur warum?
Ich verzweifle!!
SField Klasse
STile Klasse
SBoard Klasse
SMainFrame Klasse
die Main Klasse
ich versuche mich grade an einem Sudoku Spiel.. Das Aussehen hab ich schon alles so hinbekommen wie es in etwa sein sollte.. nun hab ich aber ein kleines Problem.. (ich weiß ist viel Code aber ich wüsste nicht wo ich noch was kürzen kann). Also ich versuche mal kurz zu erklären was ich da mache.. Ich habe ne SField Klasse die ein Feld das eine Zahl des Spiels beinhaltet darstellt.. dann ne STile Klasse die ein 3x3 Feld aus SFields darstellt und zuguterletzt ne SBoard Klasse die 3x3 STiles darstellt. SMainFrame ist einfach nur der Frame in dem das Board dann dargestellt wird.
Wenn ich jetzt aber in der Main Klasse oder in irgendeiner andern Klasse die ich da noch so brauche
Code:
SBoard.getInstance.getTile(2).getField(2).setNumber(2);
aufrufe passiert garnichts.. Kommt auch kein Fehler.. es wird einfach nur nix angezeigt. Wenn ich aber z.B. im Constructor von SBoard
Code:
this.getTile(2).getField(2).setNumber(2);
aufrufe wird die Zahl so wie sie sollte angezeigt.. Also ab SMainFrame geht das irgendwie nicht mehr.. nur warum?
Ich verzweifle!!
SField Klasse
Code:
public class SField extends JTextField {
/**
* The Tile to witch the field belongs
*/
private STile m_tile = null;
public SField(STile tile) {
//set the size of the SField's
this.setPreferredSize(new Dimension(50, 50));
this.setMinimumSize(new Dimension(50, 50));
this.setMaximumSize(new Dimension(500, 500));
//some font settings
this.setHorizontalAlignment(0);
this.setFont(new Font("My Font", Font.BOLD, 50));
this.m_tile = tile;
}
public void setNumber(int number) {
this.setText(Integer.toString(number));
}
}
STile Klasse
Code:
public class STile extends JPanel {
/**
* Stores the SFields of the Tile
*/
private SField m_fields[] = {
new SField(this),
new SField(this),
new SField(this),
new SField(this),
new SField(this),
new SField(this),
new SField(this),
new SField(this),
new SField(this)
};
public STile() {
//set the LayoutManager
this.setLayout(new GridLayout(3, 3));
//create Borders
this.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
//add the SFields to the Tile
this.add(m_fields[0]);
this.add(m_fields[1]);
this.add(m_fields[2]);
this.add(m_fields[3]);
this.add(m_fields[4]);
this.add(m_fields[5]);
this.add(m_fields[6]);
this.add(m_fields[7]);
this.add(m_fields[8]);
}
public SField getField(int number) {
return m_fields[number];
}
}
SBoard Klasse
Code:
public class SBoard extends JPanel{
private static SBoard m_instance = null;
/**
* Stores the STiles that belong t the Board
*/
private STile m_tiles[] = {
new STile(),
new STile(),
new STile(),
new STile(),
new STile(),
new STile(),
new STile(),
new STile(),
new STile()
};
public STile getTile(int number) {
return m_tiles[number];
}
public static SBoard getInstance() {
if(m_instance == null) {
return new SBoard();
}else {
return m_instance;
}
}
}
SMainFrame Klasse
Code:
public class SMainFrame extends JFrame {
/**
* Stores the instance of the singleton class SMainFrame
*/
private static SMainFrame m_instance = null;
/**
* Stores an instance of SBoard
*/
private SBoard m_board = SBoard.getInstance();
private SMainFrame() {
//set window title
this.setTitle("Sudoku");
//close the window after clicking on "x"
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//set the SMenuBar for the SMainFrame
this.setJMenuBar(new SMenuBar());
//set the contentPane for the SMainFrame
this.setContentPane(m_board);
//set the Size for the SMainFrame
this.setSize(new Dimension(500, 520));
this.setMinimumSize(new Dimension(500, 520));
this.setPreferredSize(new Dimension(500, 520));
this.setMaximumSize(new Dimension(5000, 5200));
}
public static SMainFrame getInstance() {
if(m_instance == null) {
return new SMainFrame();
}else {
return m_instance;
}
}
}
die Main Klasse
Code:
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException e) {
System.out.print("ClassNotFound");
} catch (InstantiationException e) {
System.out.print("Instantiation");
} catch (IllegalAccessException e) {
System.out.print("IllegalAccess");
} catch (UnsupportedLookAndFeelException e) {
System.out.print("UnsupportedLookAndFeel");
}
SMainFrame m_frame = SMainFrame.getInstance();
m_frame.setVisible(true);