/    Sign up×
Community /Pin to ProfileBookmark

Access a variable from the out class

I have a MyApplet class (extend Applet). In it, I declare 1 [B]instance variables[/B] (global var – double type) is: x = 13
and I have a button. I want then I clicked this button, a frame showed.

[I](I declared MyFrame class extend Frame)[/I]
My frame have 1 textfield and 1 button. I want then I clicked this button, value of variable x (in class MyApplet) show in textfield.

I tried created a method as getx() in MyApplet class:

[CODE]public double getx() {
return x;
}[/CODE]

Then at MyFrame class, I tried to use x , but program show 1 error ( cannot find symbol x).
– None stop, I tried to declare a new object have type MyApplet
(MyApplet obj = new MyApplet) then use obj.getx() to take value of x variable. But result returned is 0.0 ?

How do I must to take value of x variable from MyApplet class ?
help me ?

to post a comment
Java

1 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliJun 02.2007 — if I understand u correctly then u can pass the variable to the frame when u create it.
×

Success!

Help @h2q1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.22,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...