473,320 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Basic gui prob

2
im a beginner java user so forgive me for my poor code! :)... i have a simple gui with a textarea and txtbox the textarea is used for output and the textbox is used for input... i also have a few other classes which need to take the input... unfortunatly this gui cannot have any buttons.... my problem is this. I have a method called getInput which looks like this!

private void getInput(KeyEvent keyEvent){

int keyCode = keyEvent.getKeyCode();
String keyText = KeyEvent.getKeyText(keyCode);
if(keyText.equals("Enter")){
userinput = input.getText().toString();
input.setText("");
}
}

and another method that is called by other classes
public String getInput(){
//getInput();
input.requestFocusInWindow();
getInput(keyEvent);
return userinput;
}

however when getInput is called by other classes it runs and returns an empty userinput which generates an error!....

So my question is how do i get the user to enter the information into the textbox and press enter before the getInput() finishes

i would be greatful for any help thanks :D
Nov 25 '07 #1
2 973
JosAH
11,448 Expert 8TB
So my question is how do i get the user to enter the information into the textbox and press enter before the getInput() finishes

i would be greatful for any help thanks :D
GUIs don't work that way (in Java), i.e. you can't force the user to type anything;
your code has to be notified if and when the user types something. It's called
'event based programming'. If you look at the JTextField class API documentation
you'd see that you can register 'listeners' to it. When something happens in that
object it wakes up the listeners so they can respond to the event, e.g an enter
key was pressed.

You have to drastically turn your code 'inside out' for this.

kind regards,

Jos
Nov 25 '07 #2
N00bie
2
thanks i will look that up
Nov 26 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: josephrthomas | last post by:
hi..i am trying to make a login page and i am using access table.. when the user enters his userid and password i want to check the password from the table.. if any user with the userID that is...
29
by: Thomas | last post by:
Hi I have an XSL stylesheet: <xsl:for-each select="TRACKS/TRACK"> <tr class="TDL"> <td width="90%"><xsl:number value="position()" format="1" /> - <xsl:value-of select="TRACKTITLE"/></td>...
0
by: mark | last post by:
Here's the most concise description I can give you of my problem... I'm trying to create a narrow form in Visual Basic.NET 2003. The form is about 95 pixels wide by 325 long. I resized it to...
2
by: Dishan Fernando | last post by:
Hi my prob is like this.. ----------------------------- create table ax( i int , j int ) create table ay( i int ,
15
by: Raj | last post by:
Hello all: We have a table with about 2400 cells. Our requirement is to highlight the cells in the table whose data has changed, every 5 seconds. Our script behaves relatively ok in Firefox, but...
6
by: skubik | last post by:
Hi everyone. I'm attempting to write a Javascript that will create a form within a brand-new document in a specific frame of a frameset. The problem is that I can create the form and input...
2
by: Wilhelm Kutting | last post by:
hi, i like to solve a code-prob: tidy is bitching about <...> proprietary attribute "type" <...> lacks "action" attribute how can i make this nice? this is my code
28
by: Vishal Naidu | last post by:
i m new to the C world... i ve been told by my instructors not to use goto stmt.. but no one could give me a satisfactory answer as to why it is so.. plz help me out of this dilemma, coz i use...
5
by: Gerardo | last post by:
Hello everybody, could anyone paste me a snippet, or part of the code for working with trees, it's a control I need to figure out how to use it. Thanks Gerardo
0
Savage
by: Savage | last post by:
I'm making for fun a simple program which format a input file.Input file sustain of person name,lastname and date of birth.Output file si supposed to be forammted as following: NAME ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.