📄 lackbook.java
字号:
package purchase;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import java.awt.Rectangle;
import javax.swing.JButton;
import java.awt.Font;
import javax.swing.JTable;
import javax.swing.JLabel;
import javax.swing.table.DefaultTableModel;
import main.DataBase;
class LackBook extends JPanel {
private static final long serialVersionUID = 1L;
private JScrollPane jScrollPane = null;
private JButton purchase = null;
private static JTable jTable = null;
private static JLabel jLabel = null;
private static DefaultTableModel modelForTable;
// frame用来作为对话框的所有者
JFrame frame;
/**
* This is the default constructor
*/
public LackBook(JFrame frame) {
super();
initialize();
this.frame=frame;
LackBook.setModelForTable();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(0, 2, 60, 18));
jLabel.setText("查看缺书");
this.setSize(500, 280);
this.setLayout(null);
this.add(getJScrollPane(), null);
this.add(getPurchase(), null);
this.add(jLabel, null);
}
/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setBounds(new Rectangle(31, 24, 426, 196));
jScrollPane.setViewportView(getJTable());
}
return jScrollPane;
}
/**
* This method initializes purchase
*
* @return javax.swing.JButton
*/
private JButton getPurchase() {
if (purchase == null) {
purchase = new JButton();
purchase.setBounds(new Rectangle(53, 239, 107, 30));
purchase.setFont(new Font("\u6977\u4f53_GB2312", Font.BOLD, 18));
purchase.setText("采购");
purchase.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
int i=LackBook.getJTable().getSelectedRow();
if(i>-1){
String isbn=(String)LackBook.this.getModelForTable().getValueAt(i,0);
String bookname=(String)LackBook.this.getModelForTable().getValueAt(i,1);
String author=(String)LackBook.this.getModelForTable().getValueAt(i,2);
String press=(String)LackBook.this.getModelForTable().getValueAt(i,3);
String[] value=new String[4];
value[0]=isbn;
value[1]=bookname;
value[2]=author;
value[3]=press;
new Buy(LackBook.this.frame,value);
}
else{
javax.swing.JOptionPane.showMessageDialog(null,"图书馆管理系统\n"+
"请选择一条记录 \n");
}
}
});
}
return purchase;
}
/**
* This method initializes jTable
*
* @return javax.swing.JTable
*/
private static JTable getJTable() {
if (LackBook.jTable == null) {
jTable = new JTable();
}
return jTable;
}
public static void setModelForTable(){
String sql="SELECT isbn, book_name, author, press FROM lack_book";
String[] englishColumns = { "isbn", "book_name", "author", "press" };
String[] chineseColumns = { "ISBN", "书名", "作者", "出版社" };
DefaultTableModel modelForTable = DataBase.createModelForTable(
englishColumns, chineseColumns, sql);
LackBook.modelForTable=modelForTable;
LackBook.getJTable().setModel(modelForTable);
LackBook.getJTable().repaint();
}
public DefaultTableModel getModelForTable() {
return modelForTable;
}
} // @jve:decl-index=0:visual-constraint="10,10"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -