📄 mainframe.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class MainFrame
{
//获得显示器的高度和宽度
public static final int screenWidth = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
public static final int screenHeight = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();
//设置主画框的缺省宽度和缺省位置
private static int width = screenWidth / 3;
private static int height = screenHeight / 4;
private static int startX = screenWidth / 3;
private static int startY = screenHeight /3;
private static JFrame frame;
private static JPanel contentPane;
/////////////////////////////////////////////////////
private MainFrame(){}
public static void init(String title)
{
frame = new JFrame(title);
frame.setLocation(new Point(startX,startY));
contentPane = (JPanel)frame.getContentPane();
contentPane.setPreferredSize(new Dimension(width,height));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void init(String title,int w,int h,int x,int y)
{
width = w;
height = h;
startX = x;
startY = y;
init(title);
}
public static void init(String title,int w,int h,int x,int y,String lookAndFeel)
{
try
{
if(lookAndFeel.equalsIgnoreCase("windows"))
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
else if(lookAndFeel.equalsIgnoreCase("system"))
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
else if(lookAndFeel.equalsIgnoreCase("motif"))
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
else UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}
catch(Exception e){}
width = w;
height = h;
startX = x;
startY = y;
init(title);
}
//////////////////////////////////////////////////////////////////////
public static void start()
{
frame.pack();
frame.setVisible(true);
}
////////////////////////////////////////////////////////////////////
public static JPanel getContentPane()
{
return contentPane;
}
public static JFrame getMainFrame()
{
return frame;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -