Hallo,
Ich wollte auf einem Panel Buttons anordnen und das Panel dann zum Frame hinzufügen, aber die Buttons verteilen sich auf dem gesamten Frame und nicht nur auf dem 600*600 Panel.
Könnte mir wer einen Tipp geben woran das liegt?
Schon mal Danke im Vorraus.
Ich wollte auf einem Panel Buttons anordnen und das Panel dann zum Frame hinzufügen, aber die Buttons verteilen sich auf dem gesamten Frame und nicht nur auf dem 600*600 Panel.
Könnte mir wer einen Tipp geben woran das liegt?
Schon mal Danke im Vorraus.
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class frame extends JFrame {
JPanel panel;
JButton button[][] = new JButton[9][9];
public frame() {
setSize(800, 800);
setLocation(0, 0);
setTitle("Frame");
add(new panel());
setVisible(true);
}
class panelextends JPanel implements ActionListener {
panel() {
setLocation(0, 0);
setSize(600, 600);
setLayout(new GridLayout(9, 9));
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
button[i][j] = new JButton();
button[i][j].setName("" + i + ":" + "" + j); // Koordinaten vom Button
button[i][j].addActionListener(this);
button[i][j].setText("");
add(button[i][j]);
}
}
}
}
public static void main(String[] args) {
new SudokuGUI();
}