【Java开源代码栏目提醒】:网学会员--在 Java开源代码编辑为广大网友搜集整理了:BookRetrievalPanel.java绩等信息,祝愿广大网友取得需要的信息,参考学习。
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import java.util.Hashtable;
public class BookRetrievalPanel extends JPanel {
private static final long serialVersionUID = 7617206L;
protected BookDetails bookDetails;
protected BookDetailsDialog bookDetailsDialog;
protected ArrayList<BookDetails> bookArrayList;
protected JLabel selectionLabel;
protected JComboBox fieldComboBox;// 检索方式选项
protected JTextField keywordText;// 检索关键词
protected JPanel topPanel;
protected JList bookListBox;
protected JScrollPane bookScrollPane;
protected JButton retrievalButton;
protected JButton detailsButton;
protected JPanel bottomPanel;
protected MainFrame parentFrame;
protected String retrievalField;// 检索方式值
public BookRetrievalPanel(MainFrame theParentFrame) {
parentFrame = theParentFrame;
this.setLayout(new BorderLayout());
selectionLabel = new JLabel("检索方式"); // 标签
fieldComboBox = new JComboBox(); // 分类检索下拉列表
fieldComboBox.addItem("请选择...");
fieldComboBox.addItem("书名");
fieldComboBox.addItem("ISBN号");
fieldComboBox.addItem("作者");
fieldComboBox.addItem("出版");
fieldComboBox.addItemListener(new FieldSelectedListener());
keywordText = new JTextField("java", 20); // 关键字
keywordText.addMouseListener(new KeywordClickedListener());
keywordText.addKeyListener(new KeywodKeyListener());
retrievalButton = new JButton("检索");
retrievalButton.addActionListener(new RetrievalActionListener());
topPanel = new JPanel();
topPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
keywordText.setSize(topPanel.getWidth() / 2, topPanel.getWidth());
topPanel.add(selectionLabel);
topPanel.add(fieldComboBox);
topPanel.add(keywordText);
topPanel.add(retrievalButton);
this.add(BorderLayout.NORTH, topPanel);
bookListBox = new JList();
bookListBox.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
bookListBox.addListSelectionListener(new BookSelectionListener());
bookListBox.addMouseListener(new BookListMouseClickListener());
bookScrollPane = new JScrollPane(bookListBox);
this.add(BorderLayout.CENTER, bookScrollPane);
detailsButton = new JButton("详细...");
detailsButton.addActionListener(new DetailsActionListener());
detailsButton.setEnabled(false);
bottomPanel = new JPanel();
bottomPanel.setLayout(new FlowLayout());
bottomPanel.add(detailsButton);
this.add(BorderLayout.SOUTH, bottomPanel);
}
protected void ProcessBookList(String theField, String theKeyword) {
try {
bookArrayList = MainFrame.globalClient.getBookList(theField,
theKeyword);
if (bookArrayList.size() > 0) {
Object[] theData = bookArrayList.toArray();
bookListBox.setListData(theData);
} else {
// 没有检索到书的时候,应清空图书
列表区
Object[] noData = new Object[0];
bookListBox.setListData(noData);
fieldComboBox.setSelectedIndex(0);
detailsButton.setEnabled(false);
JOptionPane.showMessageDialog(null, "对不起,没有找到您要的图书!");
}
} catch (IOException e) {
JOptionPane.showMessageDialog(this, "网络故障: " + e, "
网络问题",
JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
}
}
private void DisplayBookDetailsDialog() {
int index = bookListBox.getSelectedIndex();
bookDetails = (BookDetails) bookArrayList.get(index);
bookDetailsDialog = new BookDetailsDialog(parentFrame, bookDetails,
MainFrame.globalClient);
bookDetailsDialog.setVisible(true);
}
private void RetrievalResults() {
Hashtable<String, String> bookHashTable = new Hashtable<String, String>();
bookHashTable.put("书名", "name");
bookHashTable.put("作者", "authors");
bookHashTable.put("出版", "publisher");
bookHashTable.put("ISBN号", "isbn");
if (retrievalField == null || retrievalField.startsWith("请选择")) {
JOptionPane.showMessageDialog(null, "请选择检索方式");
return;
}
String key
word = keywordText.getText();
if (keyword == null || keyword.equals("")) {
JOptionPane.showMessageDialog(null, "检索关键字不能为空");
return;
}
String field = bookHashTable.get(retri