File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Graphic question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Graphic question" Watch "Graphic question" New topic
Author

Graphic question

Kay Kumar
Greenhorn

Joined: Feb 28, 2005
Posts: 11
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

Joined: Aug 20, 2001
Posts: 1824

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.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Try this
Kay Kumar
Greenhorn

Joined: Feb 28, 2005
Posts: 11
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Graphic question