I create 4 text box and 3 buttons.button1 is using increment option and button2 using decrement option button3 using reset option.when i click the button1 the value will be increase and the result is shown into the textbox same as button2 and button3.
import javax.swing.*;
import java.awt.event.*;
class SwingExample
{
public static void main(String[] args)
{
JFrame f=new JFrame();
final JTextField text1=new JTextField(20);
JTextField text2=new JTextField(20);
JTextField text3=new JTextField(20);
JTextField text4=new JTextField(20);
f.setLayout(null);
JButton b1=new JButton("Increment");
JButton b2=new JButton("Decrement");
JButton b3=new JButton("Reset");
text1.setBounds(10,10,150,20);
text2.setBounds(10,40,150,20);
text3.setBounds(10,70,150,20);
text4.setBounds(10,100,150,20);
b1.setBounds(10,130,100,20);
b2.setBounds(120,130,100,20);
b3.setBounds(240,130,100,20);
f.add(text1);
f.add(text2);
f.add(text3);
f.add(text4);
f.add(b1);
f.add(b2);
f.add(b3);
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
int num=Integer.parseInt(text1.getText());
num=num+1;
text1.setText(Integer.toString(num));
}
});
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
int num=Integer.parseInt(text1.getText());
num=num-1;
text1.setText(Integer.toString(num));
}
});
b3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
text1.setText(" ");
}
});
f.setVisible(true);
f.setSize(350,200);
}
}