JAVA新手 初级的问题 求助
来源:百度知道 编辑:UC知道 时间:2024/07/11 08:45:20
我写的程序 谁知道错误在哪里 急啊
就是连BUTTON都出不来
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MiniMineSweeper extends JFrame
{
static int a = (int) Math.floor(Math.random()*9);
JButton[] jbt= new JButton[9];
public void Welcome()
{
JOptionPane.showMessageDialog(null,"Welcome to Mini-MineSweeper!\nThe object of the game is to click on all\n the squares EXCEPT the one with the bomb.\n(There is only one bomb).To choose a square\n to display please simply click on the square.","Message",JOptionPane.INFORMATION_MESSAGE);
}
public MiniMineSweeper()
{
Container container =getContentPane();
container.setLayout(new GridLayout(3,3,0,0));
for (int i=1;i<=9;i++)
{
jbt[i]= new JButton();
jbt[i].setBackground(Color.gray);
container.add(jbt[i]);
container.valid
就是连BUTTON都出不来
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MiniMineSweeper extends JFrame
{
static int a = (int) Math.floor(Math.random()*9);
JButton[] jbt= new JButton[9];
public void Welcome()
{
JOptionPane.showMessageDialog(null,"Welcome to Mini-MineSweeper!\nThe object of the game is to click on all\n the squares EXCEPT the one with the bomb.\n(There is only one bomb).To choose a square\n to display please simply click on the square.","Message",JOptionPane.INFORMATION_MESSAGE);
}
public MiniMineSweeper()
{
Container container =getContentPane();
container.setLayout(new GridLayout(3,3,0,0));
for (int i=1;i<=9;i++)
{
jbt[i]= new JButton();
jbt[i].setBackground(Color.gray);
container.add(jbt[i]);
container.valid
for (int i=1;i<=9;i++)
{
jbt[i]= new JButton();
这里数组下标越界,因为你最上面定义的JButton[] jbt= new JButton[9]; 数组的下标是0开始,所以最有一个应该是8,所以应该改成小于9
for (int i=1;i<9;i++)
{
jbt[i]= new JButton();
越界