How to create Jframe?

How to create a basic programme that shows JFrame?Please guide me.
[80 byte] By [maggiemaggiea] at [2007-11-26 18:50:53]
# 1
this is a very useful site, explains things in good detail without all the jargon: http://chortle.ccsu.edu/java5/Notes/chap56/ch56_1.html
boblettoj99a at 2007-7-9 6:24:58 > top of Java-index,Java Essentials,New To Java...
# 2
Thankyou Its really helpful .
maggiemaggiea at 2007-7-9 6:24:58 > top of Java-index,Java Essentials,New To Java...
# 3

Hmmm... I checked out the first few pages of that sight, but I had to flee in

horor when they suggested overriding JFrame's paint method. Aiieee!!!

Sun's Swing tutorial is very good. Here is the HelloWorld page: http://java.sun.com/docs/books/tutorial/uiswing/learn/example1.html

And here is the overall starting point: http://java.sun.com/docs/books/tutorial/uiswing/index.html

DrLaszloJamfa at 2007-7-9 6:24:58 > top of Java-index,Java Essentials,New To Java...
# 4
>Hmmm... I checked out the first few pages of that sight, but I had to flee in>horor when they suggested overriding JFrame's paint method. Aiieee!!!All I needed to see was "You create a GUI by extending class JFrame."(Don't extend JFrame)#
duckbilla at 2007-7-9 6:24:58 > top of Java-index,Java Essentials,New To Java...
# 5

> (Don't extend JFrame)

What about the following?

public class SomeFrame extends JFrame {

private JButton someButton;

private JTextArea someTextArea;

...

}

I'm playing Devil's advocate because I try to subclass only when I *have* to. But I wish I had a nickel for ever time I say this style of coding for frames and panels.

DrLaszloJamfa at 2007-7-9 6:24:58 > top of Java-index,Java Essentials,New To Java...
# 6

>What about the following?

You add() the components to a frame. Well, at least it has private modifiers. I would, nevertheless, stick to using a JFrame as it is, as long as it provides all the functionality I need (and it has so far).

What I find most horribliest is this

public class TheFrame extends JFrame implements <insert list of listeners here>

{

//...

}

Talk about bloating a class.

#

duckbilla at 2007-7-9 6:24:58 > top of Java-index,Java Essentials,New To Java...
# 7

Similarly,

public class ThePanel extends JPanel implements <insert list of listeners here>

{

//...

}

There are any number of things wrong with having a frame/panel subclass defined this way.

1. Often coders with any number of disparate buttons make their

frame or panel listener to them all:

public class ThePanel extends JPanel implements ActionListener

Then the actionPerformed method is a laundry list of if/then/elseifs. Ugh.

That's the perfect situation for specific action objects listening to specific controls.

2. Exposing implementation details: the fact that the panel is listening

to list selection is not part of the API for the panel, it's an implementation

detail, yet that's not what this reads as:

public class ThePanel extends JPanel implements ListSelectionListener

What's to stop other code from doing the following?

unrelatedList.addListSelectionListener(thePanel); //woops, thePanel wasn't meant to listen to *that* list.

It's surprising what cruft people won't tolerate in other areas of code are

happy to commit in Swing code.

Message was edited by:

DrLaszloJamf

DrLaszloJamfa at 2007-7-9 6:24:58 > top of Java-index,Java Essentials,New To Java...