Hm... einen Fehler hab ich schon selber gefunden. Ich hatte noch eine paint-Methode im Applet, die den Hintergrund zeichnet. Jetzt sieht man die Komponenten alle, allerdings sehe ich den Hintergrund nicht. Wenn ich jedoch an dem Fenster, in dem das Applet läuft, "ziehe", erscheint der Hintergrund. Ich hab schon versucht ein repaint() einzufügen aber das hilft auch nicht.
[HIGHLIGHT="Java"]
public class SudokuApplet extends JApplet implements DocumentListener {
private Sudoku sudoku = new Sudoku();
private Feld felder[][] = new Feld[9][9];
private Image background;
private JPanel grid;
private JComboBox difficultyChooser;
private JPanel mainPanel;
private JPanel optionsPanel;
private JPanel bottomPanel;
private JLabel createLabel;
private JPanel difficultyPanel;
private JLabel difficultyLabel;
private JButton createButton;
public SudokuApplet() {
}
@Override
public void init() {
initComponents();
}
private void initComponents() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException ex) {
Logger.getLogger(SudokuApplet.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(SudokuApplet.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(SudokuApplet.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnsupportedLookAndFeelException ex) {
Logger.getLogger(SudokuApplet.class.getName()).log(Level.SEVERE, null, ex);
}
SwingUtilities.updateComponentTreeUI(this);
grid = new JPanel();
grid.setLayout(new GridLayout(9, 9));
grid.setMaximumSize(new Dimension(400, 400));
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
felder[j] = new Feld(i, j);
felder[j].getDocument().addDocumentListener(this);
grid.add(felder[j]);
}
}
background = getImage(getCodeBase(), "background.png");
mainPanel = new Background(background);
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
optionsPanel = new JPanel();
optionsPanel.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, new Color(204, 204, 204)));
optionsPanel.setLayout(new BorderLayout());
optionsPanel.setMaximumSize(new Dimension(150, 75));
bottomPanel = new JPanel();
bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.X_AXIS));
createLabel = new JLabel("Sudoku erzeugen:");
createLabel.setFont(new Font("Tahoma", 1, 11));
difficultyPanel = new JPanel();
difficultyPanel.setMaximumSize(new Dimension(200, 50));
difficultyPanel.setLayout(new BoxLayout(difficultyPanel, BoxLayout.X_AXIS));
difficultyLabel = new JLabel("Schwierigkeit:");
difficultyChooser = new JComboBox();
difficultyChooser.setModel(new DefaultComboBoxModel(new String[]{"Leicht", "Mittel", "Schwer", "Test"}));
difficultyPanel.add(difficultyLabel);
difficultyPanel.add(difficultyChooser);
createButton = new JButton();
createButton.setText("Erzeuge");
createButton.setPreferredSize(new Dimension(75, 23));
createButton.addActionListener(new ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
create(evt);
}
});
Box box = Box.createVerticalBox();
box.add(createLabel);
box.add(Box.createVerticalStrut(5));
optionsPanel.add(box, BorderLayout.NORTH);
box = Box.createHorizontalBox();
box.add(Box.createHorizontalStrut(3));
box.add(difficultyLabel);
box.add(Box.createHorizontalGlue());
box.add(difficultyChooser);
optionsPanel.add(box, BorderLayout.CENTER);
box = Box.createVerticalBox();
box.add(Box.createVerticalStrut(5));
box.add(createButton);
createButton.setAlignmentX(Component.RIGHT_ALIGNMENT);
optionsPanel.add(box, BorderLayout.SOUTH);
bottomPanel.add(optionsPanel);
bottomPanel.add(Box.createHorizontalGlue());
mainPanel.add(grid);
mainPanel.add(bottomPanel);
add(mainPanel);
}
private void getSudoku(int difficulty) {
//...
}
private void create(ActionEvent evt) {
//...
}
private int[][] getSudoku() {
//...
}
private boolean allSet() {
//...
}
private boolean checkAll() {
//...
}
public void insertUpdate(DocumentEvent e) {
//...
}
public void removeUpdate(DocumentEvent e) {
//...
}
public void changedUpdate(DocumentEvent e) {
//...
}
}
[/HIGHLIGHT]
In der getSudoku()-Funktion funktioniert das Sysntax-Highlighting nicht richtig...