Hi java programmers!
I got a run time problem with my code in below
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Aline extends JFrame {
JFrame window = new JFrame("");
JButton[][] butonlar;
public Aline() {
window.setSize(600, 600);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLO SE);
window.setLayout(new GridLayout(3, 3));
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
// Determine the new location of the window
int w = window.getSize().width;
int h = window.getSize().height;
int x = (dim.width - w) / 2;
int y = (dim.height - h) / 2;
window.setLocation(x, y);
butonlar= new JButton[5][5];
// for (int i = 1; i <= 5; i++) {
// for (int j = 1; j <= 5; j++) {
// butonlar[i][j]=new JButton();
// }
//
// }
// for (int i = 1; i <= 5; i++) {
// for (int j = 1; j <= 5; j++) {
// window.add(butonlar[i][j]);
// }
//
// }
// window.add(butonlar[5][5]);
window.setVisible(true);
}
public static void main(String args[]) {
new Aline();
}
}
as you can see, I tried to write different ways but i couldnt run it. And i ignored these lines and tried different way but again it did not work
Error message is java.lang.ArrayIndexOutOfBoundsException: 5
just i want to create a matrix with jbutton or panel and i ll use it to define my path on this matrix. But i m still getting error in first step of my program and i couldnt continue to complete