Inner Class vs IS - A relationship

Im making a program that switches between frames and i just want to know which is more acceptable to use, and why to use.

Inner Class

package test;

import java.awt.FlowLayout;

import java.awt.HeadlessException;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import javax.swing.JButton;

import javax.swing.JFrame;

publicclass Startextends JFrame{

private JButton btn =new JButton("Open New Frame");

public Start(){

setSize(100,100);

getContentPane().add(btn);

btn.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent e){

setVisible(false);

new Inner();

}

});

addWindowListener(new WindowAdapter(){

publicvoid windowClosing(WindowEvent e){

System.exit(0);

}

});

setVisible(true);

}

publicstaticvoid main(String args[]){

new Start();

}

privateclass Innerextends JFrame{

public Inner(){

setSize(100,100);

setVisible(true);

addWindowListener(new WindowAdapter(){

publicvoid windowClosing(WindowEvent e){

Start.this.setVisible(true);

}

});

}

}

}

IS - A relationship

package test;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import javax.swing.JButton;

import javax.swing.JFrame;

publicclass Start_extends JFrame{

private JFrame frame =new JFrame();

private JButton btn =new JButton("Open New Frame");

public Start_(){

setSize(100,100);

getContentPane().add(btn);

btn.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent e){

setVisible(false);

frame.setSize(150,150);

frame.setVisible(true);

frame.addWindowListener(new WindowAdapter(){

publicvoid windowClosing(WindowEvent e){

setVisible(true);

}

});

}

});

addWindowListener(new WindowAdapter(){

publicvoid windowClosing(WindowEvent e){

System.exit(0);

}

});

setVisible(true);

}

publicstaticvoid main(String[] args){

new Start_();

}

}

[5804 byte] By [Zangrelaa] at [2007-10-2 5:37:49]
# 1

In this particular example, I would say they are both equally bad. In a non-trivial application your GUI component is not going to be deciding when it should and should not be displayed. Some higher level of logic is going to decide that.

For example, an open dialog does not decide it should be displayed because a user clicked open. Rather, your logic decides that when a user clicks an open button an open dialog should be created. This logic, generally, will not be part of your GUI components themselves.

kablaira at 2007-7-16 1:48:17 > top of Java-index,Java Essentials,New To Java...
# 2

"For example, an open dialog does not decide it should be displayed because a user clicked open. Rather, your logic decides that when a user clicks an open button an open dialog should be created. This logic, generally, will not be part of your GUI components themselves."

Can you show me a simple code doing that? I didnt understand what you said.

Zangrelaa at 2007-7-16 1:48:17 > top of Java-index,Java Essentials,New To Java...
# 3

up.

And sorry , the relationship is HAS - A and not IS - A like in the subject.

I did not specified very well.

But what im trying to do is to instantiate a new specific class (jframe) to use when the user clicks the search button. This new class has specific components to make the search.

These 2 ways work well, but i dont know if its good desing.

Any advice will be good.

Zangrelaa at 2007-7-16 1:48:17 > top of Java-index,Java Essentials,New To Java...
# 4
And thanks god this forum is working again.The login wasnt working to me.
Zangrelaa at 2007-7-16 1:48:17 > top of Java-index,Java Essentials,New To Java...