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

Swing probelm

Namit Puri
Ranch Hand

Joined: Aug 19, 2006
Posts: 51
import java.awt.*;
import javax.swing.*;

class MyDrawPanel extends JPanel
public void paintComponent(Graphics g)

The above code compiles successfully. But how to run it, i meant where to specify the main method, especially as we can't call the paintComponenet() method ourselves.


Namit Puri
SCJP 6.0
"Success is a journey, not a destination." Ben Sweetland
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24195


You need a "top-level component" like a JFrame to display a gui. You would then add an instance of this component to that JFrame, and display it. It doesn't matter where the main() is -- putting it into this class is perfectly fine. So main() would look something like

[Jess in Action][AskingGoodQuestions]
Namit Puri
Ranch Hand

Joined: Aug 19, 2006
Posts: 51
Thanks Ernest!!
I agree. Here's the link:
subject: Swing probelm
jQuery in Action, 3rd edition