Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing values to paint()

Status
Not open for further replies.

Tyx

Programmer
Aug 3, 2000
1
GB
Is there any way that I can pass a variable to paint()? I am trying to make an applet of a real-time graph, and it's impossible to put labels on the axes, because the graph gets scaled at every repaint, so the y-axis changes position all the time. <br>So, I tried doing it from outside, scaling it once, and passing the scaling factor to paint() just once, since it doesn't change much. <br>But it's impossible...I can't get the width and the height of the frame if I do it outside paint. I tried creating another method with the values, and calling it from inside paint...no luck, since the values are zero, without the dimensions. And even if I find a way to do that, if then I want to maximise the graph window, since the scaling is not done in paint anymore, it won't rescale, as it does now. <br>I hope this is all clear, I'm fairly new in Java programming...does anyone have any ideas, or any applets of resizable scaled real-time graphs with numbered axes that I can look at? Thanks! :)
 
&gt; Is there any way that I can pass a variable to paint()? <br><br>No, you should not have to. All of the information you need to paint with can be obtained by or given to the class that the paint method is a member of. Then at the next repaint the method has access to all the information required.<br><br>&gt; I hope this is all clear<br><br>No, it isn't.<br><br>&gt; does anyone have any ideas<br><br>Sure, show some of the pertinent code where the problem(s) occur, i.e.:<br><br>&gt; I can't get the width and the height of the frame if I do it outside paint. <br><br>Show the code where that fails and explain how and when it fails.<br><br>-pete
 
int maxx,maxy;<br>int maxx12,maxx14, maxx18,maxx34,maxx78,maxy12,maxy14,maxy18,maxy34,maxy78;<br><br>public init()<br>{<br><br>maxx = getSize().width;<br>maxy = getSize().height;<br>maxx12 = (maxx / 2); //.5<br>maxx14 =(maxx/2)/2; //.25<br>maxx18 = (((maxx/2)/2)/2); // 0.125 <br>maxx34 = maxx12 + maxx14; //.75<br>maxx78 = maxx12 + maxx14 + maxx18; //.875<br>//these lengths will be added to the x position to acheive the desired pos<br><br>//these variables con<br>maxy12 = (maxy / 2); //.5<br>maxy14 =(maxy/2)/2; //.25<br>maxy18 = (((maxy/2)/2)/2); // 0.125 <br>maxy34 = maxy12 + maxy14; //.75<br>maxy78 = maxy12 + maxy14 + maxy18; //.875<br>}<br><br>put this in the init() method of you applet<br>When the applet is first created it will take the width and height, the rest of the variable are simpel ints that are offshoots of the variables.&nbsp;&nbsp;This is the applet size that you set in the &lt;applet width=? height=?&gt;&lt;/applet&gt;&nbsp;&nbsp;that is the size that it will grab. with the getSize().width;<br>getSize().height method.<br>this is a way to position the elements in your applet dynamically to move based on what you put in the html file.&nbsp;&nbsp;Simply set your graph x and y to use these coordinates and you will not have to statically set your positions.&nbsp;&nbsp;<br><br> <p>moses<br><a href=mailto:tmoses@iname.com>tmoses@iname.com</a><br><a href= my site</a><br>"In the beginning there was HTML, and it was good"<br>
by Nick Heinle, Designing with JavaScript<br>
<br>
<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top