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



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

Have Programming Question? Ask it here!
 
 
 


Forrest
Java Applet - Adding a Button to Decrease a Total
1 Answer(s)      a year and 10 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  What tags are mandatory when creating HTML to display an applet
Java applet
Java applet   How do I go from my applet to another JSP or HTML page
java applet
java applet  If i insert in database from applet this work, but from applet.html don't
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
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
java - Applet
java  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
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  What is AppletStub Interface
Java applet
Java applet  what are types of applets
Java applet
Java applet  How do you set security in applets
Java applet
Java applet   How are the differences between Applets and Applications
Java applet
Java applet  What is the sequence for calling the methods by AWT for applets
Java applet
Java applet  What is the relationship between the Canvas class and the Graphics class
Java applet
Java applet  What is the relationship between the Canvas class and the Graphics class
java - Applet
java  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
Write an applet program to transfer the content of the text field into the component on clicking a button
Write an applet program to transfer the content of the text field into the component on clicking a button  Write an applet program to transfer the content of the text field into the component on clicking a button
Java applet
Java applet  How do I determine the width and height of my application
Java applet
Java applet  How can I arrange for different applets on a web page to communicate with each other
java applet
java applet  create applets to accept the personal details and sales details in the database. create jdbc application to connect the applets with the database
java - Applet
java  Hi, I need very urgent code............ please help me......... How to convert text to wave conversion? I need java code............ Regards, Valarmathi
java - Applet
://www.roseindia.net/java/example/java/swing/graphics2D/index.shtml Thanks
Java applet
Java applet  I wanted as many clicks are there ,circles should be displayed there. I tried this code but it erases previous circles. plz help. public void mouseClicked(MouseEvent m) { x=m.getX(); y=m.getY
Java applet
Java applet  I wanted as many clicks are there ,circles should be displayed there. I tried this code but it erases previous circles. plz help. public void mouseClicked(MouseEvent m) { x=m.getX(); y=m.getY
Java Applet
Java Applet  Hi, I have a query, on every mouse click an oval should be drawn. But in my program I have used repaint() function, therefore previous oval gets erased.How to avoid this so that I get more than one oval. PFB
Advertisements
 

 

 

DMCA.com