For the sake of everyone understanding my problem, I've created a simple GUI program which shows my problem. I'll first put the codes for you to analyze. And then, please watch the video below to see what I've been meaning to ask. Please bear with me, the video is just a few seconds and will not take time to load.
Menu JFrame:
//This is a Menu JFrame Window
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Menu extends JFrame implements GlobalVariables{
public Menu(){
clickMe.setBounds(75, 50, 100, 50);
clickMe.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
dispose();
SubMenu sm = new SubMenu();
sm.subMenuProperties();
}
});
add(clickMe);
}
void menuProperties(){
setLayout(null);
setSize(250,175);
setVisible(true);
setResizable(false);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
Menu m = new Menu();
m.menuProperties();
}
}
SubMenu JFrame:
//This is a SubMenu JFrame Window
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class SubMenu extends JFrame implements GlobalVariables{
public SubMenu(){
clickMe2.setBounds(75, 50, 100, 50);
clickMe2.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
dispose();
Menu m = new Menu();
m.menuProperties();
}
});
add(clickMe2);
}
void subMenuProperties(){
setLayout(null);
setSize(250,175);
setVisible(true);
setResizable(false);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
SubMenu sm = new SubMenu();
sm.subMenuProperties();
}
}
And if your're wondering what's the "GlobalVariables" implementation, here it is:
import javax.swing.*;
public interface GlobalVariables{
//Menu Variable
JButton clickMe = new JButton("SubMenu");
//SubMenu Variable
JButton clickMe2 = new JButton("Back");
}
Now, this video will show you what I mean in JFrame being multiplied:
http://www.youtube.com/watch?v=iCavg_1SqvY
*If you watched the video, you can see what I mean when I say the JFrame is being multiplied. I've been analyzing this for days but I cannot identify my mistake. If you can just pinpoint my mistake, I'll be more than thankful. I'm also open for comments and adjustments in the code, I just wish that the structure of the code will not be re-structured because as I've said earlier, I've created this simple GUI just to show you my problem but to tell you at least, I have a whole program waiting to be finished using this kind of approach in GUI making. Please help me.