📄 ui.java
字号:
package hartech.kids.huffman;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import hartech.ui.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Website: www.hartech.cn </p>
* <p>Page: http://www.hartech.cn/blog/blogview.asp?logID=87 </p>
* <p>Date: 2006-09-07 </p>
*/
public class UI extends JPanel {
private static final long serialVersionUID = -915854684667413368L;
static JPanel jpanel, jpanel_east;
static JTextArea jtextArea_text, jtextArea_code;
static JButton jbutton_code, jbutton_decode, jbutton_showHuffmanTree,
jbutton_showCodes, jbutton_showFrequency;
public UI() {
super(new BorderLayout());
// add
add(jpanel(), BorderLayout.CENTER);
add(jpanel_east(), BorderLayout.EAST);
}
static JPanel jpanel() {
jtextArea_text = new JTextArea();
jtextArea_text.setLineWrap(true);
jtextArea_text.setBorder(BorderFactory.createEmptyBorder(2, 5, 0, 0));
JScrollPane jScrollPane_text = new JScrollPane(jtextArea_text);
jtextArea_text.setText(Main.default_text);
jtextArea_code = new JTextArea();
jtextArea_code.setLineWrap(true);
jtextArea_code.setBorder(BorderFactory.createEmptyBorder(2, 5, 0, 0));
JScrollPane jScrollPane_code = new JScrollPane(jtextArea_code);
jbutton_code = new JButton("编码 ↓");
;
jbutton_code.addActionListener(new ActionListener_buttons());
jbutton_code.setActionCommand("encode");
jbutton_decode = new JButton("译码 ↑");
jbutton_decode.addActionListener(new ActionListener_buttons());
jbutton_decode.setActionCommand("decode");
jpanel = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.weightx = 1.0;
c.weighty = 1.0;
c.gridwidth = 3;
c.gridheight = 1;
c.gridx = 0;
c.gridy = 0;
jpanel.add(jScrollPane_text, c);
c.gridwidth = 1;
c.gridheight = 1;
c.gridx = 1;
c.gridy = 1;
jpanel.add(jbutton_code, c);
c.gridwidth = 1;
c.gridheight = 1;
c.gridx = 2;
c.gridy = 1;
jpanel.add(jbutton_decode, c);
c.gridx = 0;
c.gridy = 2;
c.gridwidth = 3;
c.gridheight = 1;
jpanel.add(jScrollPane_code, c);
return jpanel;
}
static JPanel jpanel_east() {
jbutton_showHuffmanTree = new JButton("显示哈夫曼树");
jbutton_showHuffmanTree.addActionListener(new ActionListener_buttons());
jbutton_showHuffmanTree.setActionCommand("tree");
jbutton_showCodes = new JButton("显示编码表");
jbutton_showCodes.addActionListener(new ActionListener_buttons());
jbutton_showCodes.setActionCommand("codes");
jbutton_showFrequency = new JButton("显示字母频率");
jbutton_showFrequency.addActionListener(new ActionListener_buttons());
jbutton_showFrequency.setActionCommand("fres");
jpanel_east = new JPanel(new GridLayout(3, 1));
jpanel_east.add(jbutton_showHuffmanTree);
jpanel_east.add(jbutton_showCodes);
jpanel_east.add(jbutton_showFrequency);
return jpanel_east;
}
static void createDialog(String in, int with, int high) {
Dialog dialog = new JDialog(Main.jFrame, false);
JTextArea jtextArea = new JTextArea(in);
jtextArea.setBorder(BorderFactory.createEmptyBorder(2, 5, 0, 0));
JScrollPane jScrollPane = new JScrollPane(jtextArea);
dialog.add(jScrollPane, BorderLayout.CENTER);
//dialog.pack();
dialog.setSize(with, high);
J.goCenter(dialog);
dialog.setVisible(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -