Jump to content
Sign in to follow this  
DoseSociety

Key input help java

Recommended Posts

Im working on a game and everything was going as according to plan until i started handling the user input and for some reason it isnt being picked up even know i added a KeyAdapter to the jpanel. Does anyone have an idea what i did wrong.
Here's the engine for the game with the keyadapter

[code]/**
*
* @author ethan
*/
public class Engine extends JPanel implements ActionListener {

public enum Selection {

MAIN_MENU, CHARACTER_SELECTION, OPPONENT_SELECTION, ITEM_STORE, PAUSE, GAME, ONLINE_MATCH;
}


private Selection selection;
private NPC npc;
private NPC npc1;
private Player player;

public Engine() {
selection = Selection.GAME;
npc = new NPC(508, 108);
npc1 = new NPC(241, 300);
player = new Player();

addMouseListener(new MouseAdapter() {

@Override
public void mouseClicked(MouseEvent event) {
switch (selection) {
case MAIN_MENU:
break;
case CHARACTER_SELECTION:
break;
case OPPONENT_SELECTION:
break;
case ITEM_STORE:
break;
case PAUSE:
break;
case GAME:
System.out.println(event.getX() + " " + event.getY());
break;
case ONLINE_MATCH:
break;
}
}
});
addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {

}

@Override
public void keyReleased(KeyEvent event) {

}
});
Timer timer = new Timer(5, this);
timer.start();
}

public void drawFrame() {
JFrame frame = new JFrame("Fun Fighter");
frame.setSize(805, 620);
frame.setResizable(false);
frame.setDefaultCloseOperation(3);
frame.add(this);
frame.setVisible(true);
}

@Override
public void actionPerformed(ActionEvent actionEvent) {
switch (selection) {
case MAIN_MENU:
break;
case CHARACTER_SELECTION:
break;
case OPPONENT_SELECTION:
break;
case ITEM_STORE:
break;
case PAUSE:
break;
case GAME:
player.move();
break;
case ONLINE_MATCH:
break;
}
repaint();
}

@Override
public void paint(Graphics graphics) {
Graphics2D g2d = (Graphics2D) graphics;
switch (selection) {
case MAIN_MENU:
break;
case CHARACTER_SELECTION:
break;
case OPPONENT_SELECTION:
break;
case ITEM_STORE:
break;
case PAUSE:
break;
case GAME:
g2d.drawImage(new ImageIcon("cache/background.png").getImage(), 0, 0, this);
npc.draw(g2d);
npc1.draw(g2d);
player.draw(g2d);
break;
case ONLINE_MATCH:
break;
}
}
}[/code]

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×