?? searchstudent.java
字號:
/*
* SearchStudent.java
*
* Created on 2008年4月6日, 上午11:35
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package finaltest;
import javax.swing.JTable;
/**
*
* @author Administrator
*/
public class SearchStudent {
static SearchStudent mysearch;
static int table2_num;
/** Creates a new instance of SearchStudent */
public SearchStudent(JTable jTable2, String id, String name, int flag) {
int[] index =new int [StudentNode.itemnow];
int i=0;
//System.out.println("hhhhh");
if(flag==1)
SearchID(jTable2,id);
if(flag==2)
SearchName(jTable2,name);
if(flag==3)
SearchIDAndName(jTable2,id,name);
if(flag==4)
SearchIDOrName(jTable2,id,name);
}
public void SearchID(JTable jTable2, String id){
table2_num =0;
System.out.println("idid!");
System.out.println(id);
for(StudentNode temp =StudentNode.head;temp!=null;temp =temp.next){
if(temp.student.getId().equalsIgnoreCase(id)){
jTable2.setValueAt(temp.student.getId(),table2_num%16,0);
jTable2.setValueAt(temp.student.getName(),table2_num%16,1);
jTable2.setValueAt(temp.student.getSex(),table2_num%16,2);
jTable2.setValueAt(String.valueOf(temp.student.getAge()),table2_num%16,3);
jTable2.setValueAt(temp.student.getMajor(),table2_num%16,4);
jTable2.setValueAt(temp.student.getMyclass(),table2_num%16,5);
table2_num++;
}
}
if(table2_num==0)
System.out.println("nothing found!");
else{
System.out.println("found!");
}
for(int i=table2_num;i<16;i++){
jTable2.setValueAt("",i%16,0);
jTable2.setValueAt("",i%16,1);
jTable2.setValueAt("",i%16,2);
jTable2.setValueAt("",i%16,3);
jTable2.setValueAt("",i%16,4);
jTable2.setValueAt("",i%16,5);
}
}
public void SearchName(JTable jTable2,String name){
table2_num =0;
System.out.println("name!");
for(StudentNode temp =StudentNode.head;temp!=null;temp =temp.next){
if(temp.student.getName().equalsIgnoreCase(name)){
jTable2.setValueAt(temp.student.getId(),table2_num%16,0);
jTable2.setValueAt(temp.student.getName(),table2_num%16,1);
jTable2.setValueAt(temp.student.getSex(),table2_num%16,2);
jTable2.setValueAt(String.valueOf(temp.student.getAge()),table2_num%16,3);
jTable2.setValueAt(temp.student.getMajor(),table2_num%16,4);
jTable2.setValueAt(temp.student.getMyclass(),table2_num%16,5);
table2_num++;
}
}
for(int i=table2_num;i<16;i++){
jTable2.setValueAt("",i%16,0);
jTable2.setValueAt("",i%16,1);
jTable2.setValueAt("",i%16,2);
jTable2.setValueAt("",i%16,3);
jTable2.setValueAt("",i%16,4);
jTable2.setValueAt("",i%16,5);
}
if(table2_num==0)
System.out.println("nothing found!");
else{
System.out.println("found!");
}
}
public void SearchIDAndName(JTable jTable2,String id,String name){
System.out.println("id and name!");
table2_num =0;
System.out.println(id+" "+name+"aa");
for(StudentNode temp =StudentNode.head;temp!=null;temp =temp.next){
if(name.equalsIgnoreCase("")){break;}
if(temp.student.getName().indexOf(name)!=(-1)&&name!=null&&
temp.student.getId().equalsIgnoreCase(id)){
jTable2.setValueAt(temp.student.getId(),table2_num%16,0);
jTable2.setValueAt(temp.student.getName(),table2_num%16,1);
jTable2.setValueAt(temp.student.getSex(),table2_num%16,2);
jTable2.setValueAt(String.valueOf(temp.student.getAge()),table2_num%16,3);
jTable2.setValueAt(temp.student.getMajor(),table2_num%16,4);
jTable2.setValueAt(temp.student.getMyclass(),table2_num%16,5);
table2_num++;
}
}
for(int i=table2_num;i<16;i++){
jTable2.setValueAt("",i%16,0);
jTable2.setValueAt("",i%16,1);
jTable2.setValueAt("",i%16,2);
jTable2.setValueAt("",i%16,3);
jTable2.setValueAt("",i%16,4);
jTable2.setValueAt("",i%16,5);
}
if(table2_num==0)
System.out.println("nothing found!");
else{
System.out.println("found!");
}
}
public void SearchIDOrName(JTable jTable2,String id,String name){
System.out.println("id or name");
table2_num =0;
System.out.println(id+" "+name+"aa");
for(StudentNode temp =StudentNode.head;temp!=null;temp =temp.next){
if(name.equalsIgnoreCase("")){break;}
if((name!=null)&&(temp.student.getName().indexOf(name)!=(-1)||
temp.student.getId().equalsIgnoreCase(id))){
jTable2.setValueAt(temp.student.getId(),table2_num%16,0);
jTable2.setValueAt(temp.student.getName(),table2_num%16,1);
jTable2.setValueAt(temp.student.getSex(),table2_num%16,2);
jTable2.setValueAt(String.valueOf(temp.student.getAge()),table2_num%16,3);
jTable2.setValueAt(temp.student.getMajor(),table2_num%16,4);
jTable2.setValueAt(temp.student.getMyclass(),table2_num%16,5);
table2_num++;
}
}
for(int i=table2_num;i<16;i++){
jTable2.setValueAt("",i%16,0);
jTable2.setValueAt("",i%16,1);
jTable2.setValueAt("",i%16,2);
jTable2.setValueAt("",i%16,3);
jTable2.setValueAt("",i%16,4);
jTable2.setValueAt("",i%16,5);
}
if(table2_num==0)
System.out.println("nothing found!");
else{
System.out.println("found!");
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -