I'm trying to put a counterdown timer in my Minesweeper program, however, on line 23 in my MinesweeperGrid timer.start(); is giving me an identifier expected error? I've looked in the APIs and nothing is required in start.();? help?
heres my code:
1 import java.awt.*; 2 import javax.swing.*; 3 import java.awt.event.*; 4 5 public class MinesweeperGrid extends JPanel 6 { 7 8 int currentTime = 0; 9 JFrame frame; 10 GridPanel[] grid; 11 String currentDiff = "easy"; 12 JButton reset = new JButton ("Reset"); 13 JLabel time = new JLabel ("Time"); 14 JLabel flag = new JLabel ("Flags"); 15 16 javax.swing.Timer timer = new javax.swing.Timer(1000, new ActionListener() 17 { 18 public void actionPerformed (ActionEvent event) 19 { 20 time.setLabel(Integer.toString(currentTime)); 21 } 22 }); 23 timer.start(); 24 25 public MinesweeperGrid(JFrame newFrame) 26 { 27 frame = newFrame; 28 grid = new GridPanel[81]; 29 frame.getContentPane().setLayout(new GridLayout(10,9,0,0)); 30 31 frame.getContentPane().add(time); 32 frame.getContentPane().add(new JLabel()); 33 frame.getContentPane().add(new JLabel()); 34 frame.getContentPane().add(new JLabel()); 35 frame.getContentPane().add(reset); 36 frame.getContentPane().add(new JLabel()); 37 frame.getContentPane().add(new JLabel()); 38 frame.getContentPane().add(new JLabel()); 39 frame.getContentPane().add(flag); 40 41 for( int i = 0; i < 81; i++) 42 { 43 grid[i] = new GridPanel(); 44 frame.getContentPane().add(grid[i]); 45 } 46 47 } 48 49 public void changeDiff(String newDiff) 50 { 51 if (newDiff.equals("easy")) 52 { 53 GridPanel[] newGrid = new GridPanel[81]; 54 frame.getContentPane().removeAll(); 55 56 frame.getContentPane().setLayout(new GridLayout(10,9,0,0)); 57 58 frame.getContentPane().add(time); 59 frame.getContentPane().add(new JLabel()); 60 frame.getContentPane().add(new JLabel()); 61 frame.getContentPane().add(new JLabel()); 62 frame.getContentPane().add(reset); 63 frame.getContentPane().add(new JLabel()); 64 frame.getContentPane().add(new JLabel()); 65 frame.getContentPane().add(new JLabel()); 66 frame.getContentPane().add(flag); 67 68 for( int i = 0; i < 81; i+69+) 69 { 70 newGrid[i] = new GridPanel(); 71 frame.getContentPane().add(newGrid[i]); 72 } 73 frame.getContentPane().validate(); 74 super.repaint(); 75 currentDiff = "easy"; 76 } 77 78 if (newDiff.equals("medium")) 79 { 80 81 GridPanel[] newGrid = new GridPanel[256]; 82 frame.getContentPane().removeAll(); 83 84 frame.getContentPane().setLayout(new GridLayout(17,16,0,0)); 85 86 frame.getContentPane().add(time); 87 frame.getContentPane().add(new JLabel()); 88 frame.getContentPane().add(new JLabel()); 89 frame.getContentPane().add(new JLabel()); 90 frame.getContentPane().add(new JLabel()); 91 frame.getContentPane().add(new JLabel()); 92 frame.getContentPane().add(new JLabel()); 93 frame.getContentPane().add(new JLabel()); 94 frame.getContentPane().add(reset); 95 frame.getContentPane().add(new JLabel()); 96 frame.getContentPane().add(new JLabel()); 97 frame.getContentPane().add(new JLabel()); 98 frame.getContentPane().add(new JLabel()); 99 frame.getContentPane().add(new JLabel()); 100 frame.getContentPane().add(new JLabel()); 101 frame.getContentPane().add(flag); 102 103 for( int i = 0; i < 256; i++) 104 { 105 newGrid[i] = new GridPanel(); 106 frame.getContentPane().add(newGrid[i]); 107 } 108 frame.getContentPane().validate(); 109 super.repaint(); 110 currentDiff = "medium"; 111 } 112 113 if (newDiff.equals("hard")) 114 { 115 116 GridPanel[] newGrid = new GridPanel[480]; 117 frame.getContentPane().removeAll(); 118 119 frame.getContentPane().setLayout(new GridLayout(25,20,0,0)); 120 121 frame.getContentPane().add(time); 122 frame.getContentPane().add(new JLabel()); 123 frame.getContentPane().add(new JLabel()); 124 frame.getContentPane().add(new JLabel()); 125 frame.getContentPane().add(new JLabel()); 126 frame.getContentPane().add(new JLabel()); 127 frame.getContentPane().add(new JLabel()); 128 frame.getContentPane().add(new JLabel()); 129 frame.getContentPane().add(new JLabel()); 130 frame.getContentPane().add(new JLabel()); 131 frame.getContentPane().add(reset); 132 frame.getContentPane().add(new JLabel()); 133 frame.getContentPane().add(new JLabel()); 134 frame.getContentPane().add(new JLabel()); 135 frame.getContentPane().add(new JLabel()); 136 frame.getContentPane().add(new JLabel()); 137 frame.getContentPane().add(new JLabel()); 138 frame.getContentPane().add(new JLabel()); 139 frame.getContentPane().add(new JLabel()); 140 frame.getContentPane().add(flag); 141 142 for( int i = 0; i < 480; i++) 143 { 144 newGrid[i] = new GridPanel(); 145 frame.getContentPane().add(newGrid[i]); 146 } 147 frame.getContentPane().validate(); 148 super.repaint(); 149 currentDiff = "hard"; 150 } 151 } 152 153 public class resetListener implements ActionListener 154 { 155 public void actionPerformed (ActionEvent event) 156 { 157 changeDiff(currentDiff); 158 } 159 } 160 public class timeListener implements ActionListener 161 { 162 public void actionPerformed (ActionEvent event) 163 { 164 currentTime++; 165 time.setText(Integer.toString(currentTime)); 166 repaint(); 167 System.out.println("hey, work!"); 168 } 169 } 170 }