Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

import java.awt.*;
import javax.swing.*;
import java.util.*;

// Model class
class FrogModel {
    private int xc;
    private int yc;

    public FrogModel() {
        // Initialize frog's coordinates randomly
        Random rng = new Random(); // Creating an instance of Random
        xc = rng.nextInt(200);
        yc = rng.nextInt(200);
    }

    public int getX() {
        return xc;
    }

    public int getY() {
        return yc;
    }

    public void leap() {
        // Update frog's coordinates randomly
        Random rng = new Random(); // Creating an instance of Random
        xc = rng.nextInt(200);
        yc = rng.nextInt(200);
    }
}

// View class
class FrogView extends JPanel {
    private FrogModel model;

    public FrogView(FrogModel model) {
        this.model = model;
        setBackground(Color.BLUE);
    }

    @Override
    protected void paintComponent(Graphics gc) {
        super.paintComponent(gc);
        gc.setColor(Color.GREEN);
        gc.fillOval(model.getX(), model.getY(), 10, 10); // Adjust size as needed
    }
}

// Controller class
class FrogController {
    private FrogModel model;
    private FrogView view;

    public FrogController(FrogModel model, FrogView view) {
        this.model = model;
        this.view = view;
    }

    public void leap() {
        model.leap();
        view.repaint();
    }
}

// Main class
public class FroggerMVC {
    public static void main(String[] args) {
        FrogModel model = new FrogModel();
        FrogView view = new FrogView(model);
        FrogController controller = new FrogController(model, view);

        // Set up GUI
        JFrame frame = new JFrame("Frogger");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(view);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);

        // Leap button setup
        JButton leapButton = new JButton("Leap");
        leapButton.addActionListener(e -> controller.leap());
        frame.getContentPane().add(leapButton, BorderLayout.SOUTH);
    }
}

i'm trying to run the code in replit but the code is not running. can you check from your side if this code correct and what i do to run this code. 

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education