📄 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 + -