Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Forrest
Java Applet - Adding a Button to Decrease a Total
1 Answer(s)      2 years and 6 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!


Advertisement
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:
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
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
Advertisements
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
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
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
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
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
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 - Applet
java  how to connect database table with scrollbar in java applet
java - Applet
java  how to connect database table with scrollbar in java applet
java - Applet
java  what is applet?  Hi Friend, Please visit the following link: http://www.roseindia.net/java/example/java/applet/ 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
Tutorial for total beginner in Java
Tutorial for total beginner in Java - Explains the Basics of Java programming language. This is a video tutorial for total beginner in Java. In this video... language. This video is for total beginner in Java which will teach how to create
java applet
java applet  why java applet programs doesn't contain main method
java applet
java applet  why java applet programs doesn't contain main method
java applet
java applet  If i insert in database from applet this work, but from applet.html don't
Java applet
Java applet   How do I go from my applet to another JSP or HTML page
Java applet
Java applet  What tags are mandatory when creating HTML to display an applet
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
Java Applet
Java 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 - Applet
java  what is applet
java - Applet
java  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 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
Applet
Applet  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 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
Advertisements
 

 

 

DMCA.com