📄 mainframe.java
字号:
package GUI;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MainFrame extends JFrame implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
JTabbedPane tabbedPane = null;
JButton help;// The help button
JButton exit;// The exit button
public MainFrame() {
Container container = getContentPane();
// The Panel for compress
JPanel panel1 = new CompressJPanel().getDefaultJPanel();
// The panel for decompress
JPanel panel2 = new DecompressJPanel().getDefaultJPanel();
// The tabbedPanel
tabbedPane = new JTabbedPane();
tabbedPane.setTabPlacement(JTabbedPane.TOP);
tabbedPane.addTab("Compress", panel1);
tabbedPane.addTab("Decompress", panel2);
// Use panel to hold Buttons help and exit
help = new JButton("Help");
exit = new JButton("Exit");
JPanel panel = new JPanel();
panel.add(help);
panel.add(exit);
// Add listener for the buttons help and exit
help.addActionListener(this);
exit.addActionListener(this);
// Add tabbedPanel and panel into the container
container.setLayout(new BorderLayout());
container.add(tabbedPane, BorderLayout.CENTER);
container.add(panel, BorderLayout.SOUTH);
}
public static void main(String[] args) {
MainFrame frame = new MainFrame();
frame.setTitle("Haffman compress and decompress");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 400);
frame.setVisible(true);
frame.setResizable(false);
// Make the frame be in the center of the screen
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int screenWidth = screenSize.width;
int screenHeight = screenSize.height;
int x = (screenWidth - frame.getWidth()) / 2;
int y = (screenHeight - frame.getHeight()) / 2;
frame.setLocation(x, y);
}
// The listener of the buttons "Help" and "Exit"
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("Help")) {
String helpInfo = "Welcome to use this software!!\n";
helpInfo += " Designed By Lin Ling\n\n";
helpInfo += "\"Compress\" tag is for the compress function \n\n 1,click \"select\" button to choose the file which needs to be compressed\n";
helpInfo += " 2,click \"compress to...\" button to choose the folder which is the target file\n";
helpInfo += " 3,click \"OK\" button to begin the process\n";
helpInfo += " 4,when the compression is finished, the area \"status\" will show the time of the compression \n\n";
helpInfo += "\"Decompress\" tag is for the decompress function \n\n 1,click \"select\" button to choose the file which needs to be decompressed\n";
helpInfo += " (Attention:only the file with the suffix \'~\' is allowed )\n";
helpInfo += " 2,click \"decompress to...\" button to choose the folder which is the target file\n";
helpInfo += " 3,click \"OK\" button to begin the process\n";
helpInfo += " 4,when the decompression is finished, the area \"status\" will show the time of the decompression \n\n";
helpInfo += " ";
JOptionPane.showMessageDialog(null, helpInfo,
"HaffmanTree compress and decompress",
JOptionPane.INFORMATION_MESSAGE);
} else if (e.getActionCommand().equals("Exit")) {
System.exit(0);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -