
-----------------------------------
the_short1
Thu Jun 01, 2006 10:42 am

KeyListen (outputs keycodes&amp;keytext)
-----------------------------------
A simple program i made to give the keycode and keytext values (output sent to terminal window), as you type in the gui window.

I used it to give me the values for all of my Menu shortcut keys (eg. pressing ctrl+s to save, keycode=83, keyText=S), and special ones like keyCode=8 and keyText="Backspace" to backup a move in my game.

If you have any questions/comments just pm/reply.

-kevin

-----------------------------------
cool dude
Thu Jun 01, 2006 4:38 pm


-----------------------------------
this will probably sound stupid but i can't exit the program unless i go to task manager and end the task. how would i exit the program?

-----------------------------------
HellblazerX
Thu Jun 01, 2006 4:45 pm


-----------------------------------
Hmmmmm, looks like you forgot this:

setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

Otherwise people would have to close whatever they're using to run the program, rather than the JFrame itself.

-----------------------------------
cool dude
Thu Jun 01, 2006 4:53 pm


-----------------------------------
for some reason its not working for me. it says cannot resolve symbol varaible jframe

-----------------------------------
HellblazerX
Thu Jun 01, 2006 4:57 pm


-----------------------------------
Ooooo, I see.  He's using the old awt containers, not the new Swing ones.  And it doesn't seem like the old containers have such a command.  Looks like you'll have to add a WindowListener to close the program, but I can't be sure, seeing as I have never used them before.

-----------------------------------
[Gandalf]
Thu Jun 01, 2006 5:09 pm


-----------------------------------
Something like so should do:
addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
        System.exit(0);
    }
});
Though really, there is no reason for you not to be using JFrame instead...  It only takes a few keystrokes to change.

-----------------------------------
the_short1
Thu Jun 01, 2006 6:30 pm


-----------------------------------
ty gandalf for informing them how to close the awt window, but seing as i wanted to keep it simple i didnt include that.

To close the program, close the DOS window, and it will automatically close the GUI window :)...  (and this works for most if not all programs)

-----------------------------------
cool dude
Thu Jun 01, 2006 7:42 pm


-----------------------------------
but i'm not in DOS when i run it. i run it through Blue J and it won't close! thats why i posted for help on this question because at times i make an endless loop and i can't close the window.

-----------------------------------
the_short1
Thu Jun 01, 2006 9:53 pm


-----------------------------------
ohh.. i use JCreator.. . what is blueJ? ive never heard of it.
hmm.. . well for my current game im working on i send a lot of debugging to the terminal (dos) window, why dont you see it ? what happens to all your System.out.println's?

-----------------------------------
cool dude
Fri Jun 02, 2006 7:26 pm


-----------------------------------
since i'm kinda new i don't know wat JCreator is and where to get it, but Blue J is wat most schools use (i think). it's really easy because all i have to do is write the code and then press the button compile to compile it and then i just run it by pressing a button. simple as that. instead of going to java typing the path and all that stuff. the system.out.println's just display in the terminal window and i never said i don't see them. your program works perfectly fine and i see it its just that i can't exit it but gandalf fixed that issue

-----------------------------------
the_short1
Sat Jun 03, 2006 10:58 am


-----------------------------------
ahh just a misunderstanding then :) ..  our class commonly calls the terminal window the dos window.... JCreator is used by the whole algoma district school board, and it is probally really similar to BlueJ, http://www.jcreator.com/.. 

Im still curious: does closing the 'terminal' window in bluej close this program as well?

-kevin

-----------------------------------
cool dude
Sat Jun 03, 2006 5:01 pm


-----------------------------------
u can't close the program in Blue J by clicking on the "x" because it doesn't work! the only way is to end the program by having a command in your code i.e. type 0 to exit and in your code make it so that it exits. then u can click on the close button and it will close the running program.

-----------------------------------
cool dude
Sat Jun 03, 2006 8:45 pm


-----------------------------------
wow JCreator is so much better! thanks for the link :) 
just a quick question wat is the difference when u go to file and it says new file or new project?

-----------------------------------
the_short1
Sun Jun 04, 2006 12:15 pm


-----------------------------------
well .. if your just making small programs.. go new file..  best feature of jcreator is the auto indent and auto brackets (which can be turned off in options), and nice syntax highlighting. ohh and the debugger is pretty good.

projects is for manipulating multiple source code files within one program.. eg. my pegged game, i have a main.java menu.java and verify.java, when i add all 3 to a project i can access methods from one another as if it was one big file.

no problem :)

-----------------------------------
cool dude
Sun Jun 04, 2006 12:21 pm


-----------------------------------
also when i open a new file it doesn't automatically put the class name i.e.

public class example

is there any way to make that automatic or do u have to type it every time because in BlueJ it was automatic. also when u say you could access the methods from one another as it was one big file do u have to write something in your code or it automatically accesses it?

-----------------------------------
wtd
Sun Jun 04, 2006 12:27 pm


-----------------------------------
public class example

Class names should always be capitalized (note: not the same as all-caps).  Get into the habit early on and you'll save yourself a lot of grief.

-----------------------------------
the_short1
Sun Jun 04, 2006 9:25 pm


-----------------------------------
well i think you can set up the templates somewhere in options to auto add it .. .   but personally i have a file called template.java which has everything needed for a standard gui window and i just edit that each time.

As for the projects... example: i added Main.java and MenuTest.java to a project. I have a method called createMenu (), inside menutest, and im currently coding in main.java.. .this is what i write:

MenuTest.createMenu ();

and if i remember correctly, if you call methods this way, it is static, so method createMenu must be declared static (and all your variable inside createMenu as well).. optionally, you can create a object of the other class.. eg:
MenuTest Menu = new MenuTest ();
then just call Menu.createMenu (); .... but if you use a contructor for your GUI then initializing Menu = new MenuTest (); will open a new window..

-----------------------------------
wtd
Sun Jun 04, 2006 11:13 pm


-----------------------------------
Hmmm... "createMenu" sounds like something taken from Sun's tutorials.

I strongly urge you to write your own programs from scratch, rather than modifying existing source code.  Copy and paste does not contribute to a fundamental understanding of the subject.

-----------------------------------
the_short1
Mon Jun 05, 2006 9:26 am


-----------------------------------
[quote="wtd"]Hmmm... "createMenu" sounds like something taken from Sun's tutorials.[quote]

LOL! ... more like it sounds like something from my current program... i didnt copy and paste from anywhere... lol
[code="java"] 
//snippet ..
setSize (maxx,maxy); // sets size of window
setTitle (" Level: "+pegLevel.substring(0,(pegLevel.length()-4))); // sets title of the window
setLayout (null); // sets no style, we do it ourselves
setBackground (Color.black); // sets background of the window to black
setMenuBar(Menu.createMenu()); // adds the menubar to the window
// Menu is a object of another file in my project...
[/code]

-----------------------------------
wtd
Mon Jun 05, 2006 10:11 am


-----------------------------------
Ah.
