Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Graphic question

 
Kay Kumar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I am trying to execute the code below. It compiles and runs. However when it runs the oval drawn flashes on the mainWindow and dosn't stay there (hopefully you know what i mean).

import javabook.*;
import java.awt.*;

class Test
{

public static void main (String [] args)
{

MainWindow mainWindow;
mainWindow = new MainWindow();
mainWindow.show();
Graphics graphic = mainWindow.getGraphics();

graphic.drawOval(100, 100, 200, 200);

}//main
}



Any help??

Thanks as always
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like the MainWindow class is repainting itself. Since the logic to draw the oval is not in the paint logic, you draw the oval, and the th eMainWindow paints over it.

I'm going to move this to our Swing/AWT forum; you will probably get better help there.
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this
 
Kay Kumar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm getting the error

Test1.java:11: non-static variable this cannot be referenced from a static context

mainWindow.add(new TestPanel(), BorderLayout.CENTER);


1 error
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic