Name:Roi Philip D. Orozco Guessing Game
Name:Roi Philip D. Orozco Guessing Game
_____________________________________________________________________________________
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
JLabel j4;
ButtonListener bl1;
ButtonListener2 bl2;
ButtonListener3 bl3;
int count=0;
public Guess()
Container c = getContentPane();
c.setLayout(null);
c.setBackground(Color.WHITE);
//Creating image
lblpic.setIcon(new ImageIcon("images.png"));
lblpic.setBounds(0,0,500,350);
j.setForeground(Color.RED);
j.setFont(new Font("tunga",Font.BOLD,24));
j.setSize(270,20);
j.setLocation(300,35);
j1.setFont(new Font("tunga",Font.PLAIN,17));
j1.setSize(270,20);
j1.setLocation(300,60);
t1=new JTextField(10);
t1.setSize(50,30);
t1.setLocation(350,80);
j4.setFont(new Font("tunga",Font.PLAIN,17));
j4.setSize(270,20);
j4.setLocation(290,130);
//Creating Text field for best score
t2=new JTextField(10);
t2.setSize(40,20);
t2.setLocation(10,10);
j5.setFont(new Font("tunga",Font.PLAIN,17));
j5.setSize(270,20);
j5.setLocation(60,10);
t3=new JTextField(10);
t3.setSize(40,20);
t3.setLocation(160,10);
j6.setFont(new Font("tunga",Font.PLAIN,17));
j6.setSize(270,20);
j6.setLocation(210,10);
//creating 3 buttons
b1.setSize(150,40);
b1.setLocation(260,250);
bl1=new ButtonListener();
b1.addActionListener(bl1);
JButton b2=new JButton("Give up!");
b2.setSize(100,30);
b2.setLocation(180,200);
bl2=new ButtonListener2();
b2.addActionListener(bl2);
b3.setSize(120,30);
b3.setLocation(330,200);
bl3=new ButtonListener3();
b3.addActionListener(bl3);
c.add(j5);
c.add(j4);
c.add(lblpic);
c.add(j);
c.add(j1);
c.add(t1);
c.add(t2);
c.add(t3);
c.add(b1);
c.add(b2);
c.add(b3);
c.add(j6);
t3.setEditable(false);
setSize(550,350);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
int bestScore=100;
int a = Integer.parseInt(t1.getText());
count=count+1;
if(a<rand)
else if(a>rand)
else
{
j4.setText("CORRECT, YOU WIN!!!!");
if(count<bestScore)
bestScore=count;
t2.setText(bestScore+"");
else
t2.setText(""+bestScore);
t1.setEditable(false);
t1.requestFocus();
t1.selectAll();
t3.setText(count+"");
t3.setText("");
t1.setText("");
t1.setEditable(false);
}
private class ButtonListener3 implements ActionListener
rand=(int) (Math.random()*100);
t1.setText("");
t3.setText("");
t3.setText("");
count=0;
t1.setEditable(true);
t1.requestFocus();
new Guess();