import?java.applet.Applet;
import?java.awt.Button;
import?java.awt.Color;
import?java.awt.Graphics;
import?java.awt.TextField;
import?java.awt.event.ActionEvent;
public?class?Nicki?extends?Applet{
private?static?final?long?serialVersionUID?=?1L; private?Button?ok; private?int?num=32; private?int?resu=0; private?boolean?isRig=false; private?TextField?iPut; public?Nicki(){ this.setLayout(null); ok=new?Button("OK"); ok.setActionCommand(getName()); ok.setBounds(150,?150,?40,?20); iPut=new?TextField(); this.add(iPut); iPut.setBounds(100,?150,?40,?20); this.add(ok); ok.addActionListener(new?ButtonAction(this)); } public?void?paint(Graphics?g){ g.setColor(Color.white); g.fillRect(0,?0,?this.getWidth(),?this.getHeight()); g.setColor(Color.BLACK); g.drawString("Please?guess?a?number?",?10,?20); g.drawString("between?1?and?100",?10,?40); if(isRig==false&&resu!=0){if(resu>num){
g.drawString(""+resu+"?is?too?big?!",?10,?100);
}else?if(resu<num){
g.drawString(resu+"is?too?small?!",?10,?100);
}
}else?if(isRig==true){g.setColor(Color.GREEN);
g.drawString("Yes,"+resu+"?is?the?right?number",?10,?80);
g.drawString("Your?are?great!?",?10,?100);
g.setColor(Color.red);
g.drawString(resu+"!",?70,?120);
} iPut.setText(""); g.drawString("Input?the?number:",?0,?150); } public?void?ButtonActionPerformed(ActionEvent?e){ if(e.getActionCommand().equals("panel0")){resu=Integer.parseInt(iPut.getText());
if(num==resu){
isRig=true;
}else{
isRig=false;
}
repaint();
} }}
class?ButtonAction?implements?java.awt.event.ActionListener{
Nicki?su; public?ButtonAction(Nicki?bun){ this.su=bun; } public?void?actionPerformed(ActionEvent?e)?{ su.ButtonActionPerformed(e); }}