📄 addstudentnode.java
字号:
/*
* AddStudentNode.java
*
* Created on 2008年4月2日, 下午9:18
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package finaltest;
/**
*
* @author Administrator
*/
public class AddStudentNode {
StudentNode mynode;
static AddStudentNode addmynode;
/** Creates a new instance of AddStudentNode */
public AddStudentNode(int row) {
mynode = new StudentNode();
mynode.student = new Student();
StudentNode nodetemp = StudentNode.head;
if(StudentNode.head==null){
StudentNode.head = mynode;
StudentNode.rear = mynode;
StudentNode.itemnow++;
//System.out.println("null");
}else{
for(int i =0;i<row &&nodetemp!=null;i++)
nodetemp =nodetemp.next;
if(row==0){
mynode.next =nodetemp;
nodetemp.prev =mynode;
StudentNode.head =mynode;
StudentNode.itemnow++;
//System.out.println("111");
}else if((row==1 && StudentNode.head==StudentNode.rear)||nodetemp==null){
StudentNode.rear.next =mynode;
mynode.prev =StudentNode.rear;
StudentNode.rear =mynode;
StudentNode.itemnow++;
//System.out.println("22");
}else{
mynode.next =nodetemp;
nodetemp.prev.next =mynode;
mynode.prev =nodetemp.prev;
nodetemp.prev =mynode;
StudentNode.itemnow++;
//System.out.println("hao");
}
}
//StudentNode.refreshTable(jTable1);
}
public AddStudentNode(){
mynode = new StudentNode();
mynode.student = new Student();
if(StudentNode.head==null){
StudentNode.head = mynode;
StudentNode.rear = mynode;
}else {
StudentNode.rear.next =mynode;
mynode.prev =StudentNode.rear;
StudentNode.rear =mynode;
}
}
public boolean nodeSetId(String id){
int len=id.length();
if(len<1||len>9){ //最大只有十位。
return false;
}
for(int i=0;i<len;i++){
char ch=id.charAt(i); //取出第i个字符检测
if(ch<'0'||ch>'9'){
return false;
}
}
mynode.student.setId(id);
return true;
}
public boolean nodeSetName(String name){
int len=name.length();
if(len>20||len<1){ //限制位20位
return false;
}
for(int i=0;i<len;i++){
char ch=name.charAt(i);
if( !( (ch>='A'&&ch<='Z')||(ch>='a'&&ch<='z') ) ){
return false;
}//if
}//for
mynode.student.setName(name);
return true;
}
public boolean nodeSetSex(String sex){
if(sex!=null){
mynode.student.setSex(sex);
return true;
}else
return false;
}
public boolean nodeSetAge(String age){
int len=age.length();
if(len<1||len>9){ //int型最大只有十位。
return false;
}
for(int i=0;i<len;i++){
char ch=age.charAt(i); //取出第i个字符检测
if(ch<'0'||ch>'9'){
return false;
}
}
int i =Integer.valueOf(age);
if(i<1||i>100)return false;
mynode.student.setAge(i);
return true;
}
public boolean nodeSetMajor(String major){
if(major!=null){
mynode.student.setMajor(major);
return true;
}else
return false;
}
public boolean nodeSetMyclass(String myclass){
int len=myclass.length();
if(len!=4){ //最大只有十位。
return false;
}
for(int i=0;i<len;i++){
char ch=myclass.charAt(i); //取出第i个字符检测
if(ch<'0'||ch>'9'){
return false;
}
}
mynode.student.setMyclass(myclass);
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -