📄 shoppinghistory.java
字号:
package RegisterAndLogin;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import javax.swing.JScrollPane;
import java.awt.Rectangle;
import java.sql.ResultSetMetaData;
import javax.swing.JTable;
import javax.sql.rowset.CachedRowSet;
public class ShoppingHistory extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JScrollPane jScrollPane = null;
private JTable jTable = null;
public CachedRowSet crs=null;
/**
* This is the default constructor
*/
public ShoppingHistory(CachedRowSet crs) {
super();
this.crs=crs;
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(524, 362);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
this.setVisible(true);
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJScrollPane(), null);
}
return jContentPane;
}
/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setBounds(new Rectangle(7, 8, 505, 282));
jScrollPane.setViewportView(getJTable());
}
return jScrollPane;
}
/**
* This method initializes jTable
*
* @return javax.swing.JTable
*/
private JTable getJTable() {
if (jTable == null) {
ShoppingHistoryTableModel mytablemodel=new ShoppingHistoryTableModel();
jTable = new JTable(mytablemodel);
try{ResultSetMetaData md=crs.getMetaData();
int c=md.getColumnCount();
if(crs.isBeforeFirst())
{
crs.beforeFirst();
}
for(int i=0;i<20;i++)
for(int j=0;j<6;j++)
jTable.setValueAt("", i, j);
int i=0;
while(crs.next()) //读入该商店的商品
{
String sailerID=crs.getString("sailerID");
int goodsId=crs.getInt("goodsID");
int number=crs.getInt("number");
float primaryPrice=crs.getFloat("primaryPrice");
float bargainPrice=crs.getFloat("bargainPrice");
String creatTime=crs.getString("creatTime");
jTable.setValueAt(sailerID, i, 0);
jTable.setValueAt(goodsId, i, 1);
jTable.setValueAt(number, i, 2);
jTable.setValueAt(primaryPrice, i, 3);
jTable.setValueAt(bargainPrice, i, 4);
jTable.setValueAt(creatTime, i, 5);
i++;
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
return jTable;
}
} // @jve:decl-index=0:visual-constraint="44,22"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -