Click here to Skip to main content
15,884,693 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
bill_number(using jtextfield) must auto increment by 1 after clicking submit button. I need sequtenial values in format like B3001,B3002, and so on....kindly plz help me

What I have tried:

public static class SequentialNumber
{
       private static int currentNumber=3000;
       public static String GetNextNumber()
       {
            currentNumber++;
            return "B"+currentNumber;
       }
}
public Printbill() {


    contentPane1 = new JPanel();
    contentPane1.setBackground(Color.WHITE);
    contentPane1.setBorder(new EmptyBorder(5, 5, 5, 5));

    contentPane1.setLayout(null);



    dcfield = new JTextField();

    dcfield.setBounds(553, 109, 86, 20);
    contentPane1.add(dcfield);
    dcfield.setColumns(10);
    String ContractNo=SequentialNumber.GetNextNumber();
    dcfield.setText(ContractNo);
    JButton btnAdd = new JButton("ADD");
    btnAdd.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
          Printbill p=new Printbill();
          dispose();
            p.setVisible(true);
            SequentialNumber s=new SequentialNumber();
            String stt=s.GetNextNumber();
           dcfield.setText(stt);
        }
    });

     }
            }
Posted
Updated 15-Nov-17 0:00am
v2
Comments
Richard MacCutchan 15-Nov-17 5:20am    
Split the field into alpha prefix and number. Add 1 to the number. Recombine the two fields.

1 solution

Your code is almost correct. Try
Java
class SequentialNumber
{
  private static int currentNumber = 3000;
  public static String GetNextNumber()
  {
    currentNumber++;
    return "B"+currentNumber;
  }
}

public class program
{
  public static void main(String args[])
  {
    for (int n=0; n<20; ++n)
    {
      String sn =  SequentialNumber.GetNextNumber();
      System.out.printf("sequential_number[%d] = %s\n", n, sn);
    }
  }
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900