I am making an app or (something.exe). I want to make a class that will serve as my main frame. That is because I don't want to create new frame for each class that I will make. I want my class MainMenu
to have the Frame of MainFrame
where I can put buttons and etc.
package ThinkNotOfficial;
public class Main {
public static void main(String[] args) {
MainFrame mainFrame = new MainFrame();
}
}
package ThinkNotOfficial;
import javax.swing.*;
import java.awt.*;
public class MainFrame extends JFrame{
// Global Variables
JFrame mainFrame = new JFrame("Base Frame (global)");
ImageIcon logo = new ImageIcon("Logo.png");
MainFrame (){
mainFrame.setSize(500, 500);
mainFrame.setResizable(false);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setIconImage(logo.getImage());
mainFrame.getContentPane().setBackground(new Color(255,255,255));
mainFrame.setLocationRelativeTo(null);
mainFrame.setLayout(null);
mainFrame.setVisible(true);
// ------------ PROGRAM FIELD -----------
}
}
package ThinkNotOfficial;
import javax.swing.*;
public class MainMenu{
// ------------ Global Variables ------------
JButton play = new JButton("PLAY");
MainMenu(){
// ------------ PLAY button ------------
play.setSize(100,50);
// ------------ Adding parts ------------
}
}