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

📄 mainframe.java

📁 档案管理(java).rar
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.text.*;
import javax.swing.text.*;
import javax.swing.text.*;
import java.sql.*;

//主窗体
class MainFrame implements MouseListener, ActionListener
{
	//主窗体
	 JFrame frameMain;
	Container cpMain;
	//主窗体工具栏
	JToolBar barMain;
	JLabel[] lblTool=new JLabel[7];
	//主窗体背景图
	JLabel lblImage;
	//登陆窗口
    JFrame dlFrame;
	JDialog dialog;
	JLabel[] lbl=new JLabel[2];
    Choice choice;
    JPasswordField pass;
    JButton[] cmd=new JButton[2];
    Container cp;
	//系统设置
	JPanel paneSystem,paneSys;
	JLabel[] lblSystem=new JLabel[4];
	//注册用户面板
	JPanel paneZhuce;
	JLabel[] lblZhuce=new JLabel[3];
	JTextField[] txtZhuce=new JTextField[3];
	JButton[] cmdZhuce=new JButton[2];
	//删除用户面板
	JPanel paneDel;
	JLabel lblDel;
	Choice choiceDel;
	JButton[] cmdDel=new JButton[2];
	//更改密码面板
	JPanel paneUpdate;
	JLabel[] lblUpdate=new JLabel[3];
	Choice choiceUpdate;
	JTextField[] txtUpdate=new JTextField[3];
	JButton[] cmdUpdate=new JButton[2];
	//
	JTextField[] txtTemp=new JTextField[4];
	static int admi=1;
	static String name;
	//构造函数
	MainFrame() 
	{
		//主窗体工具栏初始化
		barMain=new JToolBar();
		barMain.setFloatable(false);
		barMain.setBorder(null);
		barMain.setBackground(new Color(255,255,240));
		
		lblTool[0]=new JLabel("首页");
		lblTool[1]=new JLabel("企业");
		lblTool[2]=new JLabel("人力");
		lblTool[3]=new JLabel("就业");
		lblTool[4]=new JLabel("统计");
		lblTool[5]=new JLabel("系统");
		lblTool[6]=new JLabel("关于");
		
		for(int i=0;i<7;i++)
		{
			lblTool[i].setIcon(new ImageIcon("img/toolMain.gif"));
			lblTool[i].setForeground(Color.blue);
			lblTool[i].addMouseListener(this);//监听
			lblTool[i].setBorder(BorderFactory.createRaisedBevelBorder());
			lblTool[i].setHorizontalTextPosition(SwingConstants.CENTER);
			//工具栏加入组件
			if(i==1||i==4)
			   barMain.addSeparator();
			barMain.add(lblTool[i]);
		}
		
		//主窗体背景图
		lblImage=new JLabel();
		lblImage.setIcon(new ImageIcon("img/main.jpg"));
		//主窗体布局管理
		frameMain=new JFrame("职业中介管理系统");
		cpMain=frameMain.getContentPane();
		cpMain.setLayout(new BorderLayout());
		//主窗体加入组件
		cpMain.add(barMain,BorderLayout.NORTH);
		
		cpMain.add(lblImage,BorderLayout.CENTER);
		//显示主窗体
		frameMain.setSize(800,570);
		frameMain.show();
		//系统登陆
		dlFrame=new JFrame("登陆窗口");
		
		
		dialog=new JDialog(dlFrame,true);
		
		dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
		dialog.addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent evt)
			{
				int op=JOptionPane.showConfirmDialog(dialog,"确定要退出吗?","提示",JOptionPane.YES_NO_OPTION);
		        if(op==JOptionPane.YES_OPTION)
		        {
				    System.exit(0);
				}
			
				
			}
		});
		cp=dialog.getContentPane();
		cp.setBackground(new Color(255,255,220));
		cp.setLayout(new GridBagLayout());
		lbl[0]=new JLabel("用户名");
		lbl[1]=new JLabel("密码");
		choice=new Choice();
		setchoice(choice,"select * from 用户 order by 用户名 desc");
		pass=new JPasswordField(8);
		pass.setBackground(new Color(255,255,220));
		pass.setBorder(BorderFactory.createMatteBorder(0,0,1,0,new Color(89,89,255)));
		cmd[0]=new JButton("确定");
		cmd[1]=new JButton("退出");
		for(int i=0;i<2;i++)
		{
			lbl[i].setForeground(new Color(89,89,255));
			cmd[i].addActionListener(this);
			cmd[i].setForeground(new Color(89,89,255));
			cmd[i].setBackground(new Color(255,255,220));
		}
		GridBagConstraints c=new GridBagConstraints();
		c.insets=new Insets(8,0,8,8);
		c.gridy=0;
		cp.add(lbl[0],c);
		cp.add(choice,c);
		c.gridy++;
		cp.add(lbl[1],c);
		cp.add(pass,c);
		c.gridy++;
		
		cp.add(cmd[0],c);
		c.anchor=GridBagConstraints.EAST;
		cp.add(cmd[1],c);
		dialog.setLocation(300,200);
		dialog.pack();
		dialog.show();
		//系统设置面板
		paneSystem=new JPanel();
		paneSys=new JPanel();
		paneSystem.setBackground(new Color(255,255,240));
		paneSystem.setBorder(BorderFactory.createMatteBorder(2,2,2,2,Color.orange));
		lblSystem[0]=new JLabel("注册用户");
		lblSystem[1]=new JLabel("修改密码");
		lblSystem[2]=new JLabel("删除用户");
		lblSystem[3]=new JLabel("重新登陆");
		for(int i=0;i<4;i++)
		{
			lblSystem[i].setFont(new Font("隶书",Font.BOLD,30));
			lblSystem[i].setIcon(new ImageIcon("img/s.jpg"));
			lblSystem[i].setForeground(new Color(128,0,255));
			lblSystem[i].setHorizontalTextPosition(SwingConstants.CENTER);
		    lblSystem[i].addMouseListener(this);
		    lblSystem[i].setBorder(BorderFactory.createMatteBorder(2,2,2,2,Color.orange));
		}
		paneSystem.setLayout(new GridBagLayout());
		GridBagConstraints cs=new GridBagConstraints();
		cs.insets=new Insets(5,0,5,5);
		cs.gridy=0;
		paneSystem.add(lblSystem[0],cs);
		paneSystem.add(lblSystem[1],cs);
		cs.gridy++;
		paneSystem.add(lblSystem[2],cs);
		paneSystem.add(lblSystem[3],cs);
		paneSys.setLayout(new BorderLayout());
		paneSys.add(paneSystem,BorderLayout.CENTER);
		////注册用户面板
		paneZhuce=new JPanel();
		paneZhuce.setBackground(new Color(255,255,240));
		paneZhuce.setBorder(BorderFactory.createMatteBorder(2,2,2,2,Color.orange));
		lblZhuce[0]=new JLabel("用户名");
		lblZhuce[1]=new JLabel("密码");
		lblZhuce[2]=new JLabel("确认密码");
		for(int i=0;i<3;i++)
		{
			txtZhuce[i]=new JTextField(10);
			lblZhuce[i].setForeground(new Color(128,0,255));
			txtZhuce[i].setBorder(BorderFactory.createMatteBorder(0,0,1,0,Color.blue));
		    txtZhuce[i].setBackground(new Color(255,255,240));
		    
		}
		cmdZhuce[0]=new JButton("确认");
		
		cmdZhuce[1]=new JButton("返回");
		for(int i=0;i<2;i++)
		{
		    cmdZhuce[i].setBackground(new Color(255,255,240));
		    cmdZhuce[i].setForeground(Color.blue);
		    cmdZhuce[i].addActionListener(this);
		}
		paneZhuce.setLayout(new GridBagLayout());
		GridBagConstraints cz=new GridBagConstraints();
		cz.insets=new Insets(10,0,10,10);
		cz.gridy=0;
		paneZhuce.add(lblZhuce[0],cz);
		paneZhuce.add(txtZhuce[0],cz);
		cz.gridy++;
		paneZhuce.add(lblZhuce[1],cz);
		paneZhuce.add(txtZhuce[1],cz);
		cz.gridy++;
		paneZhuce.add(lblZhuce[2],cz);
		paneZhuce.add(txtZhuce[2],cz);
		cz.gridy++;
		paneZhuce.add(cmdZhuce[0],cz);
		cz.anchor=GridBagConstraints.EAST;
		paneZhuce.add(cmdZhuce[1],cz);
		//更改密码面板
		paneUpdate=new JPanel();
		paneUpdate.setBackground(new Color(255,255,240));
		paneUpdate.setBorder(BorderFactory.createMatteBorder(2,2,2,2,Color.orange));
		
		lblUpdate[0]=new JLabel("用户名");
		lblUpdate[1]=new JLabel("新密码");
		lblUpdate[2]=new JLabel("确认新密码");
		choiceUpdate=new Choice();
		for(int i=0;i<3;i++)
		   lblUpdate[i].setForeground(new Color(128,0,255));
		for(int i=0;i<2;i++)
		{
			txtUpdate[i]=new JTextField(10);
			txtUpdate[i].setBorder(BorderFactory.createMatteBorder(0,0,1,0,Color.blue));
		    txtUpdate[i].setBackground(new Color(255,255,240));
		    
		}
		cmdUpdate[0]=new JButton("确认");
		
		cmdUpdate[1]=new JButton("返回");
		for(int i=0;i<2;i++)
		{
		    cmdUpdate[i].setBackground(new Color(255,255,240));
		    cmdUpdate[i].setForeground(Color.blue);
		    cmdUpdate[i].addActionListener(this);
		}
		paneUpdate.setLayout(new GridBagLayout());
		GridBagConstraints cu=new GridBagConstraints();
		cu.insets=new Insets(10,0,10,10);
		cu.gridy=0;
		paneUpdate.add(lblUpdate[0],cu);
		paneUpdate.add(choiceUpdate,cu);
		cu.gridy++;
		paneUpdate.add(lblUpdate[1],cu);
		paneUpdate.add(txtUpdate[0],cu);
		cu.gridy++;
		paneUpdate.add(lblUpdate[2],cu);
		paneUpdate.add(txtUpdate[1],cu);
		
		cu.gridy++;
		paneUpdate.add(cmdUpdate[0],cu);
		cu.anchor=GridBagConstraints.EAST;
		paneUpdate.add(cmdUpdate[1],cu);
		
		//删除用户面板
		paneDel=new JPanel();
		paneDel.setBackground(new Color(255,255,240));
		paneDel.setBorder(BorderFactory.createMatteBorder(2,2,2,2,Color.orange));
		lblDel=new JLabel("用户名");
		lblDel.setForeground(new Color(128,0,255));
		choiceDel=new Choice();
		
		
		cmdDel[0]=new JButton("确认");
		
		cmdDel[1]=new JButton("返回");
		for(int i=0;i<2;i++)
		{
		    cmdDel[i].setBackground(new Color(255,255,240));
		    cmdDel[i].setForeground(Color.blue);
		    cmdDel[i].addActionListener(this);
		}
		paneDel.setLayout(new GridBagLayout());
		GridBagConstraints cd=new GridBagConstraints();
		cd.insets=new Insets(10,0,10,10);
		cd.gridy=0;
		paneDel.add(lblDel,cd);
		paneDel.add(choiceDel,cd);
		cd.gridy++;
		paneDel.add(cmdDel[0],cd);
		cd.anchor=GridBagConstraints.EAST;
		paneDel.add(cmdDel[1],cd);
		/////////////
		for(int i=0;i<4;i++)
		{
			txtTemp[i]=new JTextField(20);
			txtTemp[i].setEditable(false);
			txtTemp[i].setBorder(BorderFactory.createMatteBorder(2,2,2,2,Color.orange));
			if(i%2==0)
			   txtTemp[i].setBackground(Color.orange);
			else
			   txtTemp[i].setBackground(new Color(255,255,240));   
		}
		paneSys.add(txtTemp[0],BorderLayout.NORTH);
		paneSys.add(txtTemp[1],BorderLayout.WEST);
		paneSys.add(txtTemp[2],BorderLayout.SOUTH);
		paneSys.add(txtTemp[3],BorderLayout.EAST);
	}
	
   	//set choice
   void setchoice(Choice c,String str)
   {
   	  c.removeAll();
   	  DataBase db=new DataBase();
   	  db.GetResultSet(str);
   	  try
   	  {
	   	  while(db.rs.next())
	   	      c.addItem(db.rs.getString(1));
	   	  db.st.close();    
	  }catch(SQLException e){}
   	      
   }
	//主程序入口
	public static void main(String[] args)
	{
		new MainFrame();
	}

	public void mouseClicked(MouseEvent parm1) 
	{
		// TODO: Add your code here
	}

	public void mousePressed(MouseEvent parm1) 
	{
		//工具栏<<首页>>标签
		if(parm1.getSource()==lblTool[0]) 
		{
			cpMain.removeAll();
			cpMain.add(barMain,BorderLayout.NORTH);
			cpMain.add(lblImage,BorderLayout.CENTER);
			cpMain.setVisible(false);
			cpMain.setVisible(true);
		}
		//工具栏<<企业>>标签
		if(parm1.getSource()==lblTool[1])
		{
		
				Factory factory=new Factory();
				cpMain.removeAll();
				cpMain.add(barMain,BorderLayout.NORTH);
				cpMain.add(factory.pane,BorderLayout.CENTER);
				cpMain.setVisible(false);
				cpMain.setVisible(true);
		    
		}
		////工具栏<<人力>>标签
		if(parm1.getSource()==lblTool[2])
		{
		
				People people=new People();
				cpMain.removeAll();
				cpMain.add(barMain,BorderLayout.NORTH);
				cpMain.add(people.pane,BorderLayout.CENTER);
				cpMain.setVisible(false);
				cpMain.setVisible(true);
		    
		}
		

⌨️ 快捷键说明

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