SlideShare a Scribd company logo
1 of 5
Download to read offline
Hi my question pretains to Java programing, What I am creating is a multi lab pacman type
game.
This part one covers movement. I basically need my code below to meet the labs requiremnts. IE
I need this game to allow two players to move and i think use a construtor to pass the movement
through the player classe.
Thanks for the help
included is some codes
import javax.swing.JFrame;
public class MainFrame {
public static void main(String[] args)
{
// create the frame
JFrame myFrame = new JFrame("Platformer");
// set up the close operation
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// create panel
MainPanel myPanel = new MainPanel();
// add panel
myFrame.getContentPane().add(myPanel);
// pack
myFrame.pack();
// set visibility to true
myFrame.setVisible(true);
}
}
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
public class MainPanel extends JPanel implements KeyListener{
int x = 0;
int y = 0;
ImageIcon myIcon = new ImageIcon("./src/TreasureChest.png");
public MainPanel()
{
setPreferredSize(new Dimension(1000,1000));
addKeyListener(this);
setFocusable(true);
}
public void paintComponent(Graphics page)
{
super.paintComponent(page);
page.drawImage(myIcon.getImage(), x, y, null);
}
@Override
public void keyPressed(KeyEvent arg0) {
int keyCode = arg0.getKeyCode();
if (keyCode == KeyEvent.VK_LEFT)
{
x -= 100;
}
else if (keyCode == KeyEvent.VK_RIGHT)
{
x += 100;
}
else if (keyCode == KeyEvent.VK_UP)
{
y -= 100;
}
else if (keyCode == KeyEvent.VK_DOWN)
{
y += 100;
}
repaint();
}
@Override
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub
}
This is the overall goal for the project for this part of the lab I basically just neeed to have two
player movemet across the Jpanel so I believe I just need to use a consturer to make two
instances of the player class that uses different movement
Solution
import javax.swing.JFrame;
public class MainFrame { public static void main(String[] args)
{
// create the frame JFrame myFrame = new JFrame("Platformer");
// set up the close operation myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// create panel
MainPanel myPanel = new MainPanel();
// add panel
myFrame.getContentPane().add(myPanel);
// pack
myFrame.pack();
// set visibility to true
myFrame.setVisible(true);
}
}
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
public class MainPanel extends JPanel implements KeyListener{
int x = 0;
int y = 0;
ImageIcon myIcon = new ImageIcon("./src/TreasureChest.png");
public MainPanel()
{
setPreferredSize(new Dimension(1000,1000));
addKeyListener(this);
setFocusable(true);
}
public void paintComponent(Graphics page)
{
super.paintComponent(page);
page.drawImage(myIcon.getImage(), x, y, null);
}
@Override
public void keyPressed(KeyEvent arg0) {
int keyCode = arg0.getKeyCode();
if (keyCode == KeyEvent.VK_LEFT)
{
x -= 100;
}
else if (keyCode == KeyEvent.VK_RIGHT)
{
x += 100;
}
else if (keyCode == KeyEvent.VK_UP)
{
y -= 100;
}
else if (keyCode == KeyEvent.VK_DOWN)
{
y += 100;
}
repaint();
}

More Related Content

Similar to Hi my question pretains to Java programing, What I am creating is a .pdf

Exercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera CymbronExercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera Cymbroncymbron
 
Joomla! Components - Uma visão geral
Joomla! Components - Uma visão geralJoomla! Components - Uma visão geral
Joomla! Components - Uma visão geralFábrica Livre
 
Working with the Calculator program Once imported run the.pdf
Working with the Calculator program Once imported  run the.pdfWorking with the Calculator program Once imported  run the.pdf
Working with the Calculator program Once imported run the.pdficonsystemsslm
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleThierry Wasylczenko
 
Chapter 11.2
Chapter 11.2Chapter 11.2
Chapter 11.2sotlsoc
 
شرح مقرر البرمجة 2 لغة جافا - الوحدة التاسعة
شرح مقرر البرمجة 2   لغة جافا - الوحدة التاسعةشرح مقرر البرمجة 2   لغة جافا - الوحدة التاسعة
شرح مقرر البرمجة 2 لغة جافا - الوحدة التاسعةجامعة القدس المفتوحة
 
codigomenu-1 (1).docx
codigomenu-1 (1).docxcodigomenu-1 (1).docx
codigomenu-1 (1).docxAnaLpez275
 
codigomenu-1.docx
codigomenu-1.docxcodigomenu-1.docx
codigomenu-1.docxAnaLpez275
 
I am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdfI am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdffashionfolionr
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingVisual Engineering
 
Grain final border one
Grain final border oneGrain final border one
Grain final border oneAshish Gupta
 
Matching Game In Java
Matching Game In JavaMatching Game In Java
Matching Game In Javacmkandemir
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeletonIram Ramrajkar
 

Similar to Hi my question pretains to Java programing, What I am creating is a .pdf (20)

SWING.pptx
SWING.pptxSWING.pptx
SWING.pptx
 
Maze
MazeMaze
Maze
 
SwingApplet.pptx
SwingApplet.pptxSwingApplet.pptx
SwingApplet.pptx
 
Exercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera CymbronExercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera Cymbron
 
Joomla! Components - Uma visão geral
Joomla! Components - Uma visão geralJoomla! Components - Uma visão geral
Joomla! Components - Uma visão geral
 
Working with the Calculator program Once imported run the.pdf
Working with the Calculator program Once imported  run the.pdfWorking with the Calculator program Once imported  run the.pdf
Working with the Calculator program Once imported run the.pdf
 
Start
StartStart
Start
 
Advance jquery-plugin
Advance jquery-pluginAdvance jquery-plugin
Advance jquery-plugin
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
Chapter 11.2
Chapter 11.2Chapter 11.2
Chapter 11.2
 
شرح مقرر البرمجة 2 لغة جافا - الوحدة التاسعة
شرح مقرر البرمجة 2   لغة جافا - الوحدة التاسعةشرح مقرر البرمجة 2   لغة جافا - الوحدة التاسعة
شرح مقرر البرمجة 2 لغة جافا - الوحدة التاسعة
 
codigomenu-1 (1).docx
codigomenu-1 (1).docxcodigomenu-1 (1).docx
codigomenu-1 (1).docx
 
codigomenu-1.docx
codigomenu-1.docxcodigomenu-1.docx
codigomenu-1.docx
 
I am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdfI am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdf
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
 
Grain final border one
Grain final border oneGrain final border one
Grain final border one
 
Matching Game In Java
Matching Game In JavaMatching Game In Java
Matching Game In Java
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeleton
 
Server1
Server1Server1
Server1
 
From Swing to JavaFX
From Swing to JavaFXFrom Swing to JavaFX
From Swing to JavaFX
 

More from eyeonsecuritysystems

For each step of DNA replication, predict the outcome if • concen.pdf
For each step of DNA replication, predict the outcome if • concen.pdfFor each step of DNA replication, predict the outcome if • concen.pdf
For each step of DNA replication, predict the outcome if • concen.pdfeyeonsecuritysystems
 
Explain why a virus cant infect every cell Explain why a viru.pdf
Explain why a virus cant infect every cell Explain why a viru.pdfExplain why a virus cant infect every cell Explain why a viru.pdf
Explain why a virus cant infect every cell Explain why a viru.pdfeyeonsecuritysystems
 
Explain advantages and disadvantages of designing an OS kernel in la.pdf
Explain advantages and disadvantages of designing an OS kernel in la.pdfExplain advantages and disadvantages of designing an OS kernel in la.pdf
Explain advantages and disadvantages of designing an OS kernel in la.pdfeyeonsecuritysystems
 
Explain three similarities and two diffrences in anaerobic and aerob.pdf
Explain three similarities and two diffrences in anaerobic and aerob.pdfExplain three similarities and two diffrences in anaerobic and aerob.pdf
Explain three similarities and two diffrences in anaerobic and aerob.pdfeyeonsecuritysystems
 
Exercise 7-8 Kickapoo Company uses an imprest petty cash system. The .pdf
Exercise 7-8 Kickapoo Company uses an imprest petty cash system. The .pdfExercise 7-8 Kickapoo Company uses an imprest petty cash system. The .pdf
Exercise 7-8 Kickapoo Company uses an imprest petty cash system. The .pdfeyeonsecuritysystems
 
Discussions Grades people Syllabus Modules Google Drive D Question 1 .pdf
Discussions Grades people Syllabus Modules Google Drive D Question 1 .pdfDiscussions Grades people Syllabus Modules Google Drive D Question 1 .pdf
Discussions Grades people Syllabus Modules Google Drive D Question 1 .pdfeyeonsecuritysystems
 
Discuss the range of interactions that occur between human beings an.pdf
Discuss the range of interactions that occur between human beings an.pdfDiscuss the range of interactions that occur between human beings an.pdf
Discuss the range of interactions that occur between human beings an.pdfeyeonsecuritysystems
 
Critique the customer contact model. What are its strengths and weak.pdf
Critique the customer contact model. What are its strengths and weak.pdfCritique the customer contact model. What are its strengths and weak.pdf
Critique the customer contact model. What are its strengths and weak.pdfeyeonsecuritysystems
 
Case Study Synlait Milk is an innovative dairy processing company th.pdf
Case Study Synlait Milk is an innovative dairy processing company th.pdfCase Study Synlait Milk is an innovative dairy processing company th.pdf
Case Study Synlait Milk is an innovative dairy processing company th.pdfeyeonsecuritysystems
 
An entity with two multivalued attributes will be mapped as how many.pdf
An entity with two multivalued attributes will be mapped as how many.pdfAn entity with two multivalued attributes will be mapped as how many.pdf
An entity with two multivalued attributes will be mapped as how many.pdfeyeonsecuritysystems
 
Assume you are the new CEO of the Delta Phi Corporation. When the Bo.pdf
Assume you are the new CEO of the Delta Phi Corporation. When the Bo.pdfAssume you are the new CEO of the Delta Phi Corporation. When the Bo.pdf
Assume you are the new CEO of the Delta Phi Corporation. When the Bo.pdfeyeonsecuritysystems
 
A manager typically spends the least amount of time Communicating Mo.pdf
A manager typically spends the least amount of time Communicating Mo.pdfA manager typically spends the least amount of time Communicating Mo.pdf
A manager typically spends the least amount of time Communicating Mo.pdfeyeonsecuritysystems
 
Write message.cpp and priorityq.cpp. The code in message.cpp and pri.pdf
Write message.cpp and priorityq.cpp. The code in message.cpp and pri.pdfWrite message.cpp and priorityq.cpp. The code in message.cpp and pri.pdf
Write message.cpp and priorityq.cpp. The code in message.cpp and pri.pdfeyeonsecuritysystems
 
Will a Pigovian tax always be equal to the marginal external cost of.pdf
Will a Pigovian tax always be equal to the marginal external cost of.pdfWill a Pigovian tax always be equal to the marginal external cost of.pdf
Will a Pigovian tax always be equal to the marginal external cost of.pdfeyeonsecuritysystems
 
Would you identify UTC’s approach to supply chain managemet as ce.pdf
Would you identify UTC’s approach to supply chain managemet as ce.pdfWould you identify UTC’s approach to supply chain managemet as ce.pdf
Would you identify UTC’s approach to supply chain managemet as ce.pdfeyeonsecuritysystems
 
White collar crimes are best defined as a wide variety of nonviolent.pdf
White collar crimes are best defined as a wide variety of nonviolent.pdfWhite collar crimes are best defined as a wide variety of nonviolent.pdf
White collar crimes are best defined as a wide variety of nonviolent.pdfeyeonsecuritysystems
 
Why do we diverge from the Rational Choice Paradigm when identifying.pdf
Why do we diverge from the Rational Choice Paradigm when identifying.pdfWhy do we diverge from the Rational Choice Paradigm when identifying.pdf
Why do we diverge from the Rational Choice Paradigm when identifying.pdfeyeonsecuritysystems
 
Why is lactose much more soluble in water than in ethanolSolu.pdf
Why is lactose much more soluble in water than in ethanolSolu.pdfWhy is lactose much more soluble in water than in ethanolSolu.pdf
Why is lactose much more soluble in water than in ethanolSolu.pdfeyeonsecuritysystems
 
Which of the following is a technology that takes an Internet sig.pdf
Which of the following is a technology that takes an Internet sig.pdfWhich of the following is a technology that takes an Internet sig.pdf
Which of the following is a technology that takes an Internet sig.pdfeyeonsecuritysystems
 
What aspect of Ethernet can be a problem for security What mechanis.pdf
What aspect of Ethernet can be a problem for security What mechanis.pdfWhat aspect of Ethernet can be a problem for security What mechanis.pdf
What aspect of Ethernet can be a problem for security What mechanis.pdfeyeonsecuritysystems
 

More from eyeonsecuritysystems (20)

For each step of DNA replication, predict the outcome if • concen.pdf
For each step of DNA replication, predict the outcome if • concen.pdfFor each step of DNA replication, predict the outcome if • concen.pdf
For each step of DNA replication, predict the outcome if • concen.pdf
 
Explain why a virus cant infect every cell Explain why a viru.pdf
Explain why a virus cant infect every cell Explain why a viru.pdfExplain why a virus cant infect every cell Explain why a viru.pdf
Explain why a virus cant infect every cell Explain why a viru.pdf
 
Explain advantages and disadvantages of designing an OS kernel in la.pdf
Explain advantages and disadvantages of designing an OS kernel in la.pdfExplain advantages and disadvantages of designing an OS kernel in la.pdf
Explain advantages and disadvantages of designing an OS kernel in la.pdf
 
Explain three similarities and two diffrences in anaerobic and aerob.pdf
Explain three similarities and two diffrences in anaerobic and aerob.pdfExplain three similarities and two diffrences in anaerobic and aerob.pdf
Explain three similarities and two diffrences in anaerobic and aerob.pdf
 
Exercise 7-8 Kickapoo Company uses an imprest petty cash system. The .pdf
Exercise 7-8 Kickapoo Company uses an imprest petty cash system. The .pdfExercise 7-8 Kickapoo Company uses an imprest petty cash system. The .pdf
Exercise 7-8 Kickapoo Company uses an imprest petty cash system. The .pdf
 
Discussions Grades people Syllabus Modules Google Drive D Question 1 .pdf
Discussions Grades people Syllabus Modules Google Drive D Question 1 .pdfDiscussions Grades people Syllabus Modules Google Drive D Question 1 .pdf
Discussions Grades people Syllabus Modules Google Drive D Question 1 .pdf
 
Discuss the range of interactions that occur between human beings an.pdf
Discuss the range of interactions that occur between human beings an.pdfDiscuss the range of interactions that occur between human beings an.pdf
Discuss the range of interactions that occur between human beings an.pdf
 
Critique the customer contact model. What are its strengths and weak.pdf
Critique the customer contact model. What are its strengths and weak.pdfCritique the customer contact model. What are its strengths and weak.pdf
Critique the customer contact model. What are its strengths and weak.pdf
 
Case Study Synlait Milk is an innovative dairy processing company th.pdf
Case Study Synlait Milk is an innovative dairy processing company th.pdfCase Study Synlait Milk is an innovative dairy processing company th.pdf
Case Study Synlait Milk is an innovative dairy processing company th.pdf
 
An entity with two multivalued attributes will be mapped as how many.pdf
An entity with two multivalued attributes will be mapped as how many.pdfAn entity with two multivalued attributes will be mapped as how many.pdf
An entity with two multivalued attributes will be mapped as how many.pdf
 
Assume you are the new CEO of the Delta Phi Corporation. When the Bo.pdf
Assume you are the new CEO of the Delta Phi Corporation. When the Bo.pdfAssume you are the new CEO of the Delta Phi Corporation. When the Bo.pdf
Assume you are the new CEO of the Delta Phi Corporation. When the Bo.pdf
 
A manager typically spends the least amount of time Communicating Mo.pdf
A manager typically spends the least amount of time Communicating Mo.pdfA manager typically spends the least amount of time Communicating Mo.pdf
A manager typically spends the least amount of time Communicating Mo.pdf
 
Write message.cpp and priorityq.cpp. The code in message.cpp and pri.pdf
Write message.cpp and priorityq.cpp. The code in message.cpp and pri.pdfWrite message.cpp and priorityq.cpp. The code in message.cpp and pri.pdf
Write message.cpp and priorityq.cpp. The code in message.cpp and pri.pdf
 
Will a Pigovian tax always be equal to the marginal external cost of.pdf
Will a Pigovian tax always be equal to the marginal external cost of.pdfWill a Pigovian tax always be equal to the marginal external cost of.pdf
Will a Pigovian tax always be equal to the marginal external cost of.pdf
 
Would you identify UTC’s approach to supply chain managemet as ce.pdf
Would you identify UTC’s approach to supply chain managemet as ce.pdfWould you identify UTC’s approach to supply chain managemet as ce.pdf
Would you identify UTC’s approach to supply chain managemet as ce.pdf
 
White collar crimes are best defined as a wide variety of nonviolent.pdf
White collar crimes are best defined as a wide variety of nonviolent.pdfWhite collar crimes are best defined as a wide variety of nonviolent.pdf
White collar crimes are best defined as a wide variety of nonviolent.pdf
 
Why do we diverge from the Rational Choice Paradigm when identifying.pdf
Why do we diverge from the Rational Choice Paradigm when identifying.pdfWhy do we diverge from the Rational Choice Paradigm when identifying.pdf
Why do we diverge from the Rational Choice Paradigm when identifying.pdf
 
Why is lactose much more soluble in water than in ethanolSolu.pdf
Why is lactose much more soluble in water than in ethanolSolu.pdfWhy is lactose much more soluble in water than in ethanolSolu.pdf
Why is lactose much more soluble in water than in ethanolSolu.pdf
 
Which of the following is a technology that takes an Internet sig.pdf
Which of the following is a technology that takes an Internet sig.pdfWhich of the following is a technology that takes an Internet sig.pdf
Which of the following is a technology that takes an Internet sig.pdf
 
What aspect of Ethernet can be a problem for security What mechanis.pdf
What aspect of Ethernet can be a problem for security What mechanis.pdfWhat aspect of Ethernet can be a problem for security What mechanis.pdf
What aspect of Ethernet can be a problem for security What mechanis.pdf
 

Recently uploaded

Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 

Recently uploaded (20)

Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 

Hi my question pretains to Java programing, What I am creating is a .pdf

  • 1. Hi my question pretains to Java programing, What I am creating is a multi lab pacman type game. This part one covers movement. I basically need my code below to meet the labs requiremnts. IE I need this game to allow two players to move and i think use a construtor to pass the movement through the player classe. Thanks for the help included is some codes import javax.swing.JFrame; public class MainFrame { public static void main(String[] args) { // create the frame JFrame myFrame = new JFrame("Platformer"); // set up the close operation myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // create panel MainPanel myPanel = new MainPanel(); // add panel myFrame.getContentPane().add(myPanel); // pack myFrame.pack(); // set visibility to true myFrame.setVisible(true); } } import java.awt.Dimension; import java.awt.Graphics; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import javax.swing.ImageIcon; import javax.swing.JPanel; public class MainPanel extends JPanel implements KeyListener{ int x = 0; int y = 0;
  • 2. ImageIcon myIcon = new ImageIcon("./src/TreasureChest.png"); public MainPanel() { setPreferredSize(new Dimension(1000,1000)); addKeyListener(this); setFocusable(true); } public void paintComponent(Graphics page) { super.paintComponent(page); page.drawImage(myIcon.getImage(), x, y, null); } @Override public void keyPressed(KeyEvent arg0) { int keyCode = arg0.getKeyCode(); if (keyCode == KeyEvent.VK_LEFT) { x -= 100; } else if (keyCode == KeyEvent.VK_RIGHT) { x += 100; } else if (keyCode == KeyEvent.VK_UP) { y -= 100; } else if (keyCode == KeyEvent.VK_DOWN) { y += 100; } repaint(); }
  • 3. @Override public void keyReleased(KeyEvent arg0) { // TODO Auto-generated method stub } @Override public void keyTyped(KeyEvent arg0) { // TODO Auto-generated method stub } This is the overall goal for the project for this part of the lab I basically just neeed to have two player movemet across the Jpanel so I believe I just need to use a consturer to make two instances of the player class that uses different movement Solution import javax.swing.JFrame; public class MainFrame { public static void main(String[] args) { // create the frame JFrame myFrame = new JFrame("Platformer"); // set up the close operation myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // create panel MainPanel myPanel = new MainPanel(); // add panel myFrame.getContentPane().add(myPanel); // pack myFrame.pack(); // set visibility to true myFrame.setVisible(true); } } import java.awt.Dimension; import java.awt.Graphics; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import javax.swing.ImageIcon;
  • 4. import javax.swing.JPanel; public class MainPanel extends JPanel implements KeyListener{ int x = 0; int y = 0; ImageIcon myIcon = new ImageIcon("./src/TreasureChest.png"); public MainPanel() { setPreferredSize(new Dimension(1000,1000)); addKeyListener(this); setFocusable(true); } public void paintComponent(Graphics page) { super.paintComponent(page); page.drawImage(myIcon.getImage(), x, y, null); } @Override public void keyPressed(KeyEvent arg0) { int keyCode = arg0.getKeyCode(); if (keyCode == KeyEvent.VK_LEFT) { x -= 100; } else if (keyCode == KeyEvent.VK_RIGHT) { x += 100; } else if (keyCode == KeyEvent.VK_UP) { y -= 100; } else if (keyCode == KeyEvent.VK_DOWN) { y += 100;