
Hello everyone! Here is my current code:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Final extends Applet implements ActionListener
{
public int testone = 0;
public void init()
{
Button one = new Button("Increase");
one.addActionListener(this);
add(one);
}
public void paint(Graphics g)
{
g.drawString("Total: " + gettestone(),20,50);
}
public void actionPerformed(ActionEvent e)
{
increasetestone();
repaint();
}
public synchronized int gettestone()
{
return testone;
}
public synchronized void increasetestone() {
testone++;
}
}
When you run this current code, it will display a button in a frame, that when clicked on will increase a total. Basically it will count the total number of times you click the button.
What I need is for their to be a second button that when clicked will decrease that total amount. So basically there would be one button that when clicked, would increase that value, and another that when clicked, will decrease the value.
Thanks so much for your help!

Here is an applet program that will increment and decrement the integer value. There are two buttons in an applet for increment and decrement respectively. On clicking these button, value will get incremented and decremented.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Final extends Applet {
public int testone = 0;
public void init() {
Button one = new Button("Increase");
Button two = new Button("Decrease");
one.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
increasetestone();
repaint();
}
});
two.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
decreasetestone();
repaint();
}
});
add(one);
add(two);
}
public void paint(Graphics g)
{
g.drawString("Total: " + gettestone(),20,50);
}
public synchronized int gettestone()
{
return testone;
}
public synchronized void increasetestone() {
testone++;
}
public synchronized void decreasetestone() {
testone--;
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.