Welcome to Dream.In.Code
Become a Java Expert!

Join 150,407 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 951 people online right now. Registration is fast and FREE... Join Now!




Passing information to paint

 
Reply to this topicStart new topic

Passing information to paint

guilhermesfc
17 Mar, 2008 - 04:32 AM
Post #1

New D.I.C Head
*

Joined: 17 Mar, 2008
Posts: 1

I am trying to change paint as my appplet does some computationns (please see the code below) so that when I use repaint, I paint something new. How is this done in java?

Thank you very much!


java

package com.guilherme.main;

import javax.swing.JApplet;
import java.lang.Math;
import com.guilherme.investorRelated.VectorOfInvestors;
import com.guilherme.marketRelated.StockMarket;
import java.awt.Graphics;

public class RunnerApplet extends JApplet{

/**
*
*/
private static final long serialVersionUID = 1L;

public void init()
{this.resize(500,500);

}

public void start()
{
for (int i=0; i<2; i++)
//SOMETHING SHOULD BE CHANGING stockHistoryAux HERE
{repaint(); }

}

public void stop()
{}

public void paint(Graphics grafo)

{
int[] Ycoordinates = stockHistoryAux;
int[] Xcoordinates = {10,20,30,40,50,60,70,80,90,100};
grafo.drawPolyline(Xcoordinates,Ycoordinates,i);

}
}
}

*edit: Modified your code tags so they would work. Thanks for using them. smile.gif

This post has been edited by Martyr2: 18 Mar, 2008 - 12:35 PM
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Passing Information To Paint
18 Mar, 2008 - 12:42 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,660



Thanked: 314 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
The paint event can be a peculiar event in that it pretty much responds to the environment of the program. So to manipulate it you just need to manipulate the environment a little. What I mean by that is for you do something like make stockHistoryAux a variable of the program where you adjust its value using your loop in start() but then when you call repaint you read the value of stockHistoryAux to determine its course of action. paint() can see the variables out there in a higher scope, so if you can have your functions manipulate these variables and call a repaint, the paint function will use the current values to do its job.

So if in start() you want to store different y coordinates in the array (I am assuming it is an array of integers here based on your usage of it so far) then you would move it to be of a greater scope (like a variable of the class) and alter each of its elements. Then call repaint to have the paint() event read the current values of the array and draw accordingly.

Hopefully that makes sense to you. smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 07:34PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month