Kura_kai
02-18-2005, 05:39 PM
I need help with a small simple program i am making for java all i need is to do a user interface with they use the arrows on the keyboard not the ones on the num pad on the right. Here is a table of what happens when what arrows get pushed down.
Left Arrow:x=x-1;
Right Arrow:x=x+1;
Up Arrow:y=y+1;
Down Arrow:y=y-1;
And the default is that x=0 and y=0 just a simple script is all that i am looking for.
Kura_kai
02-18-2005, 11:24 PM
Or if possible a way to get it so you input the commands and if it is correct it works.
Kura_kai
02-19-2005, 04:01 AM
.....umm....ok this is kind of redicoulus been about 12 hours no offence and stuf but usually i have some post something giving some help or a tutorial or something
Antoniohawk
02-19-2005, 09:26 PM
I wouldn't exactly consider it ridiculous as everyone here is not getting paid to help you out, added to the fact that most of them have full time jobs.
On the topic of your question, you're gonna need to check out something called Swing. Here's a link to Sun's website that can get you started and there's always google.
[http://java.sun.com/docs/books/tutorial/uiswing/14start/index.html]
On the topic of your question, you're gonna need to check out something called Swing.
+ AWT & the AWT Event model. IMO this falls into the realm of beginner questions for which I always recommend the free electronic book (or you can buy it on CD-ROM or paper) Thinking In Java, 3rd Edition (http://www.mindview.net/Books/TIJ/). It may be more than you're looking for, but it's probably what you need to avoid further confusion with the Java language.
Kura_kai
02-22-2005, 07:01 PM
Ok thanks for those links they will be of great use but i can't find what i am looking for. I saw a book somewhere that mentioned this. It listens to see if a key is pressed and than it does something. And there is a way to find out what key was pressed. Any help?
Sun Java Tutorial: How to Write a Key Listener (http://java.sun.com/docs/books/tutorial/uiswing/events/keylistener.html)
Interface KeyListener (http://java.sun.com/j2se/1.5.0/docs/api/java/awt/event/KeyListener.html), Class KeyEvent (http://java.sun.com/j2se/1.5.0/docs/api/java/awt/event/KeyEvent.html), Class KeyAdapter (http://java.sun.com/j2se/1.5.0/docs/api/java/awt/event/KeyAdapter.html)
Kura_kai
02-23-2005, 12:09 AM
Thanks. I just slimed it down to what i basically want now than I need help with fixing the bugs this proporly wont take long but here it is
import javax.swing.*;
import java.awt.event.*;
import java.awt.BorderLayout;
import java.awt.Dimension;
public class KeyEventDemo extends JPanel
implements KeyListener,
ActionListener {
JTextArea displayArea;
JTextField typingArea;
static final String newline = "\n";
public KeyEventDemo() {
super(new BorderLayout());
typingArea = new JTextField(0);
typingArea.addKeyListener(this);
displayArea = new JTextArea();
displayArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(displayArea);
scrollPane.setPreferredSize(new Dimension(375, 125));
add(typingArea, BorderLayout.PAGE_START);
add(scrollPane, BorderLayout.CENTER);
add(button, BorderLayout.PAGE_END);
}
/** Handle the key pressed event from the text field. */
public void keyPressed(KeyEvent e) {
}
}
That is all at the moment i believe it should do nothing if a key is pressed but it keeps coming up with errors any help or pointers?