那位好心人帮忙看个java程序阿 感激不尽~~~

来源:百度知道 编辑:UC知道 时间:2024/06/02 06:26:10
想让它在运行的时候 如果点中了“Boom” 此方框变成黑色 谢谢~~~

/*
* Created on 2008-6-2
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package ly.java.game;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import ly.java.ExtendButton;

public class MiniMineSweeper extends JFrame implements ActionListener{
private Container myContainer;
private GridLayout myLayout;
ExtendButton[] myButton = new ExtendButton[9];

private MiniMineSweeper ()
{
String s = "Welcome to Mini-MineSweeper!";
this.setTitle("Boom!");
this.setSize( 300,200 );
this.InitButton();
JOptionPane.showMessageDialog( null, s, "Message", JOptionPane.INFORMATION_MESSAGE );
}

private void InitButton()
{
myContainer = getContentPane();
myLayout = n

改动了一个类,测试可用。另外你要把你问题补充里面的类名改为ExtendButton。

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import ly.java.ExtendButton;

public class MiniMineSweeper extends JFrame implements ActionListener {
private Container myContainer;
private GridLayout myLayout;
ExtendButton[] myButton = new ExtendButton[9];
int num;

private MiniMineSweeper() {
String s = "Welcome to Mini-MineSweeper!";
num = 0;
this.setTitle("Boom!");
this.setSize(300, 200);
this.InitButton();
JOptionPane.showMessageDialog(null, s, "Message",
JOptionPane.INFORMATION_MESSAGE);
}

private void InitButton() {
myContainer = getContentPane();
myLayout = new GridLayout(3, 3, 1, 1);
myContainer.setLayout(myLayout);
for (int i = 0; i < 9; i++) {
myButton[i] = new ExtendButton();
myButton[i].setBackgro