📄 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(lblPurchaseDate,3,0,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 + -