jQuery in Action, 3rd edition
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

Graphic question

Kay Kumar

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();
Graphics graphic = mainWindow.getGraphics();

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


Any help??

Thanks as always
Joel McNary

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

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
It's not a secret anymore!