Home Answers Viewqa Applet Java Applet - Adding a Button to Decrease a Total

 
 


Forrest
Java Applet - Adding a Button to Decrease a Total
1 Answer(s)      11 months ago
Posted in : Applet

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 Pages:
applet - Applet
*; import java.awt.*; public class CreateTextBox extends Applet implements...); add(text,"center"); Button button = new Button("Hello"); button.addActionListener(this); add(l); add(text); add(button
Not getting desired output while button is pressed in java applet program
Not getting desired output while button is pressed in java applet program ... T1 and T2 get subtracted and comes in T3 after we press the button.../// import...*; import java.awt.Font; public class abc extends Applet implements ActionListener
java applet - Applet
java 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 - Applet
java 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
need a login applet in java
need 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 java
need 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
Jav Applets - Applet
*rate; t3.setText(Integer.toString(total)); } } 2)applet.html: Java...Jav Applets  I need to write a small payroll program, using applet... labels to identify all three text fields and a button to calculate the result
java - Applet
java  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
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
java 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
Java Application change to java applet
Java Application change to java applet   Hi every Java Masters i'm Java beginner ,and i want below this figures source code convert to Java Applet... extends Applet implements ActionListener{ TextField text,output; Label
Hide Close Button in Java Applet - Java Server Faces Questions
Hide Close Button in Java Applet  I have an applet while running...... button or close button. Java Applet Code - Show and Hide Buttons on Applet  Java Applet code to display minimize and maximize button on Applet and code
java applet
java 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 applet
java 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
Applet
Applet  Draw the class hierarchy of an Applet class. Also explain how to set background and forground colors in java
Applet program
Applet program  Write a java applet for the following case.... 100. All above charges are applicable per day basis. The applet will display the total payment to be paid by the customer on check-out from the hotel
how to add database in Java Applet
how to add database in Java Applet  hi every java master or Java Professional my name is vincent i'm java beginners hope u all can ,tech me how to add database in Java Applet below this code is my applet source code . thank
applet
applet  applet to open new tab not working.here's my code import...*; public class NewURL extends Applet implements ActionListener{ public void init(){ String link_Text = "google"; Button b = new Button(link_Text
applet
applet  what is applet in java   An applet is a small program that can be sent along with a Web page to a user. Java applets can perform... the following link: Applet Tutorials
Applet
Applet  Write a Java applet that drwas a line between 2 points. The co-ordinates of 2 points should be passed as parametrs from html file. The color of the line should be red
Applet Graph
Applet Graph  hai, iam new to java plz help me.. 1..i have a table... columns-names by using check box and click on graph button, 3..then i have to get a graph between those columns in a applet plz send me the code thank u
core java - Applet
core java  how can draw rectangle in applet. when i pressed in mouse button the rectangle's size will also increase
Swings - Applet
to call that class in applet. is it possible. or otherwise is there any way to deploy java class in browser. Give an example... Thanks in advance...  Hi... extends Applet{ CountCharacters c=new CountCharacters(); Label l1,l2,l; TextField
Swing - Applet
Swing  Hello, I am creating a swing gui applet, which is trying... showing the result, and thee will be a button hihc the user will click... = new JPanel(); JButton button = new JButton("Calculate"); panel.add
applet - Applet
in Java Applet.",40,20); } } 2) Call this applet with html code...: http://www.roseindia.net/java/example/java/applet/ Thanks....  Hi Friend, Try the following code: 1)Create an applet
Applet - Applet
, Applet Applet is java program that can be embedded into HTML pages. Java applets... in details to visit.... http://www.roseindia.net/java/example/java/applet...Applet  what is the concept of applet? what is different between
Java Programming - Applet
Java 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
Write an applet that prints "Lear Java it is useful" at the current cursor position whenever the mouse left button is clicked.
Write an applet that prints "Lear Java it is useful" at the current cursor position whenever the mouse left button is clicked.   Write an applet that prints "Lear Java it is useful" at the current cursor position whenever
difference - Applet
as JFC?s (Java Foundation classes). 2) AWT components use native methods Swing components use the methods that are written in Java. Therefore AWT is heavy... are rectangular 5) Swings components are made in pure java and they are platform
Java program to generate the total count
Java 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
core java - Applet
core java   Namaste sir , how can draw a line in Applet. I want when I press mouse button and moves any way then show the line . i, working jdk1.5.0_17 version. without use Canvas and Frame. like this: when press mouse button
java Application to java Applet
java Application to java Applet  sorry Java master disturb again how can i modify below this Java application to applet because in swtich case i had...; System.out.println("Rental Total Charges= "+df.format(amount)); System.out.println
how to convert java Applet to Jave Frame
how to convert java Applet to Jave Frame  hi every java master or Java Professional my name is vincent i'm java beginners hope u all can ,tech me how to convert Java Applet to Jave Frame below this code is my applet source code
java button - Java Beginners
java button  i want to make form with checkboxes, after this i need button thich will open new pop-up page, where will be shown only this checkboxes..."); private JCheckBox cb4 = new JCheckBox("Check Box 4"); private JButton button
Applet - Applet
------------------------"); g.drawString("Demo of Java Applet Window Event Program"); g.drawString("Java...Applet   Namaste, I want to create a Menu, the menu name is "Display... java.awt.event.*; public class menu2frame extends Applet implements WindowListener
java application/applet - Java Beginners
java application/applet  In this project, the student has to develop and submit a program for a Java application / applet which contains a set of GUI components as detailed below. 1. The Java applet page/application models
java - Applet
java  what is applet
Java GUI - Applet
Java GUI  HELLO, i am working on java chat server, i add... but not resolve my prob. dear friend, i add JFrame Form in java package and put a button like that code: public class ClientGUI extends javax.swing.JFrame
java total lost data in hard drive
java 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 drive
java 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 drive
java 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 DRIVE
JAVA 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 - Applet
java 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
Applet for add two numbers
Applet for add two numbers  what is the java applet code for add two...; } public void paint(Graphics g) { //writes the output in the applet starting... Applet implements ActionListener{ TextField text1,text2,output; Label
loading Java Applet - Applet
loading 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 Application Convert to java Applet
java Application Convert to java Applet  Hi every Java Masters i'm Java beginner ,and i want below this figures source code convert to Java Applet... amount=(day-0)*60.00 + 100.00; System.out.println("Rental Total Charges
Applet in Eclipse - Running Applet In Eclipse
in Eclipse 3.0. An applet is a little Java program that runs inside a Web...->New->Project... from the menu bar to begin creating your Java applet....     Step 8:  Create java applet code saving and compiling
applet problem - Applet
applet problem  How can I create a file in client side by a java applet . Surely it will need a signed applet .But how can a signed applet create a file in the client side
java - Applet
java  how to connect database table with scrollbar in java applet

Ask Questions?

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.