📄 mainframe.java
字号:
/*
* MainFrame.java
*
* Created by ZZ ,on 2007年12月18日, 下午3:19
*/
package olts.ui;
import java.awt.BorderLayout;
import java.awt.Point;
import javax.swing.JButton;
import javax.swing.*;
import olts.application.*;
import java.util.*;
import java.awt.Dimension;
import olts.database.*;
import olts.persistent.*;
/**
*
* @author ZZ
* @version 1.0
*/
public class MainFrame extends javax.swing.JFrame {
// 变量声明
private javax.swing.JSeparator jSeparator1;
private javax.swing.JSeparator jSeparator2;
private javax.swing.JSeparator jSeparator3;
private javax.swing.JSeparator jSeparator4;
private javax.swing.JSeparator jSeparator5;
private javax.swing.JSeparator jSeparator6;
private javax.swing.JSeparator jSeparator7;
private javax.swing.JMenu mbMenuForHelp;
private javax.swing.JMenu mbMenuForOperation;
private javax.swing.JMenuBar menuBar;
private javax.swing.JMenuItem menuItemForAbout;
private javax.swing.JMenuItem menuItemForExit;
private javax.swing.JMenuItem menuItemForHelp;
private javax.swing.JMenuItem menuItemForMaintain;
private javax.swing.JMenuItem menuItemForTest;
private javax.swing.JButton tbButtonForExit;
private javax.swing.JButton tbButtonForHelp;
private javax.swing.JButton tbButtonForMaintain;
private javax.swing.JButton tbButtonForTest;
private javax.swing.JToolBar toolBar;
private javax.swing.JPanel workplacePanel;
// 变量声明结束//GEN-END:variables
//自己添加到变量
private FilterPanel panelFilter ;//筛选面板
private TestingPanel panelTesting ;//测试面板
private MaintainPanel panelMaintain ;//维护面板
private boolean flagToTesting ;//是否在执行测试功能
public ItemLibrary itemLib;//试题库
private List itemBuf = null;//试题缓存区
private int itemBufIndex = 0;//缓存指针
private String filterCondition;//抽取的条件
private int diff;//条件中的难度
private String type;//条件中的类型
private Item newItem;//暂存一条新的试题
private int itemId;
private Item oldItem;//暂存一个旧的试题
private boolean isAddOrUpdateSuc ;//标识增加或者更新是否成功
private boolean isPickUpStatus;//标识指示抽取是否成功了
/**
* Creates new form MainFrame
*/
public MainFrame(ItemLibrary il) {
initComponents();
this.itemLib = il;
this.setLocation(new Point(300,200));
this.toolBar.setFloatable(false);
this.menuItemForAbout.setText("about");
this.menuItemForHelp.setText("帮助");
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">//GEN-BEGIN:initComponents
private void initComponents() {
toolBar = new javax.swing.JToolBar();
tbButtonForTest = new javax.swing.JButton();
jSeparator3 = new javax.swing.JSeparator();
tbButtonForMaintain = new javax.swing.JButton();
jSeparator2 = new javax.swing.JSeparator();
tbButtonForExit = new javax.swing.JButton();
jSeparator1 = new javax.swing.JSeparator();
tbButtonForHelp = new javax.swing.JButton();
jSeparator4 = new javax.swing.JSeparator();
workplacePanel = new javax.swing.JPanel();
menuBar = new javax.swing.JMenuBar();
mbMenuForOperation = new javax.swing.JMenu();
menuItemForTest = new javax.swing.JMenuItem();
jSeparator6 = new javax.swing.JSeparator();
menuItemForMaintain = new javax.swing.JMenuItem();
jSeparator5 = new javax.swing.JSeparator();
menuItemForExit = new javax.swing.JMenuItem();
mbMenuForHelp = new javax.swing.JMenu();
menuItemForAbout = new javax.swing.JMenuItem();
jSeparator7 = new javax.swing.JSeparator();
menuItemForHelp = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("\u8054\u673a\u6d4b\u8bd5\u7cfb\u7edf ");
toolBar.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
tbButtonForTest.setIcon(new javax.swing.ImageIcon(getClass().getResource("/olts/resource/qing_big.png")));
tbButtonForTest.setText("\u8054\u673a\u6d4b\u8bd5");
tbButtonForTest.setToolTipText("\u5355\u51fb\u8fdb\u884c\u6d4b\u8bd5");
tbButtonForTest.setBorder(null);
tbButtonForTest.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tbButtonForTestActionPerformed(evt);
}
});
toolBar.add(tbButtonForTest);
jSeparator3.setOrientation(javax.swing.SwingConstants.VERTICAL);
toolBar.add(jSeparator3);
tbButtonForMaintain.setIcon(new javax.swing.ImageIcon(getClass().getResource("/olts/resource/leizhenyu_big.png")));
tbButtonForMaintain.setText("\u8bd5\u9898\u7ef4\u62a4");
tbButtonForMaintain.setToolTipText("\u5355\u51fb\u8fdb\u884c\u8bd5\u9898\u7ef4\u62a4");
tbButtonForMaintain.setBorder(null);
tbButtonForMaintain.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tbButtonForMaintainActionPerformed(evt);
}
});
toolBar.add(tbButtonForMaintain);
jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL);
toolBar.add(jSeparator2);
tbButtonForExit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/olts/resource/xiaoxue_big.png")));
tbButtonForExit.setText("\u9000\u51fa");
tbButtonForExit.setToolTipText("\u5355\u51fb\u9000\u51fa\u672c\u7cfb\u7edf");
tbButtonForExit.setBorder(null);
tbButtonForExit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tbButtonForExitActionPerformed(evt);
}
});
toolBar.add(tbButtonForExit);
jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);
toolBar.add(jSeparator1);
tbButtonForHelp.setIcon(new javax.swing.ImageIcon(getClass().getResource("/olts/resource/wu_big.png")));
tbButtonForHelp.setText("\u5e2e\u52a9");
tbButtonForHelp.setToolTipText("\u67e5\u770b\u5e2e\u52a9");
tbButtonForHelp.setBorder(null);
tbButtonForHelp.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tbButtonForHelpActionPerformed(evt);
}
});
toolBar.add(tbButtonForHelp);
jSeparator4.setOrientation(javax.swing.SwingConstants.VERTICAL);
toolBar.add(jSeparator4);
workplacePanel.setBorder(javax.swing.BorderFactory.createTitledBorder("\u5de5\u4f5c\u533a"));
javax.swing.GroupLayout workplacePanelLayout = new javax.swing.GroupLayout(workplacePanel);
workplacePanel.setLayout(workplacePanelLayout);
workplacePanelLayout.setHorizontalGroup(
workplacePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 527, Short.MAX_VALUE)
);
workplacePanelLayout.setVerticalGroup(
workplacePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 282, Short.MAX_VALUE)
);
menuBar.setBorder(javax.swing.BorderFactory.createEtchedBorder());
mbMenuForOperation.setText("\u64cd\u4f5c");
menuItemForTest.setText("\u8054\u673a\u6d4b\u8bd5");
menuItemForTest.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menuItemForTestActionPerformed(evt);
}
});
mbMenuForOperation.add(menuItemForTest);
mbMenuForOperation.add(jSeparator6);
menuItemForMaintain.setText("\u8bd5\u9898\u7ef4\u62a4");
menuItemForMaintain.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menuItemForMaintainActionPerformed(evt);
}
});
mbMenuForOperation.add(menuItemForMaintain);
mbMenuForOperation.add(jSeparator5);
menuItemForExit.setText("\u9000\u51fa");
menuItemForExit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menuItemForExitActionPerformed(evt);
}
});
mbMenuForOperation.add(menuItemForExit);
menuBar.add(mbMenuForOperation);
mbMenuForHelp.setText("\u5e2e\u52a9");
menuItemForAbout.setText("Item");
menuItemForAbout.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menuItemForAboutActionPerformed(evt);
}
});
mbMenuForHelp.add(menuItemForAbout);
mbMenuForHelp.add(jSeparator7);
menuItemForHelp.setText("Item");
menuItemForHelp.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menuItemForHelpActionPerformed(evt);
}
});
mbMenuForHelp.add(menuItemForHelp);
menuBar.add(mbMenuForHelp);
setJMenuBar(menuBar);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(workplacePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(149, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(workplacePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void tbButtonForHelpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tbButtonForHelpActionPerformed
// TODO 将在此处添加您的处理代码:
this.showHelp();
}//GEN-LAST:event_tbButtonForHelpActionPerformed
private void menuItemForHelpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemForHelpActionPerformed
// TODO 将在此处添加您的处理代码:
this.showHelp();
//JOptionPane.showMessageDialog(this,e.toString());
}//GEN-LAST:event_menuItemForHelpActionPerformed
private void menuItemForAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemForAboutActionPerformed
// TODO 将在此处添加您的处理代码:
this.showAbout();
}//GEN-LAST:event_menuItemForAboutActionPerformed
private void menuItemForExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemForExitActionPerformed
// TODO 将在此处添加您的处理代码:
System.exit(0);
}//GEN-LAST:event_menuItemForExitActionPerformed
private void menuItemForMaintainActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemForMaintainActionPerformed
// TODO 将在此处添加您的处理代码:
this.toMaintain();
}//GEN-LAST:event_menuItemForMaintainActionPerformed
private void tbButtonForMaintainActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tbButtonForMaintainActionPerformed
// TODO 将在此处添加您的处理代码:
this.toMaintain();
}//GEN-LAST:event_tbButtonForMaintainActionPerformed
private void menuItemForTestActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemForTestActionPerformed
// TODO 将在此处添加您的处理代码:
this.toTesting();
}//GEN-LAST:event_menuItemForTestActionPerformed
private void tbButtonForExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tbButtonForExitActionPerformed
// TODO 将在此处添加您的处理代码:
System.exit(0);
}//GEN-LAST:event_tbButtonForExitActionPerformed
private void tbButtonForTestActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tbButtonForTestActionPerformed
// TODO 将在此处添加您的处理代码:
this.toTesting();
}//GEN-LAST:event_tbButtonForTestActionPerformed
/**
* 测试
*/
public static void main(String args[]) {
// 测试之~
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};";
url += "DBQ=./db.mdb";
DatabaseUtil du = null;
ItemMapper im = null;
final ItemLibrary ilib;
ItemFactory ifc = null;
try{
//测试连接
du = new DatabaseUtil(driver,url,"","");
im = new ItemMapper(du);
ifc = new OltsItemFactory();
ilib = new ItemLibrary(im, ifc);
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainFrame(ilib).setVisible(true);
}
});
}catch(Exception e){
System.out.println(e);
}finally {
if (du != null ){
try{
du.close();
}catch(Exception e){
System.out.println(e);
}
}
}
}
/** 设置抽取的结果,如果成功从题库里抽取了一条题目,该处应该传入false*/
public void setPickUpStatus(boolean suc){
this.isPickUpStatus = suc;
}
/**得到上次抽取试题的状态,如果抽取成功了,则返回true,反之为false*/
public boolean getPickUpStatus(){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -