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

📄 mainwindow.java

📁 用java语言编写的银行管理系统
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.sql.*;

public class mainWindow extends JFrame implements ActionListener
{
	private JLabel whereLabel = new JLabel( "营业部" );
	private String[] whereStr = {
		new String( "营业部A" ), new String( "营业部B" )
	};
	private JComboBox whereCombo = new JComboBox( whereStr );
	 
	private JLabel whoLabel = new JLabel( "身份:" );
	private String[] whoStr = {	new String( "柜台人员" ),
		new String( "支行行长" ), new String( "营业部主任" )	
	};
	private JComboBox whoCombo = new JComboBox( whoStr );
	
	private JLabel user = new JLabel( "用户:" );
	private JTextField username = new JTextField( 20 );
	private JLabel pass = new JLabel( "密码:" );
	private JTextField passwords = new JTextField( 20 );
	
	private JButton enter = new JButton( "进入" );
	private JButton exit = new JButton( "离开" );
	
	public mainWindow()
	{
		super( "管理员登陆" );
		
		Container c = getContentPane();
		c.setLayout( new BorderLayout() );
		
		JPanel[] panel = new JPanel[3];
		for( int i=0; i<panel.length; i++ )
		{
			panel[i] = new JPanel();
			panel[i].setLayout( new FlowLayout(FlowLayout.CENTER) );
		}
		
		c.add( panel[0], BorderLayout.NORTH );
		panel[0].add( whereLabel );
		panel[0].add( whereCombo );
		panel[0].add( whoLabel );
		panel[0].add( whoCombo );
		
		c.add( panel[1], BorderLayout.CENTER );
		panel[1].add( user );
		panel[1].add( username );
		panel[1].add( pass );
		panel[1].add( passwords );
		
		c.add( panel[2], BorderLayout.SOUTH );
		panel[2].add( enter );
		panel[2].add( exit );
		
		enter.addActionListener( this );
		exit.addActionListener( this );
		
		setSize( 280, 150 );
		setResizable( false );
		setVisible( true );
		setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
	}

	public void actionPerformed( ActionEvent e )
	{
		if( e.getSource()==enter )
		{   
	       
	        String userId=username.getText();
            String password=passwords.getText(); 
            
            if((userId.length()==0)||(password.length()==0))
               {
               	System.out.println("用户名或密码不能为空!");
               }
	       /*数据库判断*/	
		   else
		     {
		     	try{
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//声明驱动程序
                   String url="jdbc:odbc:info";//指定数据源名
                   Connection con=DriverManager.getConnection(url);//连接数据库
            
               PreparedStatement select_stm=con.prepareStatement("select password from 登陆 where userId=?");
              //设置查询
               select_stm.setString(1,userId);
              //设置查询中的一个参数
               ResultSet result=select_stm.executeQuery();
               //得到查询结果
                String temp_password=null;
                //声明存储查询结果中密码属性的变量
                if(result.next())
                temp_password=result.getString(1);
                //得到查询结果中密码属性值
                 result.close();
                if(temp_password==null)
                 //如果数据库中还没有此用户名
                 {
                  System.out.println(" no userId");
                  String s="this userId is not exits!";
                  JOptionPane.showMessageDialog(null,s);
                 }
                  
                 else if(password.regionMatches(0,temp_password,0,password.length()))
                 { 
               
                   this.dispose();  //让主窗口消失
			       new Login();
                   
                 }
          
              
                   
			       con.close();
                }
                
                catch(Exception ev)
                    {
                    }
               } 
			
		}
		else if( e.getSource()==exit )
		{
			int n = JOptionPane.showConfirmDialog(
						this, "是否真的要退出", "退出窗口",
						JOptionPane.YES_NO_OPTION );
			if( n==JOptionPane.YES_OPTION )
				System.exit( 0 );
		}
	}

	public static void main( String[] args )
	{
		new mainWindow();
	}
}

⌨️ 快捷键说明

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