title: How to plus one in text file? (JAVA)
body: <p>I am a Java newbie, I am trying to test generate unique code by using "for" loop.Start from number 1000 and it will keep adding one, the texts will be store inside a text file called database.txt. For example if the first user use the program it will store "1001", then second user "1002", third will be "1003"... The problem is I'm having a error in the for loop statement "illegal start of type". Please help me, thank you!</p>
  
  <pre><code>package car.park.auto.pay.system;
  import java.io.*;
  import java.lang.*;
  import java.util.*;
  import javax.swing.JOptionPane;
  import javax.swing.JTextField;
  
  public class SelectTimeAndDate extends javax.swing.JFrame {
  
  public SelectTimeAndDate() {
      initComponents();
  
  }
  
  @SuppressWarnings("unchecked")
  // &lt;editor-fold defaultstate="collapsed" desc="Generated Code"&gt;                          
  private void initComponents() {
  
      jPanel1 = new javax.swing.JPanel();
      jLabel1 = new javax.swing.JLabel();
      jLabel2 = new javax.swing.JLabel();
      jLabel3 = new javax.swing.JLabel();
      confirmBut = new javax.swing.JButton();
      cancelBut1 = new javax.swing.JButton();
      hourField = new javax.swing.JTextField();
      dateField = new javax.swing.JTextField();
      minuteField = new javax.swing.JTextField();
      hourLab = new javax.swing.JLabel();
      dateLab = new javax.swing.JLabel();
      minuteLab = new javax.swing.JLabel();
      monthLab = new javax.swing.JLabel();
      monthField = new javax.swing.JTextField();
      secondLab = new javax.swing.JLabel();
      secondField = new javax.swing.JTextField();
      yearField = new javax.swing.JTextField();
      yearLab = new javax.swing.JLabel();
  
      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
      setTitle("Roy's Car Parking Auto Pay Station System");
  
      jLabel1.setText("Please input time and date that you are entering:");
  
      jLabel2.setText("Input time (hh:mm:ss):");
      jLabel2.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
  
      jLabel3.setText("Input date (dd/mm/yy):");
  
      confirmBut.setText("Confirm");
      confirmBut.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              confirmButActionPerformed(evt);
          }
      });
  
      cancelBut1.setText("Cancel");
      cancelBut1.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              cancelBut1ActionPerformed(evt);
          }
      });
  
      hourField.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              hourFieldActionPerformed(evt);
          }
      });
  
      hourLab.setText("Hour:");
  
      dateLab.setText("Date:");
  
      minuteLab.setText("Minute:");
  
      monthLab.setText("Month:");
  
      secondLab.setText("Second:");
  
      yearLab.setText("Year:");
  
      javax.swing.GroupLayout jPanel1Layout = new     javax.swing.GroupLayout(jPanel1);
      jPanel1.setLayout(jPanel1Layout);
      jPanel1Layout.setHorizontalGroup(
          jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(jPanel1Layout.createSequentialGroup()
              .addGap(87, 87, 87)
              .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(jPanel1Layout.createSequentialGroup()
                      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                          .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                          .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE))
                      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                          .addGroup(jPanel1Layout.createSequentialGroup()
                              .addComponent(dateLab)
                              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                              .addComponent(dateField))
                          .addGroup(jPanel1Layout.createSequentialGroup()
                              .addComponent(hourLab)
                              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                              .addComponent(hourField, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))))
                  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                      .addComponent(confirmBut, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addGap(22, 22, 22)))
              .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(jPanel1Layout.createSequentialGroup()
                      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                          .addGroup(jPanel1Layout.createSequentialGroup()
                              .addComponent(minuteLab)
                              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                              .addComponent(minuteField, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                          .addGroup(jPanel1Layout.createSequentialGroup()
                              .addComponent(monthLab)
                              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                              .addComponent(monthField)))
                      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                          .addGroup(jPanel1Layout.createSequentialGroup()
                              .addComponent(secondLab)
                              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                              .addComponent(secondField, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                          .addGroup(jPanel1Layout.createSequentialGroup()
                              .addGap(14, 14, 14)
                              .addComponent(yearLab)
                              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                              .addComponent(yearField, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))))
                  .addGroup(jPanel1Layout.createSequentialGroup()
                      .addGap(13, 13, 13)
                      .addComponent(cancelBut1, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)))
              .addContainerGap(56, Short.MAX_VALUE))
          .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
              .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
              .addComponent(jLabel1)
              .addGap(121, 121, 121))
      );
      jPanel1Layout.setVerticalGroup(
          jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
              .addContainerGap(35, Short.MAX_VALUE)
              .addComponent(jLabel1)
              .addGap(18, 18, 18)
              .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(jPanel1Layout.createSequentialGroup()
                      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                          .addComponent(jLabel2)
                          .addComponent(hourField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                          .addComponent(minuteField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                          .addComponent(hourLab)
                          .addComponent(minuteLab))
                      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                          .addComponent(jLabel3)
                          .addComponent(dateField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                          .addComponent(dateLab)
                          .addComponent(monthField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                          .addComponent(monthLab)))
                  .addGroup(jPanel1Layout.createSequentialGroup()
                      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                          .addComponent(secondField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                          .addComponent(secondLab))
                      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                          .addComponent(yearField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                          .addComponent(yearLab))))
              .addGap(18, 18, 18)
              .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addComponent(confirmBut, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addComponent(cancelBut1, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
              .addGap(28, 28, 28))
      );
  
      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
          layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
              .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
              .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addGap(40, 40, 40))
      );
      layout.setVerticalGroup(
          layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
              .addGap(35, 35, 35)
              .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addContainerGap(69, Short.MAX_VALUE))
      );
  
      pack();
  }// &lt;/editor-fold&gt;                        
  
  private void hourFieldActionPerformed(java.awt.event.ActionEvent evt) {                                          
  
  }                                         
  
  private void cancelBut1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
      new Menu().setVisible(true);
      this.dispose();
  }                                          
  
  private void confirmButActionPerformed(java.awt.event.ActionEvent evt) {                                           
      String hour=hourField.getText();
      String minute=minuteField.getText();
      String second=secondField.getText();
      String date=dateField.getText();
      String month=monthField.getText();
      String year=yearField.getText();
      int i=1000;
      i=i+1;
      for(i&lt;9000;i+){}
  
  try{
  FileWriter fw= new FileWriter("database.txt",true);
  
  PrintWriter pw= new PrintWriter(fw);
  pw.format("%s  %s  %s  %s  %s  %s  %s\r\n",hour,minute,second,date,month,year,i);
  
  pw.close();
  
  }
  catch(IOException e){
      System.out.println("Error");
  }
  
  
          if(hour.isEmpty()||minute.isEmpty()||second.isEmpty()||date.isEmpty()||month.isEmpty()||year.isEmpty()){
          JOptionPane.showMessageDialog(this,String.format("Please input all the details!", JOptionPane.ERROR_MESSAGE));
      }else{
          NewCode.getObj().setVisible(true);
          this.dispose();
      }
  
      }                                          
  
  
  
  
  // Variables declaration - do not modify                     
  private javax.swing.JButton cancelBut1;
  private javax.swing.JButton confirmBut;
  private javax.swing.JTextField dateField;
  private javax.swing.JLabel dateLab;
  private javax.swing.JTextField hourField;
  private javax.swing.JLabel hourLab;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JPanel jPanel1;
  private javax.swing.JTextField minuteField;
  private javax.swing.JLabel minuteLab;
  private javax.swing.JTextField monthField;
  private javax.swing.JLabel monthLab;
  private javax.swing.JTextField secondField;
  private javax.swing.JLabel secondLab;
  private javax.swing.JTextField yearField;
  private javax.swing.JLabel yearLab;
  // End of variables declaration                   
  }
  </code></pre>