Here is my code.new with this .thanks in advance im not sure how to use the random generator...i want to randomize my correct answer...i want to make sure that the next selection will not be the same jlabel ive selected..thank you very much if you could help me...new in programming here...
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class NumberFinder extends JFrame implements MouseListener{
FlowLayout f1 = new FlowLayout();
Font aFont = new Font("Arial", Font.BOLD, 100);
Font bFont = new Font("Century", Font.BOLD, 20);
JLabel a = new JLabel("1");
JLabel b = new JLabel("2");
JLabel c = new JLabel("3");
JLabel d = new JLabel("4");
JLabel ed = new JLabel("5");
JLabel f = new JLabel("6");
JLabel g = new JLabel("7");
JLabel h = new JLabel("8");
JLabel i = new JLabel("9");
JLabel j = new JLabel("");
int ran = 0;
int count = 0;
public NumberFinder()
{
super("Number Finder");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(f1);
a.setFont(aFont);
b.setFont(aFont);
c.setFont(aFont);
d.setFont(aFont);
ed.setFont(aFont);
f.setFont(aFont);
g.setFont(aFont);
h.setFont(aFont);
i.setFont(aFont);
j.setFont(bFont);
add(a);
add(b);
add(c);
add(d);
add(ed);
add(f);
add(g);
add(h);
add(i);
add(j);
a.addMouseListener(this);
b.addMouseListener(this);
c.addMouseListener(this);
d.addMouseListener(this);
ed.addMouseListener(this);
f.addMouseListener(this);
g.addMouseListener(this);
h.addMouseListener(this);
i.addMouseListener(this);
}
public void mouseClicked(MouseEvent e){
if(e.getSource()==a)
{
a.getText();
j.setText("Try Again");
a.setEnabled(false);
count ++;
}
else if(e.getSource()==b)
{
b.getText();
j.setText("Correct!");
b.setEnabled(true);
count ++;
}
else if(e.getSource()==c)
{
c.getText();
j.setText("Try Again");
c.setEnabled(false);
count++;
}
else if(e.getSource()==d)
{
d.getText();
j.setText("Try again");
d.setEnabled(false);
count++;
}
else if(e.getSource()==ed){
ed.getText();
j.setText("Try Again");
ed.setEnabled(false);
count++;
}
else if(e.getSource()==f){
f.getText();
j.setText("Try Again");
f.setEnabled(false);
count++;
}
else if(e.getSource()==g){
g.getText();
j.setText("Try Again");
f.setEnabled(false);
count++;
}
else if(e.getSource()==h){
h.getText();
j.setText("Try Again");
h.setEnabled(false);
count++;
}
else if(e.getSource()==i){
i.getText();
j.setText("Try Again");
i.setEnabled(false);
count++;
}}
public void mousePressed(MouseEvent e){
}
public void mouseReleased(MouseEvent e){
}
public void mouseEntered(MouseEvent e){
}
public void mouseExited(MouseEvent e){
}
}
Aucun commentaire:
Enregistrer un commentaire