Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Please help me fix this java code which is supposed to be a Pac-Man game
Java program is below
import java.awt.*;
import javax.swing.JFrame.*;
public class ManyPacMans extends JFrame
{
public void paint(Graphics g)
{
g.drawghostShape(60,30,40);
setBackground(Color.BLUE);
g.fillghostShape(130, 30,100, 80);
g.drawghostShape(60,30,40);
setBackground(Color.PINK);
g.fillghostShape(130, 30,100, 80);
g.drawghostShape(60,30,40);
setBackground(Color.RED);
g.fillghostShape(130, 30,100, 80);
g.drawOvalpacman(30,130,50, 60);
setForeground(Color.yellow);
g.fillOval(130,130,50, 60);
}
public Ghost(String imgPath, int x, int y, int speed, boolean ip)
{
super(imgPath, new int[] {0,0}, GHOST_WIDTH, GHOST_HEIGHT, GHOST_FRAMERATE, x, y);
super.addFramesForAnimation("scatter", "ghost_scatter.png", 0, 0, 22,0);
super.speed = speed;
startX = x;
startY = y;
scoreValue = 200;
}
public ManyPacMans()
{
initUI();
}
private void initUI()
{
add(new Board());
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(380, 420);
setLocationRelativeTo(null);
}
public static void main(String[] args)
{
ManyPacMans m= new ManyPacMans();
JFrame f = new JFrame();
m.paint();
f.add(m);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
EventQueue.invokeLater(() -> { var ex = new Pacman(); ex.setVisible(true); });
}
}
Expert Solution
arrow_forward
Step 1 Introduction
Java which refers to a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. Java is an object oriented programming languages and also it is used to create the web applications.
Step by stepSolved in 3 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.Similar questions
- Build a program using encapsulation base on the image below.arrow_forwardJAVA SWINGI have definied a straight TUBE as: int rectWidth = 25; // replace 50 with the desired width of the rectangleint rectHeight = 200; // replace 200 with the desired height of the rectangleint rectX = (this.getWidth() - rectWidth) / 2;int rectY = (this.getHeight() - rectHeight) / 2;game.fillRect(rectX, rectY, rectWidth, rectHeight);I need L tube, which connects the straight tubes. How to define L tubes?arrow_forwardWhy does the Number Class from this slide need to be abstract?arrow_forward
- Implement a date picker in javafx having following properties1) only numerical value can be typed in it2) / ( forward slash) appears in it when form prompt and user can write date in it3)only 8 digits can be typed in itarrow_forwardcan someone help me resize the picture in Java. This is my code: import java.awt.*;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import javax.imageio.ImageIO; class ImageDisplayGUI { public static void main(String[] args) { SwingUtilities.invokeLater(() -> { createAndShowGUI(); }); } private static void createAndShowGUI() { JFrame frame = new JFrame("Bears"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(800, 600); frame.setLayout(new BorderLayout()); // Load and display the JPG image try { BufferedImage image = ImageIO.read(new File("two bears.png")); // Replace with your image path ImageIcon icon = new ImageIcon(image); JLabel imageLabel = new JLabel(icon); frame.add(imageLabel, BorderLayout.CENTER); } catch (IOException e) { // Handle image loading error…arrow_forwardYou have to use comment function to describe what each line does import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class PreferenceData { private final List<Student> students; private final List<Project> projects; private int[][] preferences; private static enum ReadState { STUDENT_MODE, PROJECT_MODE, PREFERENCE_MODE, UNKNOWN; }; public PreferenceData() { super(); this.students = new ArrayList<Student>(); this.projects = new ArrayList<Project>(); } public void addStudent(Student s) { this.students.add(s); } public void addStudent(String s) { this.addStudent(Student.createStudent(s)); } public void addProject(Project p) { this.projects.add(p); } public void addProject(String p) { this.addProject(Project.createProject(p)); } public void createPreferenceMatrix() { this.preferences = new…arrow_forward
- please code in java..refer the 2 codes BankAccount and AccountTest.. BankAccount source code is given below and AccountTest source code is added in image Question is to add code to be able to lock the account. for example if someone withdraws a certain amount of money the accounts locks, etc /** The BankAccount class simulates a bank account.*/ public class BankAccount{ private double balance; // Account balance /** This constructor sets the starting balance at 0.0. */ public BankAccount() { balance = 0.0; } /** This constructor sets the starting balance to the value passed as an argument. @param startBalance The starting balance. */ public BankAccount(double startBalance) { balance = startBalance; } /** This constructor sets the starting balance to the value in the String argument. @param str The starting balance, as a String. */ public BankAccount(String str) { balance =…arrow_forwardIn Java intellej Correct this code and add the following 1.Correct: (The error shows a problem under () next to "firstBeachShoot.printPhotoDetails") 2.Add the following to the second package (screenshot): 1.for or for...each or while loops. 2.Arrays 3.default, no-args and parameterized constructors. Here's the first package : import java.util.Scanner;public class Image {int numberOfPhotos; // photos on rolldouble fStop; // light let it 1.4,2.0,2.8 ... 16.0int iso; // sensativity to light 100,200, 600int filterNumber; // 1-6String subjectMatter;String color; // black and white or colorString location;boolean isblurry;public String looksBlurry(boolean key) {if (key == true) {return "Photo is Blurry";} else {return "Photo is Clear";}}public void printPhotoDetails(String s1) {Scanner br = new Scanner(System.in);String subjectMatter = s1;System.out.println("Data of Nature photos:");System.out.println("Enter number of photos:");numberOfPhotos = br.nextInt();int i = 1;while…arrow_forwardjavaarrow_forward
- Implement the following in the .NET Console App. Write the Bus class. A Bus has a length, a color, and a number of wheels. a. Implement data fields using auto-implemented Properies b. Include 3 constructors: default, the one that receives the Bus length, color and a number of wheels as input (utilize the Properties) and the Constructor that takes the Bus number (an integer) as input.arrow_forwardPlease help me fix the errors in the java program below. There are two class AnimatedBall and BouncingBall import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;public class AnimatedBall extends JFrame implements ActionListener{private Button btnBounce; // declare a button to playprivate TextField txtSpeed; // declare a text field to enterprivate Label lblDelay;private Panel controls; // generic panel for controlsprivate BouncingBall display; // drawing panel for ballContainer frame;public AnimatedBall (){// Set up the controls on the appletframe = getContentPane();btnBounce = new Button ("Bounce Ball");//create the objectstxtSpeed = new TextField("10000", 10);lblDelay = new Label("Enter Delay");display = new BouncingBall();//create the panel objectscontrols = new Panel();setLayout(new BorderLayout()); // set the frame layoutcontrols.add (btnBounce); // add controls to panelcontrols.add (lblDelay);controls.add…arrow_forwardPlease help me with my Java assignment. I need to know why I can't seem to get rid of my bug errors and if I had indented wrong because I'm supposed to get my dialog box pop up and it doesn't even if I did overcame my bugs. My assignment is below this message as follows: import javax.swing.JOptionPane; public class MultipleChoiceQuestion {static int correct = 0;static int incorrect = 0;String question;String correctAnswer;MultipleChoiceQuestion(String query, String a, String b, String c, String d, String e, String Answer) {question = query+"\n";question = "A. "+a+"\n";question = "B. "+b+"\n";question = "C. "+c+"\n";question = "D. "+d+"\n";question = "E. "+e+"\n";correctAnswer = Answer.toUpperCase();}String ask() {while (true) {String answer = JOptionPane.showInputDialog(question);answer =answer.toUpperCase(); }String ask() {while (true) {String answer = JOptionPane.showInputDialog(question);answer=answer.toUpperCase();boolean valid =…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY
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 Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
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
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY