Member Avatar

Hi, I've used keylisteners multiple times, but I am having trouble with this situation. I want the keylistener to recognize a series of characters. For example, if 'e' is typed, I want the program to listen for 'l', then 'e', etc. (spelling "elephant", if you wanted to know). It recognizes the first 'e', but does not recognize the 'l' or any different letter afterwards. I'm stumped... Any help is greatly appreciated. I've searched the internet for an answer, but I haven't found an answer (hense why I'm here). If you find an answer, feel free to just post the link …

Member Avatar
+0 forum 3
Member Avatar

hello, hello! im probably being really dumb again, but i can't get java to run keyPressed() when i press a key. do i need to initialize the keylistener somewhere? any input is appreciated!(even if it's not help) import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import javax.swing.JPanel; import javax.swing.Timer; public class GamePanel extends JPanel implements ActionListener, KeyListener{ Blocks blocks = new Blocks(); Player player = new Player(); public GamePanel(){ Timer tim = new Timer(50, this); tim.start(); setFocusable(true); setFocusTraversalKeysEnabled(false); } private void update(){ blocks.update(); player.update(); } public void paintComponent(Graphics g){ blocks.paint(g); player.paint(g); } public void actionPerformed(ActionEvent e){ update(); repaint(); …

Member Avatar
+0 forum 3
Member Avatar

Hello everyone on daniweb!:) I'm trying to make a programme which will move a picture to the sides when pressing the right or left arrowkeys. I did successfully put a picture in and I was able to change the side coordinates(called "side" in the programme) to make the picture move. However now I want it to be done with KeyListener. I have been trying to browse the internet for help but I havnt yet found anything which worked. One problem is that I dont know what to add the keylistener to(now its added to "img" because I dont know better). …

Member Avatar
+0 forum 3
Member Avatar

Hey. I am trying to make a "virus" that will not let the user exit the program even with pressing Command+Q (oh, ya, I have an Apple). Here is what I have so far: if (keylistener.getKeyCode()==81){ System.out.println("Works"); } I have the println just to see if it works (which it does), but is there a way to "kill" the request or have the computer not recognize the command key if pressed? Thanks in advance!

Member Avatar
+0 forum 2
Member Avatar

Trying to add a key keylistener to a program i am making but it wont work. cant find the reason :/ any help would be awesome:) Display.class [CODE]package com.mono.main; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JFrame; import javax.swing.JPanel; import com.mono.main.handler.Controller; import com.mono.main.handler.Game; import com.mono.main.handler.InputHandler; public class Display extends JPanel implements Runnable { private static final long serialVersionUID = 1L; public static final int WIDTH = 800; public static final int HEIGHT = 600; public static final String TITLE = "Minefront Pre-Alpha 0.01"; private boolean running = false; private Thread thread; private InputHandler input; private Dude d; private Game gamer; public Display(){ …

Member Avatar
+0 forum 7
Member Avatar

I'm trying to make it so when I press ESC, it RestoreScreen() but it doesn't work. Now I don't know whether it's my method RestoreScreen() or my listeners. This is my code: [code]import javax.swing.*; import java.awt.*; import java.awt.event.*; public class main extends JFrame implements MouseListener,KeyListener{ public void keyPressed(KeyEvent e) { int rsKey = e.getKeyCode(); if(rsKey == KeyEvent.VK_ESCAPE || rsKey == 27){ s.RestoreScreen(); } } public void keyReleased(KeyEvent e) { } public void keyTyped(KeyEvent e) { } public static void main(String[] args) { DisplayMode dm = new DisplayMode(800,600,16,DisplayMode.REFRESH_RATE_UNKNOWN); main m = new main(); m.run(dm); } private title s; private JTextField command; …

Member Avatar
+0 forum 4
Member Avatar

Why won't this work? I'm trying to make a ball appear and move along my screen but it's failing :'( . I'm :( and also trying to make it so when you press any key it restores the full screen but that's also failing. :'( Can anyone help? [CODE]import javax.swing.*; import java.awt.*; import java.awt.event.*; public class main extends JFrame implements MouseListener{ class keyl implements KeyListener{ @Override public void keyPressed(KeyEvent e) { s.RestoreScreen(); } @Override public void keyReleased(KeyEvent e) { s.RestoreScreen(); } @Override public void keyTyped(KeyEvent e) { s.RestoreScreen(); } } public static void main(String[] args) { DisplayMode dm = new …

Member Avatar
+0 forum 40

The End.