📄 countrytest.java
字号:
package com.bemjh.sort;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.border.TitledBorder;
import java.awt.Dimension;
import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.*;
import java.io.*;
import com.bemjh.Shape.*;
import com.bemjh.util.*;
import javax.swing.BorderFactory;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.ListSelectionEvent;
import java.awt.Color;
import java.awt.SystemColor;
import java.text.Format;
/**
* <p>Title: Sort</p>
*
* <p>Description: Sort adopt Strategy</p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author bemjh
* @version 1.0
*/
public class CountryTest extends JFrame{
/**
* 程序构造函数,调用初始化函数
*/
public CountryTest() {
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
/**
* 程序入口点
* @param args
*/
public static void main(String[] args) {
CountryTest countrytest = new CountryTest();
}
/**
* 初始化各组件
* @throws Exception
*/
private void jbInit() throws Exception {
this.getContentPane().setLayout(xYLayout1);
this.setJMenuBar(jMenuBar1);
TabbedPane.setTabPlacement(JTabbedPane.RIGHT);
TabbedPane.setDebugGraphicsOptions(0);
addButton.addMouseListener(new CountryTest_addButton_mouseAdapter(this));
deleteButton.addMouseListener(new CountryTest_deleteButton_mouseAdapter(this));
searchButton.addMouseListener(new CountryTest_searchButton_mouseAdapter(this));
browseButton.addMouseListener(new CountryTest_browseButton_mouseAdapter(this));
sortButton.addMouseListener(new CountryTest_sortButton_mouseAdapter(this));
openFileMenuItem.addActionListener(new openFileActionListener());
saveFileMenuItem.addActionListener(new saveFileActionListener());
closeFileMenuItem.addActionListener(new closeFileActionListener());
exitMenuItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
int sel = JOptionPane.showConfirmDialog(null,
"真要要退出程序吗?",
"退出提示",
JOptionPane.YES_NO_OPTION);
if(sel == JOptionPane.YES_OPTION){
System.exit(0);
}
}
});
browseMenuItem.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent event){
TabbedPane.setSelectedIndex(3);
}
});
searchMenuItem.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent event){
TabbedPane.setSelectedIndex(0);
}
});
deleteMenuItem.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent event){
TabbedPane.setSelectedIndex(1);
}
});
addMenuItem.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent event){
TabbedPane.setSelectedIndex(4);
}
});
sortMenuItem.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent event){
TabbedPane.setSelectedIndex(2);
}
});
countMenuItem.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent event){
JOptionPane.showMessageDialog(null,"一共有: "+countryList.size()+" 条记录","统计",1,null);
}
});
aboutAuthorMenuItem1.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent event){
CarShape cs = new CarShape(0,0,20);
ShapeIcon si = new ShapeIcon(cs,30,30);
Util.showMessageDialog("关于作者","制作人:马建华 开发日期:2006-11-25",si);
}
});
addCountryButton.addMouseListener(new
CountryTest_addCountryButton_mouseAdapter(this));
searchCountryButton.addMouseListener(new
CountryTest_searchCountryButton_mouseAdapter(this));
delCountryButton.addMouseListener(new
CountryTest_delCountryButton_mouseAdapter(this));
sortCountryButton.addMouseListener(new
CountryTest_sortCountryButton_mouseAdapter(this));
firstRecordButton.addMouseListener(new
CountryTest_firstRecordButton_mouseAdapter(this));
priorRecordButton.addMouseListener(new
CountryTest_priorRecordButton_mouseAdapter(this));
nextRecordButton.addMouseListener(new
CountryTest_nextRecordButton_mouseAdapter(this));
lastRecordButton.addMouseListener(new
CountryTest_lastRecordButton_mouseAdapter(this));
displayList.addListSelectionListener(new DisplayListSelectionListener());
sortMenu.setText("排序");
sortByNameMenuItem.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent event){
Comparator comp = new SortByName(true);
Collections.sort(countryList,comp);
dataChangeActionListener();
}
});
sortByAreaMenuItem.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent event){
Comparator comp = new SortByArea(true);
Collections.sort(countryList,comp);
dataChangeActionListener();
}
});
sortByPopuMenuItem.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent event){
Comparator comp = new SortByPoPulation(true);
Collections.sort(countryList,comp);
dataChangeActionListener();
}
});
displayList.setBorder(BorderFactory.createEtchedBorder());
displayList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
statusTextField.setBackground(SystemColor.inactiveCaptionText);
statusTextField.setBorder(BorderFactory.createLoweredBevelBorder());
searchPanel.setBorder(BorderFactory.createEtchedBorder());
this.getContentPane().add(headPanel, new XYConstraints(0, 0, 432, 29));
headPanel.setLayout(xYLayout2);
fileMenu.setText("文件");
openFileMenuItem.setText("打开文件");
saveFileMenuItem.setText("保存文件");
saveFileMenuItem.setEnabled(false);
closeFileMenuItem.setText("关闭文件");
closeFileMenuItem.setEnabled(false);
exitMenuItem.setText("退出");
operateMenu.setText("操作");
browseMenuItem.setText("浏览");
searchMenuItem.setText("查找");
deleteMenuItem.setText("删除");
addMenuItem.setText("添加");
printMenuItem.setText("打印");
countMenuItem.setText("统计");
sortMenuItem.setText("排序");
systemMenu.setText("系统");
configMenuItem.setText("配置");
helpMenu.setText("帮助");
aboutAuthorMenuItem1.setText("关于作者");
helpFileMenuItem1.setText("帮助文件");
ToolBar.setBorder(null);
ToolBar.setDebugGraphicsOptions(DebugGraphics.BUFFERED_OPTION);
addButton.setText("添加");
deleteButton.setText("删除");
searchButton.setText("查找");
browseButton.setText("浏览");
sortButton.setText("排序");
bodyPanel.setLayout(xYLayout3);
TabbedPane.setBorder(null);
xYLayout1.setWidth(434);
xYLayout1.setHeight(376);
addPanel.setLayout(xYLayout4);
jLabel1.setText("名字:");
jLabel2.setText("面积:");
jLabel3.setText("人口:");
addCountryButton.setText("添加");
addPanel.setMinimumSize(new Dimension(50, 37));
addPanel.setPreferredSize(new Dimension(50, 37));
jLabel4.setText("名字:");
delPanel.setLayout(xYLayout5);
jLabel5.setText("面积:");
jLabel6.setText("人口:");
delCountryButton.setText("删除");
jLabel7.setText("人口:");
jLabel8.setText("名字:");
jLabel9.setText("面积:");
firstRecordButton.setText("第一条");
browsePanel.setLayout(xYLayout6);
priorRecordButton.setText("上一条");
nextRecordButton.setText("下一条");
lastRecordButton.setText("最后一条");
searchPanel.setLayout(xYLayout7);
jLabel10.setText("输入要查找的名字:");
searchCountryButton.setText("查询");
sortPanel.setLayout(xYLayout8);
sortByNameRadioButton.setText("按名字");
sortByAreaRadioButton.setText("按面积");
sortByPopuRadioButton.setText("按人口");
isAscendCheckBox.setText("降序显示");
isAscendCheckBox.setSelected(true);
sortGroup1.add(sortByNameRadioButton);
sortGroup1.add(sortByAreaRadioButton);
sortGroup1.add(sortByPopuRadioButton);
sortCountryButton.setText("排序");
sortByNameMenuItem.setText("按名字");
sortByAreaMenuItem.setText("按面积");
sortByPopuMenuItem.setText("按人口");
sortPopupMenu.add(sortByNameMenuItem);
sortPopupMenu.add(sortByAreaMenuItem);
sortPopupMenu.add(sortByPopuMenuItem);
sortGroup.add(sortByNameMenuItem);
sortGroup.add(sortByAreaMenuItem);
sortGroup.add(sortByPopuMenuItem);
sortMenu.add(sortByNameMenuItem);
sortMenu.add(sortByAreaMenuItem);
sortMenu.add(sortByPopuMenuItem);
jMenuBar1.add(fileMenu);
jMenuBar1.add(operateMenu);
jMenuBar1.add(sortMenu);
jMenuBar1.add(systemMenu);
jMenuBar1.add(helpMenu);
fileMenu.add(openFileMenuItem);
fileMenu.add(saveFileMenuItem);
fileMenu.add(closeFileMenuItem);
fileMenu.addSeparator();
fileMenu.add(exitMenuItem);
operateMenu.add(browseMenuItem);
operateMenu.add(searchMenuItem);
operateMenu.add(deleteMenuItem);
operateMenu.add(addMenuItem);
operateMenu.addSeparator();
operateMenu.add(printMenuItem);
operateMenu.add(countMenuItem);
operateMenu.add(sortMenuItem);
systemMenu.add(configMenuItem);
helpMenu.add(aboutAuthorMenuItem1);
helpMenu.add(helpFileMenuItem1);
ToolBar.add(addButton);
ToolBar.add(deleteButton);
ToolBar.add(searchButton);
ToolBar.add(browseButton);
ToolBar.add(sortButton);
addPanel.add(addPopuTextField, new XYConstraints(344, 15, 52, 24));
addPanel.add(addAreaTextField, new XYConstraints(242, 18, 46, 22));
addPanel.add(jLabel3, new XYConstraints(301, 15, 42, 24));
addPanel.add(jLabel1, new XYConstraints(50, 16, 39, 24));
addPanel.add(addNameTextField, new XYConstraints(90, 18, 98, 20));
addPanel.add(jLabel2, new XYConstraints(200, 16, 42, 25));
TabbedPane.add(searchPanel);
headPanel.add(ToolBar, new XYConstraints(0, 0, 279, -1));
delPanel.add(delCountryButton, new XYConstraints(192, 47, 60, 28));
delPanel.add(deletePopuTextField, new XYConstraints(351, 17, 43, 22));
delPanel.add(jLabel4, new XYConstraints(47, 23, -1, -1));
delPanel.add(deleteNameTextField1, new XYConstraints(90, 20, 100, -1));
delPanel.add(jLabel5, new XYConstraints(202, 19, 39, 22));
delPanel.add(deleteAreaTextField, new XYConstraints(248, 19, 42, 22));
TabbedPane.add(delPanel);
browsePanel.add(lastRecordButton, new XYConstraints(308, 45, -1, 22));
browsePanel.add(nextRecordButton, new XYConstraints(233, 45, -1, 22));
browsePanel.add(browsePopuTextField, new XYConstraints(362, 18, 43, -1));
browsePanel.add(jLabel8, new XYConstraints(56, 20, -1, -1));
browsePanel.add(browseNameTextField, new XYConstraints(102, 17, 100, -1));
browsePanel.add(jLabel9, new XYConstraints(213, 21, -1, -1));
browsePanel.add(browseAreaTextField, new XYConstraints(259, 18, 42, -1));
browsePanel.add(jLabel7, new XYConstraints(317, 21, -1, -1));
browsePanel.add(firstRecordButton, new XYConstraints(74, 45, 76, 23));
TabbedPane.add(sortPanel);
searchPanel.add(jLabel10, new XYConstraints(60, 26, 123, 23));
searchPanel.add(searchNameTextField, new XYConstraints(179, 27, 85, -1));
searchPanel.add(searchCountryButton, new XYConstraints(291, 24, 80, -1));
TabbedPane.add(browsePanel);
sortPanel.add(sortCountryButton, new XYConstraints(307, 26, 80, 24));
sortPanel.add(sortByNameRadioButton, new XYConstraints(87, 24, -1, -1));
sortPanel.add(sortByAreaRadioButton, new XYConstraints(159, 24, 74, 24));
sortPanel.add(sortByPopuRadioButton, new XYConstraints(231, 28, 72, 19));
sortPanel.add(isAscendCheckBox, new XYConstraints(159,42,84,42));
TabbedPane.add(addPanel);
this.getContentPane().add(statusTextField,
new XYConstraints(2, 349, 429, 26));
this.getContentPane().add(bodyPanel,
new XYConstraints( -2, 28, 437, 319));
bodyPanel.add(TabbedPane, new XYConstraints(0, 0, 454, 95));
delPanel.add(jLabel6, new XYConstraints(306, 17, 46, 25));
browsePanel.add(priorRecordButton, new XYConstraints(153, 45, 77, 23));
addPanel.add(addCountryButton, new XYConstraints(178, 48, 66, 27));
bodyPanel.add(displayList, new XYConstraints(6, 100, 426, 218));
displayList.add(sortPopupMenu);
TabbedPane.setSelectedIndex(0);
this.setLocation(250,140);
this.setTitle("Java的综合应用小示例");
this.setResizable(false);
this.setSize(425,424);
this.setVisible(true);
}
/**
* 工具栏按钮
* 添加按钮的事件
* @param e MouseEvent
*/
public void addButton_mouseClicked(MouseEvent e) {
TabbedPane.setSelectedIndex(4);
}
/**
* 工具栏按钮
* 删除按钮的事件
* @param e MouseEvent
*/
public void deleteButton_mouseClicked(MouseEvent e) {
TabbedPane.setSelectedIndex(1);
}
/**
* 工具栏按钮
*查找按钮的事件
* @param e MouseEvent
*/
public void searchButton_mouseClicked(MouseEvent e) {
TabbedPane.setSelectedIndex(0);
}
/**
* 工具栏按钮
* 浏览按钮的事件
* @param e MouseEvent
*/
public void browseButton_mouseClicked(MouseEvent e) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -