📄 application.java
字号:
package app;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.UIManager;
import draw.Draw;
import app.action.Actions;
import app.pane.MenuPane;
import app.pane.PaintPane;
/**
* 主窗口,定义了一些关于程序自身的常量
*
* @author Thihy
*
*/
public class Application extends JFrame {
/**
* 用于DEBUG,会输出大量信息。值越大,则其输出越多
*/
public static final int DEBUG = 0;
public static final String APPNAME = "画图";
public static final String ABOUT_APP = "这是一个用java编写的画图软件。\r\n\r\nCopyright@ 黄兴海 。";
/**
* 保存文件的主后缀名
*/
public static final String viewfileSuffix = "pnt";
protected PaintPane paintPane;
private MenuPane menuPane;
protected Draw draw;
protected Actions actions = new Actions(this);
/**
* 生成窗口
*/
public Application() {
super();
setTitle(Application.APPNAME);
menuPane = new MenuPane(this);
draw = new Draw(this);
paintPane = new PaintPane(draw, this);
add(paintPane, BorderLayout.WEST);
add(draw.getContentPane(), BorderLayout.CENTER);
setJMenuBar(menuPane.getMenuBar());
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
if (getDraw().closeAllViews()) {
dispose();
System.exit(0);
}
}
});
setSize(1000, 600);
moveToCenter();
setVisible(true);
}
/**
* 返回主画板。这个画板中会有多个画布
*
* @return 主画板
*/
public Draw getDraw() {
return draw;
}
/**
* 获取菜单栏
*
* @return 菜单栏
*/
public MenuPane getMenuPane() {
return menuPane;
}
private void moveToCenter() {
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
int screenHeight = screenSize.height;
int screenWidth = screenSize.width;
Dimension frameSize = getSize();
int frameHeight = frameSize.height;
int frameWidth = frameSize.width;
int centerLocationX = (screenWidth - frameWidth) / 2;
int centerLocationY = (screenHeight - frameHeight) / 2;
setLocation(centerLocationX, centerLocationY);
}
/**
* 程序入口
* @param args 程序参数
*/
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager
.getCrossPlatformLookAndFeelClassName());
} catch (Exception exc) {
System.err.println("Error loading L&F: " + exc);
}
try {
System.setProperty("sun.awt.noerasebackground", "true");
} catch (NoSuchMethodError error) {
}
new Application();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -