Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello. I want to add KeyEvent / KeyListener to my code which will move my character left, right, upward and downward. If possible, can someone

Hello. I want to add KeyEvent / KeyListener to my code which will move my "character" left, right, upward and downward. If possible, can someone add a body,legs and arm (just shapes) to my character(mage/wizard). Here is the code im working on

import java.awt.Color; import java.awt.Graphics; import java.awt.Panel; import javax.swing.JFrame; import javax.swing.JOptionPane;

public class Mage extends Panel{ static String name =""; static String color = ""; public Mage(){ this.setBackground(Color.BLACK); } public void paint(Graphics g){ //head g.setColor(Color.WHITE); g.fillOval(125,150,200,200); //eyes g.setColor(Color.red); g.fillOval(160,200,50,50); g.fillOval(240,200,50,50); //hat g.setColor(Color.CYAN); g.fillRect(175,10,100,150); g.fillRect(134,150,180,20); //mouth g.setColor(Color.BLACK); g.fillOval(210,270,30,50); //body } public static void main(String[] args){ JFrame m = new JFrame(); Mage panel = new Mage(); m.add(panel); m.setSize(1000,720); m.setVisible(true); m.setLocationRelativeTo(null); m.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

More Books

Students also viewed these Databases questions

Question

4. How did Intermountain relate to the insurance community?

Answered: 1 week ago