如何对所有 类 使用 1 个 JFrame?
How to use 1 JFrame for all the classes?
美好的一天。我想请问如何使用这个包含我的主框架细节的1class作为我将要制作的所有class的框架?我希望它成为我所有 classes 的框架。提前谢谢你。
package ThinkNotOfficial;
import javax.swing.*;
import java.awt.*;
public class MainFrame{
// Global Variables
JFrame mainFrame = new JFrame("Base Frame (global)");
ImageIcon logo = new ImageIcon("Logo.png");
MainFrame(){
mainFrame.setSize(720, 720);
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.setVisible(true);
}
}
您应该创建属性 class。和彼此 class for JFrame window
public class FrameProperties {
JFrame mainFrame = new JFrame("Base Frame (global)");
ImageIcon logo = new ImageIcon("Logo.png");
public void Properties(){
mainFrame.setSize(720, 720);
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.setVisible(true);
}
}
然后您可以创建您的框架 classes 并向其中添加您的方法
public class MainFrame extends JFrame{
// Global Variables
MainFrame(){
FrameProperties frameProperties = new FrameProperties();
frameProperties.Properties();
}
public class SecondFrame extends JFrame {
SecondFrame(){
FrameProperties frameProperties = new FrameProperties();
frameProperties.Properties();
}
}
public static void main(String[] args) {
new MainFrame();
new SecondFrame();
}
美好的一天。我想请问如何使用这个包含我的主框架细节的1class作为我将要制作的所有class的框架?我希望它成为我所有 classes 的框架。提前谢谢你。
package ThinkNotOfficial;
import javax.swing.*;
import java.awt.*;
public class MainFrame{
// Global Variables
JFrame mainFrame = new JFrame("Base Frame (global)");
ImageIcon logo = new ImageIcon("Logo.png");
MainFrame(){
mainFrame.setSize(720, 720);
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.setVisible(true);
}
}
您应该创建属性 class。和彼此 class for JFrame window
public class FrameProperties {
JFrame mainFrame = new JFrame("Base Frame (global)");
ImageIcon logo = new ImageIcon("Logo.png");
public void Properties(){
mainFrame.setSize(720, 720);
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.setVisible(true);
}
}
然后您可以创建您的框架 classes 并向其中添加您的方法
public class MainFrame extends JFrame{
// Global Variables
MainFrame(){
FrameProperties frameProperties = new FrameProperties();
frameProperties.Properties();
}
public class SecondFrame extends JFrame {
SecondFrame(){
FrameProperties frameProperties = new FrameProperties();
frameProperties.Properties();
}
}
public static void main(String[] args) {
new MainFrame();
new SecondFrame();
}