Java Applet - Adding a Button to Decrease a Total
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!
View Answers
June 8, 2012 at 5:33 PM
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--;
}
}
Related Tutorials/Questions & Answers:
Advertisements
How to decrease image thumbnail size in java?How to
decrease image thumbnail size in
java? Hi,
I my web application I have to create the thumbnail size image from the image file uploaded by user. How to
decrease image thumbnail size in
java?
Thanks
java applet - Appletjava applet I want to close
applet window which is open by another
button of
applet program. plz tell me! Hi Friend,
Try...://www.roseindia.net/
java/example/
java/
applet/
Thanks
java applet problem - Appletjava applet problem i was doing a program using
java applet. I want... for add,multiply,divide,minus and a clear and exit
button to clear the textboxes and to exit from the
applet respectively.Now i want to display a message when
java applet - Appletjava applet wants to creat address bar on my
java applet. Hi
Applet don't provide a facility to create a address bar directly. You just create a text box. In this text box if you enter any http address
loading Java Applet - Appletloading
Java Applet Hi,
I use the archive tag to download my
applet into the Browser
It takes too long to load. Can I do it in several steps... control the loading within the
applet?
thanks
Java Applet Java Applet How to add Image in
Java Applet? what is getDocumentBase
java appletjava applet Creation of
Applet for Personal Details Form
When.... The
applet must include the following validations:
ď?® The FirstName, Address1... format, and should
be later than the current date.
Create an OK
button AppletApplet I have a
java applet that has a
button. On clicking the
button it should disappear and another
applet should appear. How to write this code???? Also in login
applet after successful login it should display admin
applet java - Appletjava how to connect database table with scrollbar in
java applet java - Appletjava how to connect database table with scrollbar in
java applet java - Appletjava what is
applet? Hi Friend,
Please visit the following link:
http://www.roseindia.net/
java/example/
java/
applet/
Thanks
java - Appletjava i have
button browse
button in my
applet form.when i click on browse
button i have to go to file storage box(what ever files stored in my... in the mail).i have display that file path in my
applet form.am learner please send me
java appletjava applet why
java applet programs doesn't contain main method
java appletjava applet why
java applet programs doesn't contain main method
Java appletJava applet What tags are mandatory when creating HTML to display an
applet Java appletJava applet How do I go from my
applet to another JSP or HTML page
java appletjava applet If i insert in database from
applet this work, but from applet.html don't
Java AppletJava Applet Hi,
What is
Java Applet and how it can be useful in development of
Java programs?
Can anyone tell me the url to learn
Java Applet?
Thanks
Hi,
See the tutorial at: Applications and Applets
Thanks
java - Appletjava how to communicate to my servlet through
applet.
... this information to the servlet in the normal way.
The
applet pretends... is concerned, the
applet is just another HTTP client.
For more infomation
Java program to generate the total countJava program to generate the
total count I need a
java program which would take a text file as an input and scans through it to generate the output.
For Ex. : If the text file contains the following information:
There is/are 3
java applet java applet I want code to implement
(1) user will enter how many nodes
(2)it should allow that no. of clicks and
circle should be displayed at that
position
java appletjava applet Web page that accepts a matrix as input and computes its transpose.
The web page should have two text boxes and a submit
button labbeled... of the web page, Submit
button should be clicked.
Once clicked, a number of text boxes
java appletjava applet Web page that accepts a matrix as input and computes its transpose.
The web page should have two text boxes and a submit
button labbeled... of the web page, Submit
button should be clicked.
Once clicked, a number of text boxes
java total lost data in hard drivejava total lost data in hard drive please help me, i need
java source code about
total lost data in hard drive. how to find the
total deleted data ih hard drive using
java programming... this my project...pls help me
java total lost data in hard drivejava total lost data in hard drive please help me, i need
java source code about
total lost data in hard drive. how to find the
total deleted data ih hard drive using
java programming... this my project...pls help me
java total lost data in hard drivejava total lost data in hard drive please help me, i need
java source code about
total lost data in hard drive. how to find the
total deleted data ih hard drive using
java programming... this my project...pls help me
JAVA TOTAL LOST DATA IN HARD DRIVEJAVA TOTAL LOST DATA IN HARD DRIVE please help me, i need
java source code about
total lost data in hard drive. how to find the
total deleted data ih hard drive using
java programming... this my project...pls help me
java applet progjava applet prog
applet to display scrolling text from right to left in an
applet window using thread. text should be accepted by html parameter
java - Appletjava 1.An
applet program to draw a line graph for y=2x+5.[for suitable values of x & y]
2. An
applet program to draw following shapes
(1)cone... java.applet.Applet;
public class CubeExample extends
Applet {
Stroke
need a login applet in javaneed a login
applet in java i'm
java beginner. Can some
java master teach me how to write a login
applet? combine with my coding
import... java.text.*;
import java.awt.event.*;
public class BoatRental extends
Applet implements
need a login applet in javaneed a login
applet in java i'm
java beginner. Can some
java master teach me how to write a login
applet? combine with my coding
import... java.text.*;
import java.awt.event.*;
public class BoatRental extends
Applet implements
core java - Appletcore java how can draw rectangle in
applet. when i pressed in mouse
button the rectangle's size will also increase
The Java Applet Viewer The
Java Applet Viewer
Applet viewer is a command line program to run
Java applets...; the browser should be
Java enabled.To create an
applet, we need to define
Java Programming - AppletJava Programming Write an
applet that accepts a string as input...
Applet implements ActionListener {
Label l1,l2,l3;
TextField text;
Button b... = new
Button("Reverse");
b.addActionListener(this);
p.add(l1);
p.add(text
disable keyboard in java appletdisable keyboard in
java applet How to disable key board of my client in an
java applet embedded in a website while the
applet is running.? Plz help
Java appletJava applet How do you set security in applets
Java appletJava applet How are the differences between Applets and Applications
Java appletJava applet What is the sequence for calling the methods by AWT for applets
Java appletJava applet What is the relationship between the Canvas class and the Graphics class
Java appletJava applet What is the relationship between the Canvas class and the Graphics class
java - Appletjava what is the use of java.utl Hi Friend,
The
java...://www.roseindia.net/
java/example/
java/util/
http://www.roseindia.net/
java/example/
java/util/
java-util-package.shtml
Thanks
Java appletJava applet How do I determine the width and height of my application