Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 2 [3]

Author Topic: Basic Java GUIs  (Read 4406 times)

SolarShado

  • Bay Watcher
  • Psi-Blade => Your Back
    • View Profile
Re: Basic Java GUIs
« Reply #30 on: December 06, 2009, 03:35:18 am »

I do most of my coding when I'm away from 'net access, so I use the javap command and toString() alot.
Logged
Avid (rabid?) Linux user. Preferred flavor: Arch

eerr

  • Bay Watcher
    • View Profile
Re: Basic Java GUIs
« Reply #31 on: December 06, 2009, 11:43:26 am »

Eclipse will give you better information per function than javap.

Eclipse gives the online descriptions of every function for a given object. You can find them by selecting an object of that type, a period, and focusing(f2). You'll see a box full of functions. If you Type out the first letter and eclipse will pull out all the functions that begin with that letter.

Unfortunately, I don't think eclipse has anything for the variables inside.

BTW, I was browsing an old java API book a week ago. There were 9 pages of get__() methods, and only 3 pages of set__() methods.
« Last Edit: December 06, 2009, 12:01:30 pm by eerr »
Logged

AlStar

  • Bay Watcher
    • View Profile
Re: Basic Java GUIs
« Reply #32 on: December 06, 2009, 12:41:56 pm »


Ok, I think that I've overcome most of the problems I was having getting all this set up. (Turns out I was improperly using the KeyListener, so that nothing was getting picked up.)

Anyway, now when I type in my jTextField, KeyEvents will trigger as intended, and if I throw a toString() in the KeyLogger, I get the same kind of information that Solar posted.

Now I'm trying to actually use the information I'm getting from the KeyListener in my program, and I'm coming up a little short.

What I'm trying to do is have the user enter their name. Should be easy, yes?
The code that I'm trying to write is something along the lines of:
(note: jTextField1 has the KeyListener attached to it)
Code: [Select]
... (//code before this)
jTextField2.setText("What name will you be known by?: ");//another textbox set above the one that the user enters information on.
jTextField1.setText(null);//clears the old information that was in the textbox.
While (done == false){ //while waits for the information to be entered.
if (jTextField1.*command I can't figure out* == enter){ //SHOULD wait for user to press enter, then grab the name so that it can contune.
input = jTextField1.getText();
done = true;
}
}
... (//code after this)

But there doesn't seem to be any way to access jTextField1's KeyListener that I can figure out. I dunno, maybe I'm trying to go about this the wrong way. How do I get the main body of my code to realize when enter is pressed?

eerr

  • Bay Watcher
    • View Profile
Re: Basic Java GUIs
« Reply #33 on: December 06, 2009, 01:02:47 pm »

You make me cry. Every question you asked so far worked in my mock-up program.

The enter button triggers on "KEY_PRESSED" or "KEY_UP".
It does give a 0(null) for key code and keywhatever inside the "KEY_TYPED" event.

While (done == false){ //while waits for the information to be entered.
if (jTextField1.*command I can't figure out* == enter){ //SHOULD wait for user to press enter, then grab the name so that it can contune.
input = jTextField1.getText();done = true;}}

A loop is the wrong way to do this. This is not console.in or console.out, though i'm almost done with my buffered console.
However, if you really do want to do that way, you'll need a few things.
A "final" buffer listed in your program, something that can accept input and buffer the output. You can make your own version if you want, as I couldn't find any that did exactly what I want(still working on it).
Your console must declare the buffer in a "final" variable, then pass said variable to the keylistener. like

final textF=textfield1;
final buff=buffer;
textF.addkeylistener(
Keypressed(keyevent e){

buffer.add(textF.gettext());
textF.settext("");
}
)
Then the console can spam-request input from the buffer, which will be a string devoid of any characters that Textfields ignore.

« Last Edit: December 10, 2009, 08:57:18 am by eerr »
Logged

eerr

  • Bay Watcher
    • View Profile
Re: Basic Java GUIs
« Reply #34 on: December 08, 2009, 09:36:28 am »

Come to think of it, I'm not sure if the keylistener will accumulate more than one call. It's only one thread after all.

If thats the case, just pass the method that accepts new user input, with instructions on where to send it. Enterpressed is probably the only method you'll need.

Logged
Pages: 1 2 [3]