⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lendview.java

📁 java课程的资料以及实验的代码
💻 JAVA
字号:
/*
 *LendView.java:建立借用归还管理界面(类)。
 *包括:借用,归还2个子界面。
 */

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.sql.*;

public class LendView extends JDialog   {
   public LendPanel p1;
   public LendView(ButPanel p2) {
		getContentPane().setLayout(new BorderLayout());
		p1 = new LendPanel();
		getContentPane().add(p1,BorderLayout.CENTER);
		getContentPane().add(p2,BorderLayout.SOUTH);
   }
}

class LendPanel extends JPanel {
   private Container cont;
   private GridBagLayout layout;
   private GridBagConstraints cons;
   CateIdChoices cc ;
   DbConn dbc,dbc2;
   Connection conn, conn2;
   String returnChoices[] = {"借用","归还"};
   
   JLabel lblAssetId;
   JLabel lblEmpNo;
   JLabel lblUseDate;
   JLabel lblRetDate;
   JLabel lblIsReturn;
   JLabel lblLender;
   JLabel lblRemarks;

   public JComboBox jtfAssetId ;
   public JComboBox jcbEmpNo;
   public JTextField jtfUseDate;
   public JTextField jtfRetDate;
   public JComboBox jtfIsReturn;
   public JTextField jtfLender;
   public JTextField jtfRemarks ;
   String[] empnoer;
   
   public LendPanel() {
   	
   	cont = this;
   	String sEmpno[];
   	layout = new GridBagLayout();
   	cont.setLayout(layout);
   	cons = new GridBagConstraints();
   	
	lblAssetId = new JLabel("资产编号");
	lblEmpNo = new JLabel("借用人");
	lblUseDate = new JLabel("借用日期");
	lblRetDate = new JLabel("归还日期");
	lblIsReturn = new JLabel("是否归还") ;
	lblLender = new JLabel("操作员");
	lblRemarks = new JLabel("备注");
  	
    jtfAssetId = new JComboBox();
  	
  	jcbEmpNo = new JComboBox();
  	
      String sql, sql2;
      dbc = new DbConn();
      dbc2 = new DbConn();
      conn = dbc.getConnection();
      conn2 = dbc2.getConnection();
      
      sql = "SELECT empno FROM Employee";
      sql2="select assetid from asset";
      try {
      	Statement stmt = conn.createStatement();
      	ResultSet rset = stmt.executeQuery (sql);
      	
      	while (rset.next()) {
			jcbEmpNo.addItem(rset.getString(1));
      	}
      	
      	conn.commit(); 
      	rset.close();
      	stmt.close();
      	conn.close();
      }
      catch (java.sql.SQLException s) {
		System.out.println("exception: " + s.getMessage());
      }
      
      try {
      		Statement stmt2 = conn2.createStatement();
      		ResultSet rset2 = stmt2.executeQuery (sql2);
      		while (rset2.next()) {
				jtfAssetId.addItem(rset2.getString(1));
      		}
	      	conn2.commit(); 
	      	rset2.close();
	      	stmt2.close();
	      	conn2.close();
      }
      catch (java.sql.SQLException s) {
		System.out.println("exception: " + s.getMessage());
      }
   
    jtfAssetId.setOpaque(true);
    jtfAssetId.setPreferredSize(new Dimension(110,20));
    jtfAssetId.setBackground(Color.white);
   
  	jcbEmpNo.setOpaque(true);
    jcbEmpNo.setPreferredSize(new Dimension(110,20));
    jcbEmpNo.setBackground(Color.white);
        
  	jtfUseDate = new JTextField(10);
    jtfRetDate = new JTextField(10);
    
	jtfIsReturn = new JComboBox(returnChoices);
	jtfIsReturn.setOpaque(true);
    jtfIsReturn.setPreferredSize(new Dimension(110,20));
    jtfIsReturn.setBackground(Color.white);
	
    jtfLender = new JTextField(10);
    jtfRemarks = new JTextField(10);
        
	addComponent(lblAssetId,0,0,1,1);
	addComponent(jtfAssetId,0,1,1,1);
	addComponent(lblEmpNo,0,2,1,1);
	addComponent(jcbEmpNo,0,3,1,1);
	addComponent(lblUseDate,1,0,1,1);
	addComponent(jtfUseDate,1,1,1,1);
	addComponent(lblRetDate,1,2,1,1);
	addComponent(jtfRetDate,1,3,1,1);
	addComponent(lblIsReturn,2,0,1,1);
	addComponent(jtfIsReturn,2,1,1,1);
	addComponent(lblLender,2,2,1,1);
	addComponent(jtfLender,2,3,1,1);
	addComponent(lblRemarks,3,0,1,1);
	addComponent(jtfRemarks,3,1,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);
   }
   
}

class LenLendView extends LendView {
	public LenLendView(ButPanel p) {
		super(p);
		setTitle("借用资产");
//		p1.jtfAssetId.setEnabled(false);
	}
}
class RetLendView extends LendView {
	public RetLendView(ButPanel p) {
		super(p);
		setTitle("归还资产");
//		p1.jtfAssetId.setEnabled(false);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -