Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question

anyone please help me with this java. i want this code to be fix i dont need any code. thank you

ERROR MESSAGE:

Error: Main method not found in class Gameframe, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application

------------------------------------------------------------------

JAVA CODE:

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.SwingUtilities;

public class Gameframe extends JFrame
{
private int Guesses = 1;
private int GuessOld = 0;
private int number;
private JTextField guessInputJTextField;
private JLabel prompt1JLabel;
private JLabel prompt2JLabel;
private JLabel messageJLabel;
private JLabel message2JLabel;
private JLabel random1 = new JLabel("");
private JButton newGameJButton;
private Color background;

public Gameframe(){
super("Guessing Game");
setLayout(new FlowLayout());
background = Color.LIGHT_GRAY;
prompt1JLabel = new JLabel("I have a number between 1 and 1000.");
add(prompt1JLabel);
prompt2JLabel = new JLabel("Can you guess my number? Enter your Guess:");
add(prompt2JLabel);
guessInputJTextField = new JTextField(5);
guessInputJTextField.addActionListener(new GuessHandler());
add(guessInputJTextField);
messageJLabel = new JLabel("");
add(messageJLabel);
message2JLabel = new JLabel("");
add(message2JLabel);
newGameJButton = new JButton("New Game");
add(newGameJButton);

Random generator = new Random();
number = generator.nextInt(1001);

newGameJButton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
guessInputJTextField.setText("");
Random generator = new Random();
number = generator.nextInt(1001);
random1.setText("" + number);
SwingUtilities.updateComponentTreeUI(random1);
messageJLabel.setText("");
guessInputJTextField.setEditable(true);
Guesses = 0;
message2JLabel.setText("Number of Guesses: " + Guesses);
Guesses++;
}
}
);
theGame();
}

public void theGame()
{
}

class GuessHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
int Guess;
Guess = Integer.parseInt(guessInputJTextField.getText());
if (Math.abs(number - Guess) < Math.abs(number - GuessOld))
{
getContentPane().setBackground(Color.RED);
}
else
{
getContentPane().setBackground(Color.BLUE);
}
GuessOld = Guess;
if (Guess > number)
{
messageJLabel.setText("Too High.");
SwingUtilities.updateComponentTreeUI(messageJLabel);
}
if (Guess < number)
{
messageJLabel.setText("Too Low.");
SwingUtilities.updateComponentTreeUI(messageJLabel);
}
if (Guess == number)
{
messageJLabel.setText("Correct!");
SwingUtilities.updateComponentTreeUI(messageJLabel);
guessInputJTextField.setEditable(false);
}
message2JLabel.setText("Number of Guesses: " + Guesses++);
}
}
}

 

 

 

-----------------------

public class GuessGame
{
public static void main(String args[]) throws Exception
{
Gameframe guessgame = new Gameframe();
guessgame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
guessgame.setSize(550, 150);
guessgame.setVisible(true);
}
}

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