?? borrower.java
字號:
package client;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
import javax.swing.WindowConstants;
import com.swtdesigner.SwingResourceManager;
import sever.business.iface.ILibrarianInfoIface;
import sever.business.impl.IlibrarianInfoImpl;
import sever.dao.BorrowInfoDAO;
import sever.db.ConnectionDB;
import sever.entity.BookInfo;
public class Borrower extends JFrame{
private JTextArea textArea;
private JTextField textField_1;
private JComboBox comboBox;
private JTextField textField;
private JFrame frame;
ImageIcon image=new ImageIcon("E:\\image\\10.JPG");
ImageIcon image2=new ImageIcon("E:\\image\\11.JPG");
ImageIcon image3=new ImageIcon("E:\\image\\12.JPG");
ImageIcon image4=new ImageIcon("E:\\image\\2.JPG");
ImageIcon image5=new ImageIcon("E:\\image\\7.JPG");
ImageIcon image6=new ImageIcon("E:\\image\\one.JPG");
ResultSet rs;
/**
* Launch the application
* @param args
*/
// public static void main(String args[]) {
// try {
// Borrower window = new Borrower();
// window.setVisible(true);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
public Borrower() {
new JFrame();
getContentPane().setLayout(null);
setTitle("借閱查詢");
getContentPane().setFont(new Font("@黑體", Font.PLAIN, 14));
setBounds(190, 135, 481,479 );
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
final JLabel label = new JLabel();
label.setFont(new Font("@黑體", Font.PLAIN, 14));
label.setText("按書名查詢");
label.setBounds(81, 37, 72, 28);
getContentPane().add(label);
textField = new JTextField();
textField.setBounds(182, 42, 149, 20);
getContentPane().add(textField);
//退出未設置
final JLabel label_1 = new JLabel();
label_1.setFont(new Font("@黑體", Font.PLAIN, 14));
label_1.setText("按類別查詢");
label_1.setBounds(81, 88, 72, 28);
getContentPane().add(label_1);
comboBox = new JComboBox();
comboBox.setFont(new Font("@黑體", Font.PLAIN, 14));
comboBox.setBounds(182, 91, 149, 23);
getContentPane().add(comboBox);
comboBox.addItem("請選擇類別");
comboBox.addItem("計算機類");
comboBox.addItem("經典著作類");
comboBox.addItem("科學教育類");
comboBox.addItem("社會科學類");
comboBox.addItem("哲學類");
comboBox.addItem("文學理論類");
final JLabel label_2 = new JLabel();
label_2.setFont(new Font("@黑體", Font.PLAIN, 14));
label_2.setText("按編號查詢");
label_2.setBounds(81, 143, 72, 28);
getContentPane().add(label_2);
textField_1 = new JTextField();
textField_1.setBounds(182, 148, 149, 20);
getContentPane().add(textField_1);
final JScrollPane scrollPane = new JScrollPane();
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setBounds(20, 249, 430, 111);
getContentPane().add(scrollPane);
final JButton button = new JButton();
button.setText("書名查詢");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(textField.getText().length()==0){
JOptionPane.showMessageDialog(null,"請輸入書名");
}
else{
ConnectionDB db=new ConnectionDB();
try {
BookInfo book=new BookInfo();
book.setBookName(textField.getText().trim());
BorrowInfoDAO bif = new BorrowInfoDAO();
ILibrarianInfoIface face=new IlibrarianInfoImpl();
ResultSet rs=face.borrow(book);
ResultSetMetaData rsm=rs.getMetaData();
int count=rsm.getColumnCount();
Vector row=new Vector();
while(rs.next()){
Vector cell=new Vector();
cell.addElement(rs.getString(1));
cell.addElement(rs.getString(2));
cell.addElement(rs.getString(3));
cell.addElement(rs.getInt(4));
cell.addElement(rs.getInt(5));
cell.addElement(rs.getInt(6));
cell.addElement(rs.getString(7));
cell.addElement(rs.getString(8));
row.addElement(cell);
String []h={"書名","作者","類型","編號","價格","數量","是否完好","入庫時間"};
Vector hh=new Vector();
hh.addElement("書名");
hh.addElement("作者");
hh.addElement("類型");
hh.addElement("編號");
hh.addElement("價格");
hh.addElement("數量");
hh.addElement("是否完好");
hh.addElement("入庫時間");
final JTable table = new JTable(row,hh);
scrollPane.setViewportView(table);
table.setEnabled(false);
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
}
});
button.setFont(new Font("@黑體", Font.PLAIN, 14));
button.setBounds(62, 202, 91, 23);
getContentPane().add(button);
final JScrollPane scrollPane1 = new JScrollPane();
scrollPane1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane1.setBounds(20, 249, 430, 111);
getContentPane().add(scrollPane1);
final JButton button_1 = new JButton();
button_1.setText("類別查詢");
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
BookInfo book=new BookInfo();
book.setBookTypes(comboBox.getSelectedItem().toString().trim());
BorrowInfoDAO bif = new BorrowInfoDAO();
ILibrarianInfoIface face=new IlibrarianInfoImpl();
ResultSet rs=face.lookupType(book);
ResultSetMetaData rsm=rs.getMetaData();
int count=rsm.getColumnCount();
Vector row=new Vector();
while(rs.next()){
Vector cell=new Vector();
cell.addElement(rs.getString(1));
cell.addElement(rs.getString(2));
cell.addElement(rs.getString(3));
cell.addElement(rs.getInt(4));
cell.addElement(rs.getInt(5));
cell.addElement(rs.getInt(6));
cell.addElement(rs.getString(7));
cell.addElement(rs.getString(8));
row.addElement(cell);
String []h={"書名","作者","類型","編號","價格","數量","是否完好","入庫時間"};
Vector hh=new Vector();
hh.addElement("書名");
hh.addElement("作者");
hh.addElement("類型");
hh.addElement("編號");
hh.addElement("價格");
hh.addElement("數量");
hh.addElement("是否完好");
hh.addElement("入庫時間");
final JTable table = new JTable(row,hh);
scrollPane.setViewportView(table);
table.setEnabled(false);
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
});
button_1.setFont(new Font("@黑體", Font.PLAIN, 14));
button_1.setBounds(186, 202, 91, 23);
getContentPane().add(button_1);
final JScrollPane scrollPane2 = new JScrollPane();
scrollPane2.setAutoscrolls(true);
scrollPane2.setDoubleBuffered(true);
scrollPane2.setFocusCycleRoot(true);
scrollPane2.setFocusTraversalPolicyProvider(true);
scrollPane2.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane2.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane2.setBounds(20, 249, 430, 111);
getContentPane().add(scrollPane2);
final JButton button_2 = new JButton();
button_2.setText("編號查詢");
button_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(textField_1.getText().length()==0){
JOptionPane.showMessageDialog(null,"請輸入編號");
}
else{
try {
BookInfo book=new BookInfo();
book.setBookNumber(Integer.parseInt(textField_1.getText().trim()));
BorrowInfoDAO bif = new BorrowInfoDAO();
ILibrarianInfoIface face=new IlibrarianInfoImpl();
ResultSet rs=face.lookupNumber(book);
ResultSetMetaData rsm=rs.getMetaData();
int count=rsm.getColumnCount();
Vector row=new Vector();
while(rs.next()){
Vector cell=new Vector();
cell.addElement(rs.getString(1));
cell.addElement(rs.getString(2));
cell.addElement(rs.getString(3));
cell.addElement(rs.getInt(4));
cell.addElement(rs.getInt(5));
cell.addElement(rs.getInt(6));
cell.addElement(rs.getString(7));
cell.addElement(rs.getString(8));
row.addElement(cell);
String []h={"書名","作者","類型","編號","價格","數量","是否完好","入庫時間"};
Vector hh=new Vector();
hh.addElement("書名");
hh.addElement("作者");
hh.addElement("類型");
hh.addElement("編號");
hh.addElement("價格");
hh.addElement("數量");
hh.addElement("是否完好");
hh.addElement("入庫時間");
final JTable table = new JTable(row,hh);
scrollPane.setViewportView(table);
table.setEnabled(false);
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
}
});
button_2.setFont(new Font("@黑體", Font.PLAIN, 14));
button_2.setBounds(312, 202, 91, 23);
getContentPane().add(button_2);
final JLabel label_3 = new JLabel();
label_3.setFont(new Font("@黑體", Font.PLAIN, 14));
label_3.setText("結 果:");
label_3.setBounds(20, 221, 36, 28);
getContentPane().add(label_3);
final JButton button_3 = new JButton();
button_3.setText("重置");
button_3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textField.setText("");
textField_1.setText("");
}
});
button_3.setFont(new Font("@黑體", Font.PLAIN, 14));
button_3.setBounds(112, 366, 69, 25);
getContentPane().add(button_3);
final JButton button_4 = new JButton();
button_4.setText("取消");
button_4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
button_4.setFont(new Font("@黑體", Font.PLAIN, 14));
button_4.setBounds(283, 366, 69, 25);
getContentPane().add(button_4);
getContentPane().setBackground(new Color(224, 235, 237));
setIconImage(SwingResourceManager.getImage(Borrower.class, "/LOGO.jpg"));
}
}
/**
* Initialize the contents of the frame
*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -