找找找,找你妹啊! 没错就是找,这里写一个查找功能:
查询界面
相比其他界面,查询有点麻烦。但是界面切换和基本思想还是一致的。只是返回的时候将所查询得到的集合返回出来,用这个集合中的数组来新建一个listPanel的构建函数,并显示出来。重要的是在Myset中写的query方法。这里界面写法区别不大。
查询界面图:
返回按钮还是返回list界面。而查询则是根据返回值去list界面重新构造一个list。
具体表现层的代码如下:
/*
* QueryPanel.java
*
* Created on __DATE__, __TIME__
*/
package cn.hncu.ui;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import cn.hncu.busines.Myset;
/**
*
* @author __USER__
*/
public class QueryPanel extends javax.swing.JPanel {
private JFrame mainFrame = null;
/** Creates new form QueryPanel */
public QueryPanel(JFrame mainFrame) {
this.mainFrame = mainFrame;
initComponents();
setBack();
}
private void setBack() {
this.setOpaque(false);
Icon image=new ImageIcon("./image/query.jpg");
JLabel imageLbl=new JLabel(image);
this.add(imageLbl);
imageLbl.setBounds(0, 0, 800, 600);
}
/** 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.
*/
//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
tfdName = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
tfdAge = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
tfdAddress = new javax.swing.JTextField();
btnQuery = new javax.swing.JButton();
btnBack = new javax.swing.JButton();
setMinimumSize(new java.awt.Dimension(800, 600));
setLayout(null);
jLabel1.setFont(new java.awt.Font("Microsoft YaHei UI", 3, 36));
jLabel1.setText("\u67e5\u8be2\u8054\u7cfb\u4eba");
add(jLabel1);
jLabel1.setBounds(260, 30, 200, 50);
jLabel2.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 24));
jLabel2.setText("\u59d3\u540d:");
add(jLabel2);
jLabel2.setBounds(130, 100, 60, 60);
add(tfdName);
tfdName.setBounds(210, 110, 250, 40);
jLabel3.setFont(new java.awt.Font("Microsoft YaHei UI", 3, 24));
jLabel3.setText("\u5e74\u9f84:");
add(jLabel3);
jLabel3.setBounds(120, 190, 70, 30);
add(tfdAge);
tfdAge.setBounds(210, 180, 250, 40);
jLabel4.setFont(new java.awt.Font("Microsoft YaHei UI", 3, 24));
jLabel4.setText("\u5730\u5740\uff1a");
add(jLabel4);
jLabel4.setBounds(120, 250, 72, 40);
add(tfdAddress);
tfdAddress.setBounds(210, 250, 320, 40);
btnQuery.setBackground(new java.awt.Color(255, 102, 0));
btnQuery.setFont(new java.awt.Font("Microsoft YaHei UI", 2, 36));
btnQuery.setForeground(new java.awt.Color(153, 153, 255));
btnQuery.setText("\u67e5\u8be2");
btnQuery.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnQueryActionPerformed(evt);
}
});
add(btnQuery);
btnQuery.setBounds(110, 370, 130, 50);
btnBack.setBackground(new java.awt.Color(204, 204, 255));
btnBack.setFont(new java.awt.Font("Microsoft YaHei UI", 3, 36));
btnBack.setForeground(new java.awt.Color(0, 204, 255));
btnBack.setText("\u8fd4\u56de");
btnBack.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnBackActionPerformed(evt);
}
});
add(btnBack);
btnBack.setBounds(400, 370, 140, 50);
}// </editor-fold>
//GEN-END:initComponents
private void btnQueryActionPerformed(java.awt.event.ActionEvent evt) {
String name=tfdName.getText();
String age=tfdAge.getText();
String address=tfdAddress.getText();
Myset set=new Myset();
Object objs[]=set.query(name,age,address);
mainFrame.setContentPane(new listPanel(mainFrame,objs));
mainFrame.validate();
}
private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {
mainFrame.setContentPane(new listPanel(mainFrame));
mainFrame.validate();
}
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JButton btnBack;
private javax.swing.JButton btnQuery;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JTextField tfdAddress;
private javax.swing.JTextField tfdAge;
private javax.swing.JTextField tfdName;
// End of variables declaration//GEN-END:variables
}