473,320 Members | 1,993 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.

Noob Question - getFocusOwner not working?

Ok, heres the deal, i'm using netbeans 5.5 to create a Rational calculator(1/2 + 2/3 = 5/6, so on so forth) anyways, I have looked up on google, on this site, everywhere, and I am apperently missing the big idea, I can't get getFocusOwner to work, what does it return, what's the object u call it with? heres what i've been trying, so far nothin's workin.

// When i hit the 1 button, i want to add the integer 1 to the end of the int's in
// the focus'd jTextField. I don't even think i'm doin the appending correctly, but
// thats a whole nother story that I am alot less worried about.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
String temp = this.getFocusOwner().getText();
this.getFocusOwner().setText(temp + 1);
}

What i want in specific is, how do i find the focusowner, what variable does it return(ie jTextField1, jTextField2, and jTextField3 are textfields, does it return jTextField1, or does it return something else, such as text field 1?)
and how do i append an integer onto the end of the textfield's variables.

I know this is a simple question but I am about to lose it, i'm normally the one that just keeps pounding away tell i figure it out, but i've given up, and resorted to outside help. Thanks for the, sorry if it's already been "discussed" 100 times now, redirect me if it will answer my question fully.
Nov 7 '06 #1
9 4111
r035198x
13,262 8TB
Ok, heres the deal, i'm using netbeans 5.5 to create a Rational calculator(1/2 + 2/3 = 5/6, so on so forth) anyways, I have looked up on google, on this site, everywhere, and I am apperently missing the big idea, I can't get getFocusOwner to work, what does it return, what's the object u call it with? heres what i've been trying, so far nothin's workin.

// When i hit the 1 button, i want to add the integer 1 to the end of the int's in
// the focus'd jTextField. I don't even think i'm doin the appending correctly, but
// thats a whole nother story that I am alot less worried about.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
String temp = this.getFocusOwner().getText();
this.getFocusOwner().setText(temp + 1);
}

What i want in specific is, how do i find the focusowner, what variable does it return(ie jTextField1, jTextField2, and jTextField3 are textfields, does it return jTextField1, or does it return something else, such as text field 1?)
and how do i append an integer onto the end of the textfield's variables.

I know this is a simple question but I am about to lose it, i'm normally the one that just keeps pounding away tell i figure it out, but i've given up, and resorted to outside help. Thanks for the, sorry if it's already been "discussed" 100 times now, redirect me if it will answer my question fully.
Read the docs.

you call it on a widow(JFrame etends Window). It returns a Component(JTextField extends Component).

you could therefore do
((JTextField)frame.getFocusOwner()).getText();
Nov 7 '06 #2
See, i just tried it, and its saying jTextField isn't a variable, i want a generic code that turns out the owner of the focus(i've only got focusable on the 4 text fields.) so that when i hit the button it adds the value of the button i hit. and, read the docs, i've read about 10 tutorials and none of em haev worked, i spent about 1 hour making the rational class, 1 hour designing the buttons and about 10 trying to get the focusowner, i need a solid example, not some snippet that is incorrect.
Nov 7 '06 #3
sicarie
4,677 Expert Mod 4TB
See, i just tried it, and its saying jTextField isn't a variable, i want a generic code that turns out the owner of the focus(i've only got focusable on the 4 text fields.) so that when i hit the button it adds the value of the button i hit. and, read the docs, i've read about 10 tutorials and none of em haev worked, i spent about 1 hour making the rational class, 1 hour designing the buttons and about 10 trying to get the focusowner, i need a solid example, not some snippet that is incorrect.
Are you still using the code you posted above? Or did you change it to include the cast and the other parentheses? (Can you post both the new snippet and your error message?)
Nov 7 '06 #4
I've given up, i just resulted in doing this, as i only have 4 textfields and 10 buttons, it's not gonna make a bit of difference(maybe the teacher might not like it so much, o well)


// button/ 0 /

private void jButton10ActionPerformed(java.awt.event.ActionEven t evt) {
boolean tf1 = jTextField1.isFocusOwner();
boolean tf2 = jTextField2.isFocusOwner();
boolean tf3 = jTextField4.isFocusOwner();
boolean tf4 = jTextField5.isFocusOwner();
if(tf1 == true)
{
jTextField1.setText(jTextField1.getText() + "0");
}
if(tf2 == true)
{
jTextField2.setText(jTextField2.getText() + "0");
}
if(tf3 == true)
{
jTextField4.setText(jTextField4.getText() + "0");
}
if(tf4 == true)
{
jTextField5.setText(jTextField5.getText() + "0");
}

So i got that for button's 1 - 10(0 - 9), its alright, ill just go have an office hour with my teacher and figure all this crap out. thanks for the help, sorry for being short with whoever posted that.
Nov 7 '06 #5
r035198x
13,262 8TB
See, i just tried it, and its saying jTextField isn't a variable, i want a generic code that turns out the owner of the focus(i've only got focusable on the 4 text fields.) so that when i hit the button it adds the value of the button i hit. and, read the docs, i've read about 10 tutorials and none of em haev worked, i spent about 1 hour making the rational class, 1 hour designing the buttons and about 10 trying to get the focusowner, i need a solid example, not some snippet that is incorrect.
And at this rate, you will take 10 years to learn the java language. That snippet is correct. I gave you a snippet because I thought you knew what you were doing and would know how to use it.
Nov 8 '06 #6
sicarie
4,677 Expert Mod 4TB
Your code:
Expand|Select|Wrap|Line Numbers
  1. String temp = this.getFocusOwner().getText();
  2.  
Snippet given to you by r035198x:
Expand|Select|Wrap|Line Numbers
  1. ((JTextField)frame.getFocusOwner()).getText();
  2.  
I would suggest looking at the help given to you, and playing around with it a little bit, before saying you ran it and it didn't work.
Nov 8 '06 #7
Ok, if you must. his code, and the errors i get with it

Expand|Select|Wrap|Line Numbers
  1. ((JTextField)frame.getFocusOwner()).getText();
  2.  
  3. cannot find symbol
  4. symbol: class JTextField
  5. location: class FractionCalculator.FractionCalculator
  6.  
  7. cannot find symbol
  8. symbol: variable frame
  9. location: class FractionCalculator.FractionCalculator
now my code(adapted, i think correctly, but apparently not)
Expand|Select|Wrap|Line Numbers
  1. ((jTextField)FractionCalculator.getFocusOwner()).getText();
  2.  
  3. cannot find symbol
  4. symbol: class JTextField
  5. location: class FractionCalculator.FractionCalculator
  6.  
  7. non-static method getFocusOwner() cannot be referenced from a static context
as i may have said before, it is much easier for me to learn from code, not generic examples, like lets say:

what the class name is for JTextField and frame is, like say when you initialize it, do they still stay JTextField and frame, or am i supposed to change them. as i said before, i'm a beginner, using generic stuff on me and me knowing what it's referenced to is a strech from the truth. i need examples. If i need to, i'll post my fractioncalculator.java somehow or put it on rapidshare or somethin, maybe send it to some1's email if thats allowd??
Nov 8 '06 #8
here's the full code(for netbeans, the src files are inside it)

Fraction Calculator

sorry if this isn't considered helpful resources(it is to me:)) thanks for the help.
Nov 8 '06 #9
sicarie
4,677 Expert Mod 4TB
It would probably be helpful to have the full code.

What do your import statements look like? (import java.swing.text.*)?
Nov 8 '06 #10

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

Similar topics

7
by: administrata | last post by:
Is it possible? I tried... I = "John" print \ """ I used to love pizza"""
10
by: Matt Hollingsworth | last post by:
Hello, Very new to python, so a noob question. When I've written stuff in JavaScript or MEL in the past, I've always adopted the variable naming convention of using a $ as the first character...
1
by: davestrike | last post by:
I am a noob to sql and asp programming. I am working on a db for the gaming squad I am a member of. One of the pages I created is a roster list of all the squad members. Part of this roster is...
8
by: Ivan Shevanski | last post by:
Alright heres another noob question for everyone. Alright, say I have a menu like this. print "1. . .Start" print "2. . .End" choice1 = raw_input("> ") and then I had this to determine what...
0
by: AndyW | last post by:
Hey folks. I am trying to get a soap wsdl service working and have a bit of a noob php programming question for it. I'm using PHP 5.x btw. I have written a soap server that contains a...
2
by: Link360 | last post by:
Im a complete noob and im proud of it. I am excited in learning everything about the C++ language. Right now im trying to make tic-tac-toe. Go ahead laugh. here is what i have so far ...
5
by: Hydrogenfussion | last post by:
Hello and thank you for reading this. I have just started to learn C++ from www.cprogramming.com,its a great site! But i do not understand some of the terms. I am using Dev-C++. Can you tell me...
4
by: larry | last post by:
Ok I'm a Python noob, been doing OK so far, working on a data conversion program and want to create some character image files from an 8-bit ROM file. Creating the image I've got down, I open...
1
by: Fluffy654 | last post by:
First off I am a complete noob when it comes to doing anything with servers. I'm just beginning to learn today because I need to start adding SSI to my websites. I apologise in advance if I am making...
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...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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.