• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way...

The String newName is making it to the DisplayReport class...
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I figured it out, just needed a constructor to pass in the string.
Thanks for thinking on this guys.
Have a great day!
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,
I am also suffering this problem, after reading all these posts i solved it,
Excellent information, thanks all of you.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic