![]() |
#2
林月儿2015-12-16 21:24
|
点击开始按钮后激活pb[i]点击

JButton start = new JButton("开始");// 创建开始按钮
p2.add(start);// 向p2添加开始按钮
start.setPreferredSize(new java.awt.Dimension(100, 110));// 开始按钮设置为宽100,高110
start.setFont(new Font("宋体", Font.LAYOUT_NO_LIMIT_CONTEXT, 33));// “开始”字体设置为宋体、无布局限制、33号
JButton restart = new JButton("重置");// 创建重置按钮
p2.add(restart);// 向p2添加重置按钮
restart.setPreferredSize(new java.awt.Dimension(100, 110));// 重置按钮设置为宽100,高110
restart.setFont(new Font("宋体", Font.LAYOUT_NO_LIMIT_CONTEXT, 33));// “重置”字体设置为宋体、无布局限制、33号
// 图片按钮 事件
for (int i = 0; i < 25; i++) { // 添加25个按钮到p1
// 按钮属性
p1.add(pb[i] = new JButton((new ImageIcon("./src/images/cm.jpg")))); // 新建按钮图片
pb[i].setActionCommand(i + "");// 设置按钮名称为i,显示空
pb[i].addActionListener(this); // 添加 监听者到按钮pb[i]
pb[i].setEnabled(false);// 初始为不可点击
}
start.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent s) {
Object[] options = { "确定", "取消" };
int response = JOptionPane.showOptionDialog(null,
"点击一个图片时,本身及其上下左右的图片会变成另一张图片,当图片全部变成另一张时胜利", "规则",
JOptionPane.YES_OPTION, JOptionPane.PLAIN_MESSAGE, null,
options, options[0]);
if (response==0){
}
}
});
p2.add(start);// 向p2添加开始按钮
start.setPreferredSize(new java.awt.Dimension(100, 110));// 开始按钮设置为宽100,高110
start.setFont(new Font("宋体", Font.LAYOUT_NO_LIMIT_CONTEXT, 33));// “开始”字体设置为宋体、无布局限制、33号
JButton restart = new JButton("重置");// 创建重置按钮
p2.add(restart);// 向p2添加重置按钮
restart.setPreferredSize(new java.awt.Dimension(100, 110));// 重置按钮设置为宽100,高110
restart.setFont(new Font("宋体", Font.LAYOUT_NO_LIMIT_CONTEXT, 33));// “重置”字体设置为宋体、无布局限制、33号
// 图片按钮 事件
for (int i = 0; i < 25; i++) { // 添加25个按钮到p1
// 按钮属性
p1.add(pb[i] = new JButton((new ImageIcon("./src/images/cm.jpg")))); // 新建按钮图片
pb[i].setActionCommand(i + "");// 设置按钮名称为i,显示空
pb[i].addActionListener(this); // 添加 监听者到按钮pb[i]
pb[i].setEnabled(false);// 初始为不可点击
}
start.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent s) {
Object[] options = { "确定", "取消" };
int response = JOptionPane.showOptionDialog(null,
"点击一个图片时,本身及其上下左右的图片会变成另一张图片,当图片全部变成另一张时胜利", "规则",
JOptionPane.YES_OPTION, JOptionPane.PLAIN_MESSAGE, null,
options, options[0]);
if (response==0){
}
}
});