aspose file tools*
The moose likes Applets and the fly likes I'm having trouble passing a string to a class which extends applet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "I Watch "I New topic
Author

I'm having trouble passing a string to a class which extends applet?

Joe McTigue
Ranch Hand

Joined: Mar 05, 2012
Posts: 52
Hi,

I've created a swing application which collects data from a user and creates a graph with the data collected.

I need the paint method of the class which extends applet to be able to access a string.
I've tried passing the String to the paint method by way of instaniating the class from the
paint method like below, but can;t get it to work? I haven't worked with graphics in a long
time and could use any advice from any of you gurus on this. :-)

I'm using java SE 7 for this on a windows platform, developing using Eclipse IDE.

here's the segment I'm refering to:



The above segment as you can see is calling the following method in
the DisplayReport class:



Any advice dealing with getting the string to the GenerateLineGraph class would be awesome!
Thanks in advance for any input on this.
Joe McTigue
Ranch Hand

Joined: Mar 05, 2012
Posts: 52
By the way...

The String newName is making it to the DisplayReport class...
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18901
    
    8

I don't get what your DisplayReport class is supposed to be for. It's got some code to produce a new JFrame and put a JPanel in it (I don't know why you would want to do that, but that's what it does) and it's got some code to encapsulate a "name" string. The two parts don't seem to be related at all and so they shouldn't be in the same class.

Also in your applet's paint() method you shouldn't be doing anything which creates new GUI components. That method can be called whenever the Swing GUI control code decides it needs to redraw the applet. I was going to say it should not be creating a new DisplayReport object, but now that I look at the code again, you aren't calling the object's report() method so creating that object is harmless. It's also pointless, which maybe is the source of your question.

So... I can't advise you what to do because you have a lot of dysfunctional code, and I can't tell what it's supposed to be for. Perhaps you should back up a couple of steps and explain what you're trying to do instead of trying to fix what you have there.
Joe McTigue
Ranch Hand

Joined: Mar 05, 2012
Posts: 52
Hi Paul,

I'm trying to display 4 seperate graphics in the frame of the DisplayReport class.
this is the first I was trying to get working.
it actually works if you don't need to pass and data to it, but unfortunately, I need
to pass a string to it some how so it can use this data to retrieve more data from a
database to use in creating the report graph.

Keep in mind this is not a web application, only stand-alone SE application.
If you know of a better way of doing this, by all means please point me in the right
dirrection.

Thank you for your constructive remarks on code, I am working on cleaning it up
as well. Just trying to through something together to see if this could work first.

Any further advice is welcome and appreciated. :-)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18901
    
    8

Also I can't figure out why you're using the paint() method to do whatever it is, rather than painting the applet. The paint() method should draw on the Graphics object and essentially nothing else, and yours isn't even doing any drawing. So no, I don't have any suggestions how to modify that code to do whatever it is you're asking, except to reiterate my suggestion to tear it down and start over.
Joe McTigue
Ranch Hand

Joined: Mar 05, 2012
Posts: 52
I figured it out, just needed a constructor to pass in the string.
Thanks for thinking on this guys.
Have a great day!
piyush aegis
Greenhorn

Joined: Dec 27, 2012
Posts: 6
Hello everyone,
I am also suffering this problem, after reading all these posts i solved it,
Excellent information, thanks all of you.

Liferay Application Development
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: I'm having trouble passing a string to a class which extends applet?