?? searchbookview.java
字號:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.table.DefaultTableModel;
import java.util.Vector;
public class SearchBookView extends JFrame
{
private JTable books;
private Vector colNames;
private Vector data;
JTextField Txt;
JButton findBtn;
JButton borrowBtn;
JPanel jp1,jp2;
JFrame fr=new JFrame("借書模塊");
public SearchBookView(ActionListener aln){
colNames = new Vector();
colNames.add("ID");
colNames.add("Name");
data = new Vector();
Txt=new JTextField(20);
findBtn=new JButton("查找");
borrowBtn=new JButton("借書");
jp1=new JPanel();
jp2=new JPanel();
fr.setLayout(new BorderLayout());
books = new JTable(new DefaultTableModel(data,colNames));//設置選擇模式,這里允許選擇不連續的多行
books.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);//注冊選擇監聽事件
JScrollPane scptable =new JScrollPane(books);
jp1.add(new JLabel("書號/書名:"));
jp1.add(Txt);
jp1.add(findBtn);
jp1.add(borrowBtn);
findBtn.addActionListener(aln);
borrowBtn.addActionListener(aln);
jp2.add(scptable);
fr.add("North",jp1);
fr.add("Center",jp2);
fr.setSize(500,400);
fr.setVisible(true);
}
public String getKey(){
return Txt.getText().trim();
}
public Vector getBookIDs(){
Vector bookIDs = new Vector();
int[] temp = books.getSelectedRows();
for(int i=0;i<temp.length;i++){
bookIDs.add(books.getValueAt(temp[i],0));
System.out.println(temp[i]);
}
return bookIDs;
}
public Vector getBookNames(){
Vector BookNames = new Vector();
int[] temp = books.getSelectedRows();
for(int i=0;i<temp.length;i++){
BookNames.add(books.getValueAt(temp[i],1));
System.out.println(temp[i]);
}
return BookNames;
}
public void showResult(Vector v){
books.setModel(new DefaultTableModel(v,colNames));
books.repaint();
}
//public static void main(String[] args){
//new SearchBookView();
//}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -