I have a code in which there is a variable v
whose default value is 0 . I also have 2 buttons : ok
and nope
. Using my code, when ok
is pressed, the value of v
should be 1 and when nope
is pressed the value of v
should be 2. But in both the cases it is printing the value of v
as 2. Why is this? How can I correct it?
Edit : I did a minor mistake, I have corrected it, thanks to MadProgrammer.
import java.awt.*;
public class chk extends java.applet.Applet
{
Button ok = new Button("OK!");
Button nope = new Button("Nope");
int v = 0;
public void init()
{
setBackground(Color.white);
add(ok);
add(nope);
}
public boolean action(Event evt , Object arg)
{
if(evt.target instanceof Button)
{
check((Button)evt.target);
return true;
}
return false;
}
public void check(Button b)
{
if(b == ok);
{
v= 1;
repaint();
}
if(b == nope);
{
v=2;
repaint();
}
}
public void paint(Graphics g)
{
g.drawString(""+v,40,40);
}
}
All help is appreciated. Please let me know if I've made any mistakes.