周末作业,写的草草,BUG很多,直接贴代码。
基于文本文档的,不是数据库。
功能极其有限,也没有用WindowBuilder。
教师查询窗口
package wh.one;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import wh.io.ReadStuFromFile;
public class FirstWindow implements ActionListener {
JTextField jxt = null;
JTextArea jta = null;
JFrame f = null;
JComboBox<String> se = new JComboBox<String>();
public void showMyWindow() {
JButton blog = new JButton("select");
JButton bclear = new JButton("clear");
JLabel jl = new JLabel("Select conditon:");
JLabel jl2 = new JLabel("Input:");
se.addItem("choose");
se.addItem("student number");
se.addItem("student name");
jxt = new JTextField("No support for fuzzy query",20);
jta = new JTextArea(10,20);
f = new JFrame("Select");
JPanel p = new JPanel();
p.add(jl);
p.add(se);
p.add(jl2);
p.add(jxt);
p.add(blog);
p.add(bclear);
p.add(jta);
f.add(p,BorderLayout.CENTER);
blog.addActionListener(this);
bclear.addActionListener(this);
jxt.setEditable(false);
se.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
String temp = se.getSelectedItem().toString();
if(temp.equals("student number")) { //Only numbers can input in the jxt
jxt.setEditable(true);
jxt.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
char keyChar = e.getKeyChar();
if(!( (keyChar >= KeyEvent.VK_0 && keyChar <= KeyEvent.VK_9) ||
keyChar == (22&0x1f) /*Ctrl+V(ASCLL CODE) used to paste*/ ||
keyChar == KeyEvent.VK_BACK_SPACE)) {
JOptionPane.showMessageDialog(null,"Only NUMBERS can be input in","Warning",JOptionPane.ERROR_MESSAGE);
e.consume();
jxt.setText("");
}
}
});
}
else if(temp.equals("student name")) { //Only Chinese can input in the jxt
jxt.setEditable(true);
jxt.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
char keyChar = e.getKeyChar();
if( !( ( (keyChar >= '\u4e00' && keyChar <= '\u9fa5') ||
(keyChar >= 'a' && keyChar <= 'z') ||
(keyChar >= 'A' && keyChar <= 'Z') ||
keyChar == KeyEvent.VK_BACK_SPACE ) ) ) {
JOptionPane.showMessageDialog(null,"Only CHINESE or ENGLISH can be input in","Warning",JOptionPane.ERROR_MESSAGE);
e.consume();
jxt.s