Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started