stuck on button code


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: stuck on button code

  1. #1
    Join Date
    Sep 2006
    Posts
    6

    stuck on button code

    Im new to programing i made a little program that increases or decreases the value of 1000 by 1. I wanna no how i can add anther button to reset the value back to 1000. right now the reset button increases. can anyone help


    Code:
    package ello;
    import java.applet.*;
    import java.awt.*;
       public class Button2 extends Applet
       {  Button increase, decrease, reset;            
          int value = 1000;
        
          public void init (){
          setBackground (Color.black);
          setForeground (Color.white);
          }
          
          
    
          {
             reset = new Button ("Reset the value");
             add (reset);
            
             increase  = new Button("Increase the value");
            add(increase);
      
            decrease = new Button("Decrease the value");
            add(decrease);
            
            
          }
          public boolean action (Event e, Object args)
            { if (e.target == reset)
               value++;
             if (e.target == increase)
             value++;
            if (e.target == decrease)
             value--;
            repaint();
            return false;
           }
          
          
          public void paint (Graphics g)
          { g.drawString("The value is currently " + value, 50, 80);
          }
       }

  2. #2
    Join Date
    Apr 2006
    Posts
    20
    you've put in

    Code:
    if (e.target == reset)
               value++;
    change it to

    Code:
    if (e.target == reset)
               value=1000;
    simple fix ^^

  3. #3
    Join Date
    Sep 2006
    Posts
    6
    ok thx

Similar Threads

  1. Getting a GUI to run
    By Eric in forum Java
    Replies: 4
    Last Post: 04-14-2006, 10:09 AM
  2. Binding navigator button code
    By Franco22 in forum .NET
    Replies: 0
    Last Post: 02-24-2006, 06:17 PM
  3. Speaking of strings...
    By Harlow in forum .NET
    Replies: 246
    Last Post: 10-26-2002, 01:30 AM
  4. Brain Washing
    By Danny Bowman in forum .NET
    Replies: 152
    Last Post: 09-13-2001, 08:23 AM
  5. Determine which mouse button cliked
    By Natalie in forum VB Classic
    Replies: 12
    Last Post: 01-19-2001, 08:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center