I have this function which computes the position record of 6 requests. ( ie x,y,dx,dy--these are the position records for a request)
I want to display these position records in a textfield, which i have in my GUI, as soon as i press the "positionrecord" button.
I am able to print the position records for all 6 requests on the console(of eclipse), but on the GUI only the position record of the 6th request is getting displayed in the textfield.I have also used a delay function which is working fine.I had been suggested to use paint function.
I have put the paint function also but i am not at all sure if it is correct.

public void paint() {
Graphics g= null;
PosRecord prec=requestGenerator.getNextRecord(); 
Graphics2D g2 = (Graphics2D)g;
double x = 15, y = 50, w = 70, h = 70;

SidePanel.PositionRecc.setText(prec.toString());

MainFrame.mapPanel.repaint();
Ellipse2D e = new Ellipse2D.Double(x, y, w, h);
GradientPaint gp = new GradientPaint(75, 75, Color.white,
95, 95, Color.gray, true);

e.setFrame(x 200, y, w, h);

System.out.println("inside paint function");

if(buffer != null) 

bgraphics = buffer.getGraphics();
Graphics2D g2d = (Graphics2D) bgraphics;

} 


if (request.getId()==100) {
System.out.println("Anonmized for message of node id " request.getId() );
System.out.println("Grid Cells: "); //request.getId()
for (int i = 0; i < orequests.size(); i++) {

SidePanel.PositionRecc.setText(request.toString());
paint();
SidePanel.PositionRecc.isOpaque();


System.out.println("NEW");

isVisible();
//MainFrame.mapPanel.repaint();
try
{
Thread.sleep(100);


}
catch(InterruptedException e)
{

//e.printStackTrace();

} 

//super.update(g);
SidePanel.PositionRecc.setText(request.toString());
MainFrame.mapPanel.repaint();
// TraceGenerator.SidePanel.PositionRecc.setText(request.toString());
System.out.print("NEW1 " + orequests.get(i));
}

The problem is that you are executing all of that code on the event dispatch queue - which also handles repaints - so it can't update the GUI until your current code completes. You need to start a separate thread to for the calcs and then update the UI on the event dispatch thread. You can read about that here: http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.