Question

Hey guys,

One question!
How do people import weird libraries? I mean.... like in Java, I can compile some of the coding that I copy from Internet as the libraries are not found.... Does that means that there is some kinda programmer defined library?

For example:
import com.ibm.as400.access.*;
import com.urbancode.lib.registry.RegistryEntry;
import java.rmi.*;

And.... lots more!! What's that?? How do we define that? Can anyone explain to me? Do we need to store something so that we can call the library?


Oh yes....another question.....
How to make KeyListener for the "down", "up", "left" & "right" button??? I am creating a game but.... can't find a way to do the keylistener for that...
I try using:

char c=e.getKeyChar();

And.... it only works for the alphanumeric and numeric.... And... I also tried using VK_DOWN.... but it says that variable not found.... Mmm... that's weird!
So.... anyone know how???

Comments

  • I might be able to answer the first question for ya. Those "libraries" are actually websites and their directories. ex:com.ibm.as400.access.* is really saying the current directory contains a directory called com, com contains a directory called ibm, ibm contains a directory called called as400, as400 contains a directory called access, access contains all the classes needed for the application that you copied. Anyways hope that helps. The second question is beyond me I'm still learning.
    shaneone1
    : Hey guys,
    :
    : One question!
    : How do people import weird libraries? I mean.... like in Java, I can compile some of the coding that I copy from Internet as the libraries are not found.... Does that means that there is some kinda programmer defined library?
    :
    : For example:
    : import com.ibm.as400.access.*;
    : import com.urbancode.lib.registry.RegistryEntry;
    : import java.rmi.*;
    :
    : And.... lots more!! What's that?? How do we define that? Can anyone explain to me? Do we need to store something so that we can call the library?
    :
    :
    : Oh yes....another question.....
    : How to make KeyListener for the "down", "up", "left" & "right" button??? I am creating a game but.... can't find a way to do the keylistener for that...
    : I try using:
    :
    : char c=e.getKeyChar();
    :
    : And.... it only works for the alphanumeric and numeric.... And... I also tried using VK_DOWN.... but it says that variable not found.... Mmm... that's weird!
    : So.... anyone know how???
    :

  • Second question :
    Did you tried ALL constants in KeyEvent ?
    [code]From KeyEvent documentation
    static int VK_KP_DOWN
    Constant for the numeric keypad down arrow key.
    static int VK_KP_LEFT
    Constant for the numeric keypad left arrow key.
    static int VK_KP_RIGHT
    Constant for the numeric keypad right arrow key.
    static int VK_KP_UP
    Constant for the numeric keypad up arrow key.
    [/code]

    First question :
    You can find some free API (java.sun.com), but you can also buy some.
    Usually, sun free API are called java.xxx.*.. and other com.xxx.*...
    As soon as you download an API, in .jar or .class format, you have tell at JVM where to find them. Update your classpath environnement variable and then you can write import com.*


    [size=4][red](v)[/red][/size]

  • : I might be able to answer the first question for ya. Those "libraries" are actually websites and their directories. ex:com.ibm.as400.access.* is really saying the current directory contains a directory called com, com contains a directory called ibm, ibm contains a directory called called as400, as400 contains a directory called access, access contains all the classes needed for the application that you copied. Anyways hope that helps. The second question is beyond me I'm still learning.

    Oh.... it contains classes.... Then, why do we need to import them??? What for? Why can we just put all the files together in a same folder and just run the main one???
  • : First question :
    : You can find some free API (java.sun.com), but you can also buy some.
    : Usually, sun free API are called java.xxx.*.. and other com.xxx.*...
    : As soon as you download an API, in .jar or .class format, you have tell at JVM where to find them. Update your classpath environnement variable and then you can write import com.*

    What do you mean??? What does API do? Why do we need to import them?
  • You must say import to tell the compiler where to find the classes you need to compile current class. This is the equivallent of include in C or Project Reference in VB.
    You won't have to specify import of classes if in your source code, you write the complete name of the class ex :
    [code]
    java.util.Date d = new java.util.Date();
    [/code]
    A bit long , isn't it ?
    So :
    [code]
    import java.util.*;
    ...
    Date d = new Date();
    [/code]
    Most accurate.
    In any case, classes you specify or import must be in classpath for compilation or execution



    [size=4][red](v)[/red][/size]

  • Oh now I understand... But... the problem is how to import? I mean do we need to create the Java files and store it in a folder called "Util" and then.... we import from there? If so, what import statement should we use? This one "import java.util.*;"? Or what?
  • First set your classpath to your working dir :
    set classpath=%classpath%;c:myWork

    Manage your java file as you want into subdirs for ex :
    c:myWorkfunstuffMyClass.java

    in MyClass.java, write in top of code :
    [code]
    package fun.stuff;
    [/code]

    In other class : for ex c:myWorkseriousstuffUserClass.java
    write :
    [code]
    package serious.stuff;
    import fun.stuff.*;

    public class UserClass{
    //You can use MyCall here :)

    }
    [/code]

    Here it is
    [size=4][red](v)[/red][/size]

  • : First set your classpath to your working dir :
    : set classpath=%classpath%;c:myWork

    Why do I need to set the classpath? Is it important to make the "import" statement work? If we need to set the classpath all the time if we want to make use of the import statment, then, how is the end-user going to know? How will they know about it?

    : package serious.stuff;
    : import fun.stuff.*;
    :
    : public class UserClass{
    : //You can use MyCall here :)
    : }

    Why do we need to make package as "package serious.stuff;"? Why not just "package stuff;"?

    P/S: Last question: Why do we use this? What for? Is it similar to the C++ header file?

  • : : First set your classpath to your working dir :
    : : set classpath=%classpath%;c:myWork
    :
    : Why do I need to set the classpath? Is it important to make the "import" statement work? If we need to set the classpath all the time if we want to make use of the import statment, then, how is the end-user going to know? How will they know about it?

    You need to set classpath in two cases : first for compilation. Javac need to know where to find classes used in your code. That's easy to understand.
    Now you need to set classpath for execution too. In any execution situation, you have a classpath set (current dir, %jre%/lib %jre%/jar etc...). When you run your code you must put classes you use in system specific directory or set classpath before. Most common solution are for execution in application mode : set classpath to . and run your classes from root dir with java serious.stuff.MyMainClass.
    In applet use jar file and set code to serious.stuff.MyMainClass
    :
    : : package serious.stuff;
    : : import fun.stuff.*;
    : :
    : : public class UserClass{
    : : //You can use MyCall here :)
    : : }
    :
    : Why do we need to make package as "package serious.stuff;"? Why not just "package stuff;"?
    As you want !!! you can manage your class as you like ! It was just a sample showing subdirs.
    :
    : P/S: Last question: Why do we use this? What for? Is it similar to the C++ header file?
    It's usefull to sort class depending on their fonctionnalities. Doing this, you can make import and use all object for given fonction. But it's most accurate to do this in a work context, for personnal coding it's not quite necessary exept if you have a billion of classes.
    :
    :

    [size=4][red](v)[/red][/size]

  • Oh yeah... now I understand!!!!!

    Ok. One more thing:

    (1.) Can anyone explain to me how do people create games with graphics? I mean in general! I tried to create it and it works. But, I uses lots of graphics from frame to another frame and oh my god, it really needed huge hard disk! So, how do people create a game? I mean like Fifa? Or maybe just a simple old 2D game like Mario Bros? Do they do like what I do? Frame by frame? Or is there any method to allow the game to work nicely?

    (2.) I have created a game which uses a thread. I uses KeyListener and when I press a key from my keyboard, the game work. The thread run and it executes the whole images that I put. But, after that, it can't run again. For example, I press "W", and the person walks for about 5cm in th monitor. Next, I want it to jump, and I press "J", but it won't. I know that my coding on the jump images to load doesn't have error, but... it's the problem with the thread. I think I stop the thread and it can't load back. You know how?

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories