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); } }


Reply With Quote


Bookmarks