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_();
}
}

