This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
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

Win a copy of Building Microservices this week in the Design forum!
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: 24190


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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Swing probelm
It's not a secret anymore!