This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Swing probelm" Watch "Swing probelm" New topic
Author

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)
{
g.setColor(Color.orange);
g.fillRect(20,50,100,100);
}
}

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.

Thanks!


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

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi,

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!!
 
 
subject: Swing probelm
 
Similar Threads
Document Listener and/or Ley Listener
using classes in jsp (not servlets )
println
String value substitution
DOM and JAVA