Needs help in logic
Hi guys: Can any one please help me in that program. I try it but
stuck in it.
ask user to enter random number between 1 to 1000 using JTextfield.
Input the user's guess in the code for a previously-registered event-
handler method or the actionPerformed method of class based on the
ActionListener
interface. For the first guess color the entire background red. If
this is the second or later guess, and they are further from the
correct number than the last guess, then color the entire background
blue. If they get the correct number then
color the background some other color than red or blue. If the user
guessed the number correctly, respond with their number, post a
congratulatory message, get a new random number, and display a JButton
to start a new game. Otherwise, to help the user close in on the
correct number, post a message, with their guessed number, whether
they are "TOO HIGH" or "TOO LOW" from the correct number, and whether
they are "WARMER" or "COLDER" (this should match the background
color). Also report the guess number of the next guess (e.g. "Enter
guess number nnn"). use a concatenated string in JLabel for these
incorrect guess messages. The process is repeated each game until the
user guesses the correct number. erase obsolete status messages.
import java.awt.*;
import javax.swing.*;
public class guessprogram {
public static void main(String args[]){
String title = (args.length == 0 ? "Guess Program"
: args[0]);
JFrame frame = new JFrame(title);
Container content = frame.getContentPane();
JPanel namePanel = new JPanel(new BorderLayout());
JLabel nameLabel = new JLabel("Enter Number: ");
JTextField nameTextField = new JTextField();
nameLabel.setLabelFor(nameTextField);
namePanel.add(nameLabel, BorderLayout.WEST);
namePanel.add(nameTextField, BorderLayout.CENTER);
content.add(namePanel, BorderLayout.NORTH);
frame.setSize(250, 150);
frame.setVisible(true);
}
}