1. Create a simple game that will allow user to guess the secret number. 2. Create a folder named LastName_FirstName (ex. Reyes_Mark) in your local drive. 3. Create a new project named LabExer7A. Set the project location to your own folder. 4. Add another class named RunNumberFinder. 5. For the LabExer7A class, instantiate an object of NumberFinder to create a JFrame in the main method. Set the object’s width to 600 and height to 200. Make sure the JFrame is visible. 6. For the LabExer7A class, perform the following: 6.1 Construct import

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

1. Create a simple game that will allow user to guess the secret number.
2. Create a folder named LastName_FirstName (ex. Reyes_Mark) in your local drive.
3. Create a new project named LabExer7A. Set the project location to your own folder.
4. Add another class named RunNumberFinder.
5. For the LabExer7A class, instantiate an object of NumberFinder to create a JFrame in the main
method. Set the object’s width to 600 and height to 200. Make sure the JFrame is visible.
6. For the LabExer7A class, perform the following:

  • 6.1 Construct import statements to use the packages listed below:
    • javax.swing
    • java.awt
    • java.awt.event
    • java.util
  • 6.2 Extend the JFrame class and implement the MouseListener interface. (The MouseListener
    interface is for receiving mouse events such as click and press on a component.)
  • 6.3 Create the following objects/variables outside all methods (just below the class declaration):
    • One (1) FlowLayout object
    • Two (2) Font objects: For the first object, set the typeface to Arial, style to Bold, and point
    size to 100. For the second, set the typeface to Century, style to Bold, and point size to 20.
    Syntax: Font nameOfFontObj = new Font(“Typeface”, Font.STYLE, point size);
    • 10 JLabel objects: Nine (9) are for displaying numbers 1-9 while the tenth JLabel is for
    displaying the result (initially set to blank text). Syntax: JLabel nameOfJLabelObj = new
    JLabel(“1”);
    • Random object
    • Two (2) integers: One is for accepting the value of the random number from 1-9 while the
    other is for counting the number of guess attempts.
    Note: Additional objects/variables may be created.
  • 6.4 Follow the instructions below for the content of the LabExer7A constructor.
    • Place the statement super(“Number Finder”);
    • Set the Java program to end when the Close or X button is clicked.
    • Set the previously created FlowLayout object as the layout. Syntax:
    setLayout(nameOfFlowLayoutObj);
  • Set the first Font object as the font setting of the nine (9) JLabel objects. Set the second Font object as the font setting of the tenth JLabel object. Ex. nameOfJLabelObj.setFont(nameOfFontObj);
  • Add the JLabel objects to the JFrame. Ex. add(nameOfJLabelObj);
  • Set the nine (9) JLabel objects as mouse listeners. Ex. nameOfJLabelObj.addMouseListener(this);
  • Set the first Font object as the font setting of the nine (9) JLabel objects. Set the second Font object as the font setting of the tenth JLabel object. Ex. nameOfJLabelObj.setFont(nameOfFontObj);
  • Add the JLabel objects to the JFrame. Ex. add(nameOfJLabelObj);
  • Set the nine (9) JLabel objects as mouse listeners. Ex.nameOfJLabelObj.addMouseListener(this)

6.5 Construct the five (5) required methods of the MouseListener interface. The program will not
execute if these methods are not complete.
• mouseClicked
• mousePressed
• mouseReleased
• mouseEntered
• mouseExited
Ex. public void mouseClicked(MouseEvent e) { }
The program shall:
• allow the user to click a number until the secret number is found
• display a JLabel (the tenth JLabel created earlier) to indicate the result of the guess. Show “Try again.” if the guess is wrong. Otherwise, show “Correct!” and the number of guess attempts.


6.6 In the mouseClicked method, create multiple if-else statements to accomplish the program flow.
See example below.
if (e.getSource()==nameOfLabelObj)
{
//events that will occur when the JLabel object is clicked
}
Here are some of the methods which you may find useful:
• getText() – to retrieve the current text of the JLabel
Syntax: nameOfJLabelObj.getText().equals(nameOfAnother);
• setEnabled() – to enable or disable the JLabel
Syntax: nameOfJLabelObj.setEnabled(booleanValue);
• toString() – to convert an integer to String
Syntax: Integer.toString(nameOfIntVar);

Set the firut fant abjecd athe fant eting of te nine abel stjactu. Sat the cond
Fant abject a te tont ng h abe object
namtabelong.utiont (nanolantan)i
• Add the abel abjec to the rane. Ex adajeantabelega
• Sat t nine abel cjeds rou dera a
namtabeloeg.admousistenarthiaji
The JFame should loak ke hi once the praganincut
Number firder
123456789
as Conutua ha ve S girnd rahed at the Moutetietaner inetfaca. The program wil nat
hes methodi nat completa
• moiad
• moreed
• moueRainmed
• mouseiniered
• mtad
Ee public vedd nouseclicknaselvent a) {)
The pragram ha
• alow he uner didkanunber unti he secutnunber ia fund
• dagiay a abel he tath ab cad sariar indicae the retd he gua
Show Try again"nhe gaiang. Othan, howComat" and the number
of pus rga Sea snahotu belo
Number firder
123456789
Try again.
Transcribed Image Text:Set the firut fant abjecd athe fant eting of te nine abel stjactu. Sat the cond Fant abject a te tont ng h abe object namtabelong.utiont (nanolantan)i • Add the abel abjec to the rane. Ex adajeantabelega • Sat t nine abel cjeds rou dera a namtabeloeg.admousistenarthiaji The JFame should loak ke hi once the praganincut Number firder 123456789 as Conutua ha ve S girnd rahed at the Moutetietaner inetfaca. The program wil nat hes methodi nat completa • moiad • moreed • moueRainmed • mouseiniered • mtad Ee public vedd nouseclicknaselvent a) {) The pragram ha • alow he uner didkanunber unti he secutnunber ia fund • dagiay a abel he tath ab cad sariar indicae the retd he gua Show Try again"nhe gaiang. Othan, howComat" and the number of pus rga Sea snahotu belo Number firder 123456789 Try again.
Nunber finder
123456789
Correet! 9 attemptla)
Ganhe ouscickad mathod o uigie tamanta to accomplah the progan ow
Se mple beow
1f (getsaurce )aa )
wenets that will accr uhan the abel saject is cliciad
Hee ane of the mathada which you may ind ta
• ptteat()-e ee he t ethe atel
Synta aoabe ettt).isao er
• utinaled) -to enabie or diubie the abel
Synta aofabej.etiab leal
• tustring)-o conertangw Sng
Synta integer.tostringnaoatar
Transcribed Image Text:Nunber finder 123456789 Correet! 9 attemptla) Ganhe ouscickad mathod o uigie tamanta to accomplah the progan ow Se mple beow 1f (getsaurce )aa ) wenets that will accr uhan the abel saject is cliciad Hee ane of the mathada which you may ind ta • ptteat()-e ee he t ethe atel Synta aoabe ettt).isao er • utinaled) -to enabie or diubie the abel Synta aofabej.etiab leal • tustring)-o conertangw Sng Synta integer.tostringnaoatar
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY