?? assetview.java
字號:
/*
*AssetView.java:建立固定資產管理界面(類)。
*包括:增、刪、改3個子界面。
*/
package zichan;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
public class AssetView extends JDialog {
public AssetView() {
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public AssetPanel p1;
public AssetView(Mydialog p2) {
getContentPane().setLayout(new BorderLayout());
p1 = new AssetPanel();
getContentPane().add(p1,BorderLayout.CENTER);
getContentPane().add(p2,BorderLayout.SOUTH);
}
private void jbInit() throws Exception {
}
}
class AssetPanel extends JPanel implements ActionListener {
private Container cont;
private GridBagLayout layout;
private GridBagConstraints cons;
CateIdChoices cc ;
JLabel lblAssetId;
JLabel lblAssetName;
JLabel lblCateId;
JLabel lblSubCateId;
JLabel lblModel;
JLabel lblPrice;
JLabel lblPurchaseDate;
JLabel lblStatus;
JLabel lblUseby;
JLabel lblRemarks;
public JTextField jtfAssetId ;
public JTextField jtfAssetName ;
public JComboBox jcbCateId ;
public JComboBox jcbSubCateId ;
public JTextField jtfModel ;
public JTextField jtfPrice ;
public JTextField jtfPurchaseDate ;
public JComboBox jcbStatus;
public JTextField jtfUseby ;
public JTextField jtfRemarks ;
String [] cateid;
String [] subcateid;
String statusChoices[] = {"1","0"};
public AssetPanel() {
cc = new CateIdChoices();
int cnt = cc.selCateCnt();
cateid = new String[cnt];
cc.selCateId(cateid);
cont = this;
layout = new GridBagLayout();
cont.setLayout(layout);
cons = new GridBagConstraints();
lblAssetId = new JLabel("資產編號");
lblAssetName = new JLabel("資產名稱");
lblCateId = new JLabel("大類編號");
lblSubCateId = new JLabel("子類編號");
lblModel = new JLabel("樣式");
lblPrice = new JLabel("價格") ;
lblPurchaseDate = new JLabel("購入日期");
lblStatus = new JLabel("狀態");
lblUseby = new JLabel("購入人");
lblRemarks = new JLabel("備注");
jtfAssetId = new JTextField(10);
jtfAssetName = new JTextField(10);
jcbSubCateId = new JComboBox();
jcbSubCateId.setOpaque(true);
jcbSubCateId.setPreferredSize(new Dimension(110,20));
jcbSubCateId.setBackground(Color.white);
jcbCateId = new JComboBox();
jcbCateId.addActionListener(this);
jcbCateId.setActionCommand("selCateId");
jcbCateId.setOpaque(true);
jcbCateId.setPreferredSize(new Dimension(110,20));
jcbCateId.setBackground(Color.white);
for (int i=0;i<cnt;i++)
jcbCateId.addItem(cateid[i]);
jtfModel = new JTextField(10);
jtfPrice = new JTextField(10);
jtfPurchaseDate = new JTextField(10);
jcbStatus = new JComboBox(statusChoices);
jcbStatus.setOpaque(true);
jcbStatus.setPreferredSize(new Dimension(110,20));
jcbStatus.setBackground(Color.white);
jtfUseby = new JTextField(10);
jtfUseby.setText("Admin");
jtfRemarks = new JTextField(10);
addComponent(lblAssetId,0,0,1,1);
addComponent(jtfAssetId,0,1,1,1);
addComponent(lblAssetName,0,2,1,1);
addComponent(jtfAssetName,0,3,1,1);
addComponent(lblCateId,1,0,1,1);
addComponent(jcbCateId,1,1,1,1);
addComponent(lblSubCateId,1,2,1,1);
addComponent(jcbSubCateId,1,3,1,1);
addComponent(lblModel,2,0,1,1);
addComponent(jtfModel,2,1,1,1);
addComponent(lblPrice,2,2,1,1);
addComponent(jtfPrice,2,3,1,1);
addComponent(jtfPurchaseDate,3,1,1,1);
addComponent(lblStatus,3,2,1,1);
addComponent(jcbStatus,3,3,1,1);
addComponent(lblUseby,4,0,1,1);
addComponent(jtfUseby,4,1,1,1);
addComponent(lblRemarks,4,2,1,1);
addComponent(jtfRemarks,4,3,1,1);
setVisible(true);
}
private void addComponent(Component comp,
int row,int column,int width,int height) {
cons.gridx = column;
cons.gridy = row;
cons.gridwidth = width;
cons.gridheight = height;
layout.setConstraints(comp,cons);
cont.add(comp);
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand() == "selCateId") {
JComboBox cb = (JComboBox)e.getSource();
String cid = (String)cb.getSelectedItem();
jcbSubCateId.removeAllItems();
int cnt = cc.selSubCateCnt(cid);
subcateid = new String[cnt];
cc.selSubCateId(subcateid,cid);
for (int i=0;i<cnt;i++)
jcbSubCateId.addItem(subcateid[i]);
}
}
}
class AddAssetView extends AssetView {
public AddAssetView(Mydialog p) {
super(p);
setTitle("增加資產");
p1.jtfAssetId.setEnabled(false);
p1.jtfUseby.setEnabled(false);
}
}
class UptAssetView extends AssetView {
public UptAssetView(Mydialog p) {
super(p);
setTitle("修改資產");
p1.jcbCateId.setEnabled(false) ;
p1.jcbSubCateId.setEnabled(false) ;
}
}
class DelAssetView extends AssetView {
public DelAssetView(Mydialog p) {
super(p);
setTitle("刪除資產");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -