?? informationlist.java
字號:
import java.io.*;
public class InformationList implements java.io.Serializable
{
private Information first;
private int size;
public InformationList()
{
first=new Information();
first.setNext(null);
size=0;
}
public InformationList(Information element)
{
first.setNext(element);
size++;
}
public void insert(Information obj)
{
Information p=first;
while(p.getNext()!=null&&p.getNext().getScore()>obj.getScore())
{
p=p.getNext();
}
obj.setNext(p.getNext());
p.setNext(obj);
size++;
}
public Information search(int index)
{
//System.out.println("in search()");
Information result=this.first;
int p=0;
while(p<index)
{
result=result.getNext();
p++;
}
return result;
}
public void delete()
{
Information p=first.getNext();
while(p!=null)
{
Information temp=p;
p=p.getNext();
temp.setNext(null);
temp=null;
}
first.setNext(null);
}
public int getSize()
{
return this.size;
}
public Information getFirst()
{
return this.first;
}
public void displayList()
{
Information p=first.getNext();
int i=1;
while(p!=null&&i<=this.size)
{
//System.out.println("Rand"+i+" :"+p.getUserName()+" Score: "+p.getScore());
p=p.getNext();
i++;
}
}
public void writeBack()
{
Information p=first.getNext();
//System.out.println("Here in writeBack");
try{
ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream("score.friend"));
while(p!=null)
{
out.writeObject(p);
p=p.getNext();
}
out.close();
}catch(Exception e)
{
// System.out.println("Here in writeBack error");
}
}
public void reLive()
{
// System.out.println("Here in reLive");
ObjectInputStream in=null;
try{
in=new ObjectInputStream(new FileInputStream("score.friend"));
//System.out.println("Here in reLive34444433");
while(true)
{
//System.out.println("Here in reLive333333");
Information temp=(Information)in.readObject();
//System.out.println("Name:"+temp.getUserName()+" "+temp.getScore());
this.insert(temp);
}
//in.close();
}catch(EOFException e)
{
System.out.println("Here in reLive error");
if(in!=null)
try{
in.close();
}catch(IOException ev)
{
System.out.println(ev);
}
}catch(ClassNotFoundException classNotFound)
{
}catch(IOException ioException)
{
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -