Simple Java swing program to count number

Java swing program to count number

In this post we sill see simple Java swing program to count number. The program uses a JLabel to hold lable, a JTextField component to hold the number count, JButton component to create plus, minus and reset buttons. This program will be an useful example for someone starting our with Java swing.

Java swing counter example

CounterExample.java

Below is the GUI create by the above program.

java swing count example

When you click the ‘+’ button, the count in the text box will get incremented by 1 and by clicking ‘-‘ button the count will be decremented by 1. Clicking the Reset button will reset the count to zero.

Hope you liked this example Java swing program to count number. If you have any doubts, ask me in comments.

The following two tabs change content below.
Working as a Java developer since 2010. Passionate about programming in Java. I am a part time blogger.
One comment
  1. The blog has a well written program and the display of output is on the mark and the indentation is perfect. Swing provides the ability to create a GUI. It’s components are used with the JFC(Java Foundation Class).

Add Comment

Required fields are marked *. Your email address will not be published.