Help for a labyrinth program

hello everyone!
i need some help for my program, i've just begun java and i'm creating a labyrinth program for a school project.
it's far from being finished, but my main problem right now is the KeyListener....
i'd like to create a new Labyrinthe class when i use the arrow keys to make sure it works.
please help me and correct me, here's my program:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Labyrinthe extends JFrame implements MouseListener, KeyListener{
     public static void main(String args[]) {
        new Labyrinthe();
     JPanel p1 = new JPanel();
     JPanel p2 = new JPanel();
     JPanel p3 = new JPanel();
     JPanel p4 = new JPanel();
     JButton sauv = new JButton ("sauvegarder");
     JButton q = new JButton("quitter");
     JButton newW = new JButton("nouveau");
     JButton closeW = new JButton("fermer");
     JButton dirh = new JButton("haut");
     JButton dirb = new JButton("bas");
     JButton dird = new JButton("droite");
     JButton dirg = new JButton("gauche");
     public Labyrinthe() {
        setLayout(new BorderLayout());
        Label l = new Label("Labyrinthe");
        Label l2 = new Label("Options");
        Label l3 = new Label("Directions");
        add(p1,BorderLayout.NORTH);
        add(p2,BorderLayout.SOUTH);
        add(p3,BorderLayout.WEST);
        add(p4,BorderLayout.CENTER);
        p1.add(l2);
        p1.add(q); p1.add(newW); p1.add(closeW); p1.add(sauv);
        p2.add(l3);
        p2.add(dirh);p2.add(dirb);p2.add(dird);p2.add(dirg);
        p3.add(l);
        p4.setBackground(Color.cyan);
        setTitle("Labyrinthe");
        setSize(400,400);
        setVisible(true);
        sauv.addMouseListener(this);
        q.addMouseListener(this);
        newW.addMouseListener(this);
        closeW.addMouseListener(this);
        dirh.addMouseListener(this);
          dirb.addMouseListener(this);
          dird.addMouseListener(this);
          dirg.addMouseListener(this);
          addKeyListener(this);
          addWindowListener(new WindowAdapter(){
               public void windowClosing(WindowEvent evt){
                    System.exit(0);
     public void mouseClicked(MouseEvent e) {
        Object s = e.getSource();
        if(s instanceof JButton) {
                if((JButton)s == q) // quit
                        System.exit(0);
                if((JButton)s == newW) // nouveau
                        new Labyrinthe();
                if((JButton)s == closeW) // fermer
                        this.dispose();
                if((JButton)s == dirh)
                     new Labyrinthe();
                if((JButton)s == dirb)
                     new Labyrinthe();
                if((JButton)s == dirg)
                     new Labyrinthe();
                if((JButton)s == dird)
                     new Labyrinthe();
     public void mouseEntered(MouseEvent e) {
     public void mouseExited(MouseEvent e) {
     public void mousePressed(MouseEvent e) {
     public void mouseReleased(MouseEvent e) {
     public void keyPressed (KeyEvent k) {
          if (k.getKeyCode() == KeyEvent.VK_UP){
               new Labyrinthe();
          if (k.getKeyCode() == KeyEvent.VK_DOWN){
               new Labyrinthe();
          if (k.getKeyCode() == KeyEvent.VK_LEFT){
               new Labyrinthe();
          if (k.getKeyCode() == KeyEvent.VK_RIGHT){
               new Labyrinthe();
     public void keyReleased (KeyEvent k) {
     public void keyTyped (KeyEvent k) {
}thx again for your help

You only get key events if you have input focus; as you have it, one of the buttons has focus.
Either
- add mouse and key listener to p4, and have p4 request the focus on initialisation or when you click on it,
Or
- create AbstractActions for your movement commands which call methods which carry out the commands, and set the keyboard shortcut for them to the approriate keys.
Pete

Similar Messages

  • Need help for writing extract program

    hi
    i need help for writing extract program to retriew data from legacy system.
    i already developed bdc programs for me31k and me21.
    my requirement is to write extract program s for those t.codes.
    to retriew data from legacy system and stored in flat file.

    i need help with a java program. it is a program that allows the user to enter a student's GPA, number of extracurricular activities, and number of service activities. The user can not enter a gpa above 4.0 or below 0. The user can not enter a negative number for the number of both activities. If the student meets the following criteria: 1) GPA of 3.8 or above and at least one extracurricular activity and one service activity, 2) GPA below 3.8 but at least 3.4 and a total of at least three extracurricular and service activities, 3) GPA below 3.4 but at least 3.0 and at least two extracurricular activities and three service activities, the message "Scholarship candidate" should display. If the student does not meet the criteria above, then the message"not a candidate" should display. Can you help me, please?
    You haven't posted ANY 'java program' for us to help with.
    The forum is NOT a coding service. It is to help you with YOUR code.
    Post the code you have written and SHOW us (don't just tell us) how you compile it and execute it and the results you get. Then we can help you with any problems you are are having.
    If you need help understanding just what the program should be doing you need to ask your instructor to clarify the assignment.

  • Help for my dumb program

    Dear Sir/Madam:
    I am a lazy one.....So I post my dumb program here and hope .....
    public class AssertionExp {
    public static void main(String[] args){
    final double height = 22.5;
    final double weight = 11.0;
    assert(height < 0): AssertionExp.ErrorMessage(height,weight); //<== this line gets problem!!!
    System.out.println("The program ends....");
    public void ErrorMessage(double he, double we){
    double weight = we;
    double height = he;
    System.out.println("weight = " + weight + ", height =" + height);
    }

    Dear Sir/Madam:
    I just learn Java no more than three months....
    so.....
    the netbeans compiler shows that....
    Compiling 1 source file to C:\.....\build\classes
    C:\.....\src\AssertionExp.java:11: non-static method ErrorMessage(double,double) cannot be referenced from a static context
    assert(height < 0): AssertionExp.ErrorMessage(height,weight);
    C:\......\src\AssertionExp.java:11: 'void' type not allowed here
    assert(height < 0): AssertionExp.ErrorMessage(height,weight);
    2 errors
    I have no idea ablout the problem....
    Please help for the trouble shooting.....
    Thank you so much...

  • Java Help For Apple Widget Program

    I'm working on a Apple Widget and I have a question for the JS part of it.
    I want multiple elements to fade out when the widget loads up, I can get one element to fade out, but how do I get multiple elements to fade out on the same onLoad event.
    Here is the code to get one item to fade out.
    function elementHide(event)
    // Values you provide
    var itemToFadeOut = document.getElementById("img"); // replace with name of element to fade
    // Fading code
    var fadeHandler = function(a, c, s, f){ itemToFadeOut.style.opacity = c; };
    new AppleAnimator(5, 13, 1.0, 0.0, fadeHandler).start();
    } Thanks for any help given.

    Avi,
    Dude, this is java forum, and Java is NOT javascript... so try a [javascript forum|http://www.google.com/search?q=javascript+forum&hl=en&sourceid=gd&rls=GGLD,GGLD:2008-06,GGLD:en&aq=t].
    You just might get an answer here, but the majority of regulars refuse to address javascript questions here, as a matter of principle... even though the same people are happy to answer the same questions on the javascript forums. Go figure.
    Cheers. Keith.

  • Need help for encoder count program !!!!!!!!!

    I am a new labview user.
    And i am trying to complete a project for my course.
    For a quick background on what I am working with, I am using a NI PCI-73566-Axis Stepper/Servo Motion Controller for PCI, NI UMI-7764 Series, NI USB-6009 and a IDEC SC1B Rotary Encoder.
    I am try to design a encoder count program and a new program to convert the encoder signal to RPM.
    But I just don't know where should I start? How can I get the same block diagram like P11 in the attach file?
    Please check more detail from the attach file.
    Attachments:
    P11.jpg ‏127 KB
    P8.jpg ‏149 KB
    P15.jpg ‏141 KB

    Hello,
    The two objects on the block diagram are DAQ Assistants and can be found under Functions»Measurement I/O»NI-DAQmx. From what I can gather, this is acquirign signals that you should have connected to the USB-6009.
    -Zach
    Certified LabVIEW Developer

  • HELP for Compile java programe !

    Hello All,
    i want to make java programe by which i can compile java programes
    and when i compile java programe from my programe then
    i shoul get compiled status means programe compile successfuly
    or not compile.
    if any example i m thanksfull.
    onlyforjava.

    how about if compile fail?
    the process obj seems return value 0 as it run successful.
    I haven't try this, but I have experienced the process obj returns 0 if the executed command has some routine to handle error cases, in which, error will not halt the system.
    So, I recommand the following scenario.
    1. let say, if your java is test.java. check the existence of file test.class.
    If, it exists, get its modified time.
    2. compile the java code with
    Procress p = Runtime.exec(new String[]{"javac", "test.java"});
    3. get the error string if any.
    InputStream in = new BufferedInputStream(p.getInputStream());int read;while ((read = in.read()) != -1){  System.out.println((char)read);}
    4. handle error with the exitValue
    if (p.exitValue() != 0){  System.out.println("warning.");}
    5. check again the file test.class if it is a newly created file.
    6. if it is newly created, compile success. Else, failed.

  • How to display Help for the message in our program

    Hi Experts,
    Do any one know how to display the HELP for the Message in our ABAP program? Just like the user click the Long Text button in SE91.Do we have any function modules or Class method to do that? Thanks in advance.
    Joe

    Hi Joe,
    While creating a message class in se93, theres a button (documentation) on the application tool bar. Click on that and you will be lead to a text editor where you can fill in the necessary documentation for the message you have created.

  • F4 help for the screen fields in module pool program

    Hi All,
      I have a requirement that, i want to provide F4 help for the 2 fields in module pool program. the fields are document number and fiscal year from rbkp table.
    i could provide search help for two fields.
    but how to select matching fiscal year for that document number.
    problem: i am getting fiscal year as first four digits of document number.
    please help me to solve this problem.
    Thanks & Regards,
    Namratha.V

    Hi,
       If your requirement is after selecting the document no from f4 help then the corresponding year should be updated in the document year field then use FM --> DYNP_VALUES_UPDATE
    In  this function module pass the screen no program & field for which u want to update value

  • Assign search help for a screen field in standard program?

    Hi All,
    Is there any other way to assign search help to a standard SAP screen field? (to be precise i want to assign search help to Recipient field in table control of components tab in transaction IW32/IW31)
    I know we can do this by assigning search help through screen painter (by changing standard program, which is my last option).
    Any advice/help will be greatly appreciated.

    Hi,
    I think you will find solution in below <b>threads</b>:
    Re: Search Help for standard field
    How to assign a search help
    Search help for Standard SAP field
    <b>Reward if helpful</b>
    Rgds,

  • I want parameters with f4 help for program names in value request

    I want parameters with f4 help for program names in value request
    points will be awarded if  useful

    lv_name1 TYPE name1,        "Vendor Name
    CALL FUNCTION 'POPUP_TO_SEARCH_VALUE'
        EXPORTING
          textline1   = 'Vendor Name'(f09)
          titel       = 'Enter'(f17)
          valuelength = 35
        IMPORTING
          value       = lv_name1.
    try this out ..

  • Freely Programed Help for select-option field

    Hi,
    how can i set freely programmed help for select option field, i mean while adding selection field what are the parameters that are important for freely programmed help.
    i have implemented iwd_value_help in one component comp1 and declared the usage of comp1 in comp2 where i actually defined the usage of select-option component.
    i used parameter   i_value_help_type = if_wd_value_help_handler=>co_prefix_appldev while adding selection field, however when i presss F4 icon, the following message is coming
    View WD_VALUE_HELP does not exist within the component WDR_SELECT_OPTIONS
    Please suggest where i am doing wrong??
    Edited by: kranthi kumar on Dec 29, 2010 6:19 PM

    >
    kranthi kumar wrote:
    > Hi,
    >
    > how can i set freely programmed help for select option field, i mean while adding selection field what are the parameters that are important for freely programmed help.
    >
    > i have implemented iwd_value_help in one component comp1 and declared the usage of comp1 in comp2 where i actually defined the usage of select-option component.
    >
    > i used parameter   i_value_help_type = if_wd_value_help_handler=>co_prefix_appldev while adding selection field, however when i presss F4 icon, the following message is coming
    >
    > View WD_VALUE_HELP does not exist within the component WDR_SELECT_OPTIONS
    >
    > Please suggest where i am doing wrong??
    >
    > Edited by: kranthi kumar on Dec 29, 2010 6:19 PM
    Hi Kranthi,
    Please help me to understand your design.
    Why would you like to create a Freely programmed value help for select-option?. why not use wdr_select_option directly ?

  • Help regarding with a program that calculates change for a cashier.

    I am seeking help for a java script or program that can answer my problem:
    Write a program that calculates change for a cashier. The program requests the cost of the item. The user then types in the cost. The program then outputs the cost of the item including the sales tax (use 6% as the sales tax value). The program next request and recieves the amount tendered by the customer. Finally, the program outputs a summary of all figures, including the amount of change due to the customer. (change . java)
    change . java has the following attributes and methods:
    double costs; doublegetCosts ( ) void setCost (double x)
    double tax; doublegetTax ( ) void setTax (double x)
    double payment; doublegetPayment ( ) void setpayment (double x)
    *rite another program that will have an instance of change . java. Call the file as cashier.java
    *Public Cashier {
    public void static main (string27argc
    change x ;
    x = new change ( ) ;
    * cashier . java will use the attributes and methods stated on change java via the instance of change inside cashier.
    Please I have no idea for java, I am student who really needs help on this. If anyone knows how to do this please reply to this topic!
    Thank you

    the correct way to get help in forums like this is to post
    the specific problem you have, along with what you have tried
    and details of the output you expect Vs the output you get.
    simply posting the assignment makes it look like just another
    "do my homework for me" plea - even though it may not be.

  • F4 help for one field in modulepool program..(Possible values)

    Hello Experts,
    I have 3 fields in my module pool screen.
    PLANT, MATERIALNO AND STORAGELOCATION.
    BASED ON PLANT AND MATERIAL I NEED TO PROVIDE F4 HELP FOR STORAGE LOCATION(LGORT).
    How can i write the code in PROCESS ON VALUE REQUEST ..
    AND WHICH FUNCTION MODULE SHOULD BE USED.
    Please can anybody send me the code asap.
    I will give u full points if ur code matches my requirement.

    Hi Raja,
               i will send a sample code for ur problem check in once..In that code i explicitly hardcoded the values for serchhelp.Instead of that we have to use select statement based on ur condition and place them in internal table ok.
    FUNCTION MODULE:
    F4IF_INT_TABLE_VALUE_REQUEST.
    CODE:
    *& Report  YSEARCHHELP                                                 *
    *& DEVELOPER   : KIRAN KUMAR.G.A                                       *
    *& PURPOSE     : DEMO ON SEARCH HELP                                   *
    *& CREATION DT : 27/12/2007                                            *
    *& REQUEST     : ERPK900035                                            *
    REPORT  YSEARCHHELP.
    INTERNAL TABLE FOR STORING NAMES IN SELECTION LIST
    data: begin of t_itab occurs 0,
            name(10) type c,
          end of t_itab.
    *FIELDNAME AND TAB NAME FOR THE SELECTION
    DATA :field_tab LIKE dfies  OCCURS 0 WITH HEADER LINE.
    *THE TABLE FOR RETURNING THE NAME OF THE SELECTED ITEM
    DATA : return_tab LIKE ddshretval OCCURS 0 WITH HEADER LINE.
    *START THE SELECTION SCREEN BLOCK
    selection-screen begin of block ss1 with frame.
    parameters: p_name1(10) type c.
    selection-screen end of block ss1.
    *& F4 Help for p_name1                                                 *
    at selection-screen on value-request for p_name1.
    *CLEAR ALL EXISTING DATA
    *TO BE DONE EVERYTIME F4 HELP IS REQUESTED
    REFRESH t_itab.
    REFRESH field_tab.
      field_tab-fieldname = 'ERNAM'.
      field_tab-tabname = 'VBAK'.
    APPEND field_tab.
    t_itab-name = 'Andrews'.
    append t_itab.
    t_itab-name = 'Jennie'.
    append t_itab.
    CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
      EXPORTING
      DDIC_STRUCTURE         = ' '
        retfield               = field_tab-fieldname
      PVALKEY                = ' '
      DYNPPROG               = ' '
      DYNPNR                 = ' '
      DYNPROFIELD            = ' '
      STEPL                  = 0
        WINDOW_TITLE           = 'Select name'
      VALUE                  = ' '
      VALUE_ORG              = 'C'
      MULTIPLE_CHOICE        = ' '
      DISPLAY                = ' '
      CALLBACK_PROGRAM       = ' '
      CALLBACK_FORM          = ' '
      MARK_TAB               =
    IMPORTING
      USER_RESET             =
      tables
       value_tab              = t_itab
       FIELD_TAB              = field_tab
       RETURN_TAB             = return_tab
      DYNPFLD_MAPPING        =
    EXCEPTIONS
       PARAMETER_ERROR        = 1
       NO_VALUES_FOUND        = 2
       OTHERS                 = 3
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    else.
    p_name1 = return_tab-fieldval.
    ENDIF.
    Award points if helpful.
    Kiran Kumar.G
                    Have a Nice Day..

  • Need to restrict values in F4 help for Batch Characteristic

    Hi,
    I need to restrict values in F4 Help for a batch characteristic based on values entered for another characteristic. I could not find any BADI or Exit for this purpose. There is a BADI CACL_VALUE which is triggered after an entry is selected from dropdown list but nothing when we press F4. I thought of using Object Dependency but I need to write a programming logic for the requirement. Please let me know if there is any way to write program in Object Dependency or any other way for this requirement.
    Regards,
    Nikhil

    Hi nikhil simha,
    first of all, find out which search help is called.
    [Hierarchy of the Search Help Call|http://help.sap.com/saphelp_nw70/helpdata/en/0b/32e9b798da11d295b800a0c929b3c3/frameset.htm]
    may help you.
    If you know the search help, you may enhance it, but first of all you should check the where-used-list and make sure that the search help shows the requested behavior only in the context where you want it to.
    If it is your own program, you may be better off to create your own search help and define the triggering fields as search help interface input fields. Then you can use the values to filter results.
    Regards
    Clemens

  • Search Help for Vendor Feild not getting populated in the Screen Element

    Hi Everyone,
    In transaction Miro, I get a POP-UP for Invoicing Party i.e. Vendor and Users required a custom search help.
    The Search help for Vendor(LIFNR) is KRED_C and i appended a Z search help under this.
    Now that the search help exists and I can drill down the values too but when i select/choose any value,  that value is not getting populated in Screen feild.
    is there any validation I need to do for this.
    Please suggest me... I checked SDN there are many things but i couldn't figure out wat i need to do and where I need to modify.
    Regards,
    Raj

    Dear Hema,
    Could you please tell me how many internal tables you are using to store the data for display.
    I observerd that you have lt_stock and lt_mat2 declared in the part of the program
    >DATA: lv_stock TYPE lty_stock.
    >DATA: ltmat2 TYPE TABLE OF lty_mat.
    you have displayed above, however you are also using ls_stock and lv_stock .
    >IF p_ztotal = ' '. "line
    >WRITE 18 ls_stock-matnr.
    >WRITE 38 lv_stock-strgr.
    >
    >ELSEIF ztotal = 'S'.                             "subtotal
        >WRITE: 15 ls_stock-nrmit.
        >WRITE 32 lv_stock-dispo.                    
        >WRITE 43 lv_stock-fevor.                      
      >ELSE.                                            "total
        >WRITE: 15 'TOTAL'(016), ls_stock-prgrp.
    >
      >ENDIF.
    Are those for displaying some other information?
    Also the problem of display you are facing can also be because there are no records to be displayed which satisfies the selection criteria.
    Best Regards,
    Rajesh.
    Please reward points if found helpful.

Maybe you are looking for

  • Error code -36

    Hi there, I'm encountering the following problem when attempting to trash or move files from a drive in an external FW800 enclosure: The Finder cannot complete the operation because some data in "folder name" could not be read or written. (Error code

  • Help!! Unable to launch Outlook Express - Error says 'end of file reached'

    I double clicked on my icon to launch my email and got this message. I had Outlook Express 5.02 Tried rebooting twice. Backed up 5.02 on simple drive, then downloaded OE 5.06. Getting the same message... Unable to launch, end of file reached. anyone

  • Mounting /tmp as a filesystem on Solaris 10?

    Hi, Does anyone know if it's possible to mount /tmp as a filesystem in Solaris 10? My server is running Veritas Volume Manager 5.0 and the boot drive is encapsulated. After I change vfstab to mount /tmp as a standard filesystem, the server goes into

  • Is there a way to allow setting of "Due Date for All Tasks" to current date in OOB Workflow

    Is there a way to allow setting of "Due Date for All Tasks" to current date in OOB Workflow I need to set it today because there are tasks that is needed to be completed on the same day. Is there a way without modifying the page/form. like a configur

  • Weird problem with tabs bar

    So I just installed the new Safari 4 on my iMac after seeing it on my Dad's Macbook. How come his tab bar automatically show's up under the bookmarks bar and mine doesn't? He didn't change any settings or anything, that is just the way his looks afte