OK.
I made small changes. Below are the codes, both for the .java and .html.
You need to have large enough applet window in the html page so that you could see the string Yo Ya won... etc
That is because of the coordinates where you draw the string. Now I also made some changes in the decide() function, but only with the position of the curly braces. Now your logic errors were made by bad formatting the code of the .java file.
Ok you'll see the differences, but since this is applet, I suggest you delete the rps.class file. Then use the codes below. If you have any questions or problems with it, you know where to ask. Enjoy
rps.javaCODE
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class rps extends Applet implements ActionListener
{
Button Scissor;
Button Paper;
Button Rock;
Button Reset;
int count, random, userChosen, won, lost, draw, cpuChosen,total,result;
String user, cpu;
public void init()
{
Scissor = new Button ("Scissor");
Paper = new Button ("Paper");
Rock = new Button ("Rock");
Reset = new Button("Reset");
add(Paper);
add(Scissor);
add(Rock);
add(Reset);
Paper.addActionListener(this);
Scissor.addActionListener(this);
Rock.addActionListener(this);
Reset.addActionListener(this);
user = " nothing ";
cpu = " nothing ";
result = 0;
}
public void actionPerformed(ActionEvent e)
{
cpuChosen = (int) (Math.random()*3 +1);
if (e.getSource() == Rock)
{
userChosen = 1;
user = "Rock";
count = 1;
}
if (e.getSource() == Paper){
userChosen = 2;
user = "Paper";
count = 1;
}
if (e.getSource() == Scissor)
{
userChosen = 3;
user = "Scissor";
count = 1;
}
if (cpuChosen == 1)
{
cpu = "Rock";
}
if (cpuChosen == 2)
{
cpu = "Paper";
}
if (cpuChosen == 3)
{
cpu = "Scissor";
}
total++;
if(e.getSource() == Reset)
{
user = "nothing";
cpu = "nothing";
total = 0;
count = 0;
won = 0;
lost = 0;
}
repaint();
}
public void decide()
{
if(userChosen==1)
{
if (cpuChosen==1)
{
result = 2;
draw++;
}
else if (cpuChosen==2)
{
result = 3;
lost++;}
else
{
result = 1;
won++;
}
}
else if(userChosen==2)
{
if (cpuChosen==1)
{
result = 1;
won++;
}
else if (cpuChosen==2)
{
result = 2;
draw++;
}
else
{
result = 3;
lost++;
}
}
else if(userChosen==3)
{
if (cpuChosen==1)
{
result = 3;
lost++;
}
else if (cpuChosen==2)
{
result = 1;
won++;
}
else
{
result = 2;
draw++;
}
}
}
public void paint (Graphics g)
{
decide();
g.fillRect(0, 0, 1280, 800);
g.setColor(Color.white);
g.drawString("alex a.k.a kazaf, all rights reserved", 300, 400);
g.drawString(""+draw , 230, 300);
g.drawString(""+lost , 60, 300);
g.drawString(""+won , 150, 300);
g.drawString("Ya chosen " + user, 200, 140);
g.drawString("CPU chosen " + cpu, 200, 160);
g.drawString("--result--" + result, 100, 360);
g.drawString("--userChosen--" + userChosen, 100, 380);
g.drawString("--cpuChosen-" + cpuChosen, 100, 400);
if (result == 1)
{
g.drawString("Yo, Ya won!", 200, 200);
}
else if (result ==2)
{
g.drawString("it's drawn, Come on. try again", 200, 200);
}
else
{
g.drawString("Oh, sorry! ya lost!", 200, 200);
}
}
}
rps.htmlCODE
<html>
<head>
<applet code="rps.class" height=800 width=600 >
</applet>
</head>
<body>
</body>
</html>