Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Dec 2004
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Java Help-User Interface

    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.

  • #2
    Regular Coder
    Join Date
    Dec 2004
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Or if possible a way to get it so you input the commands and if it is correct it works.
    Last edited by Kura_kai; 02-18-2005 at 11:27 PM. Reason: Typo

  • #3
    Regular Coder
    Join Date
    Dec 2004
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts
    .....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

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts
    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/tutor...art/index.html]

  • #5
    cfc
    cfc is offline
    Regular Coder
    Join Date
    Dec 2004
    Location
    Keswick, Ontario
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Antoniohawk
    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. It may be more than you're looking for, but it's probably what you need to avoid further confusion with the Java language.

  • #6
    Regular Coder
    Join Date
    Dec 2004
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #7
    cfc
    cfc is offline
    Regular Coder
    Join Date
    Dec 2004
    Location
    Keswick, Ontario
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts

  • #8
    Regular Coder
    Join Date
    Dec 2004
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Code:
    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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •