黑马程序员技术交流社区
标题:
代码找错
[打印本页]
作者:
樊占江
时间:
2012-8-17 22:43
标题:
代码找错
import java.awt.BorderLayout;import java.awt.Color;import java.awt.Dimension;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;//=============================WindowsFrame.java========================public class WindowsFrame extends JFrame implements ActionListener{ //构造函数 public WindowsFrame(String str) { this.setTitle(str); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } //窗口面板 public JPanel win_panel = new JPanel(); win_panel.setLayout(new GridLayout(5,5)); //控制面板 public JPanel control_panel = new JPanel(); //主面板 public JPanel main_panel = new JPanel(); private JLabel mess_label = new JLabel(); private JButton restart_button = new JButton(); private JButton[] win_button = new JButton[25]; //窗口默认颜色 Color default_color; for(int i=0;i<25;i++ ) { win_button[i].setActionCommand(String.valueOf(i)); win_button[i].addActionListener(this); win_panel.add(win_button[i]); } default_color= win_button[0].getBackground(); win_panel.setPreferredSize(new Dimension(300,300)); control_panel.add(mess_label); restart_button.addActionListener(new Reset()); control_panel.add)(restart_button); main_panel.setLayout(new BorderLayout()); main_panel.add(win_panel,BorderLayout.CENTER); main_panel.add(control_panel,BorderLayout.SOUTH); public void actionPerformed(ActionEvent e) { int x= Integer.parseInt(e.getActionCommand()); select(x); isOK(); } //选中窗口后执行的动作 private void select(int x) { if (x == 0) { changeColor(win_button[x]); changeColor(win_button[x + 1]); changeColor(win_button[x + 5]); } else if (x > 0 && x < 4) { changeColor(win_button[x]); changeColor(win_button[x - 1]); changeColor(win_button[x + 1]); changeColor(win_button[x + 5]); } else if (x == 4) { changeColor(win_button[x]); changeColor(win_button[x - 1]); changeColor(win_button[x + 5]); } else if (x == 20) { changeColor(win_button[x]); changeColor(win_button[x - 5]); changeColor(win_button[x + 1]); } else if (x == 24) { changeColor(win_button[x]); changeColor(win_button[x - 5]); changeColor(win_button[x - 1]); } else if (x > 20 && x < 24) { changeColor(win_button[x]); changeColor(win_button[x - 5]); ==================接下页========问题补充:
private void isOK() { int num=0; for(int i=0;i<25;i++) { if(win_button[i].getBackground()==Color.GREEN) num++; } if(num==25) JOptionPane.showMessageDialog(null,"Congratulations!!!"); } //重新开始按钮的监听器 class Reset implements ActionListener { public void actionPerformed(ActionEvent e) { for(int i=0;i<25;i++) { win_panel.win_button[i].setBackground(default_color); } } }}//==================OpenWindowViewer.java============public class OpenWindowViewer{ public static void main(Sring[] args) { new WindowsFrame(“开窗游戏”); }}我编写的一个开窗游戏的代码,编译是有错。但我不知道错在哪里!请求各位帮助!!!
作者:
金龙
时间:
2012-8-18 01:24
我表示,这个代码,。。没法看……
作者:
牛杨
时间:
2012-8-18 02:10
本帖最后由 牛杨 于 2012-8-18 02:11 编辑
金龙 发表于 2012-8-18 01:24
我表示,这个代码,。。没法看……
够彪悍,够草根 。 I 服了 you 了 发错了 我说的是楼主
作者:
高薇
时间:
2012-8-18 08:44
好无奈哦
作者:
艾衍年
时间:
2012-8-18 08:59
这是一道要考验眼力的题。。。。
作者:
官文昌
时间:
2012-8-18 09:20
这样的代码看到就够了~~谁还有心情帮你找错啊~
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2