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

📄 managerframe.java

📁 学生资料管理系统 基于c/s模式开发 用户可以运行用户端登陆服务器 然后通过客户端来进行服务器端的数据库操作
💻 JAVA
字号:
import javax.swing.*; 
import java.awt.*; 
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

/**
 * author sunringove
 * data 2007-01-17
 * 信息管理界面
 */

public class ManagerFrame extends JFrame implements ActionListener,WindowListener{ 
		

	private static final long serialVersionUID = 1L;
	private JComboBox box=new JComboBox();
	private JButton button1=new JButton("查找");
	private JButton button2=new JButton("修改");
	private JButton button3=new JButton("删除");
	private JButton button4=new JButton("添加");
	private JButton button5=new JButton("刷新");
	private JTextField textField=new JTextField();
	private JLabel label=new JLabel();
	private JMenuItem item1;
	private JMenuItem item2;
	private JMenuItem item3;
	private JMenuItem item4;
	private JMenuItem item5;
	private JMenuItem item6;
	private JTable table;
	public String data[][];
	public  String choics[]={"姓名","学号","性别","入学年份","专业","系别","所在社团","加入时间","退出时间"};
	public Member member;
	public Member members[];
	public int index;
	public FrameOperator frameOperator;
	public boolean hasActive;					//表中数据是否已经更新
	public String nowOperate;
	public String searchKey;
	public String searchValue;
	public String delID;
		
	public ManagerFrame(Member[] member,int index){ 
		
		members=new Member[index];
		members=member;
		this.index=index;
		
		data=new String[index][9];
						
		for(int i=0;i<choics.length;i++){
			box.addItem(choics[i]);
		}
			
		label.setText("查询条件");
					
		textField.setText('\t'+"");
				
		setLocation(40,40);
		JToolBar toolbar=new JToolBar();
		toolbar.setLayout(new FlowLayout(FlowLayout.LEADING));
		toolbar.add(label);
		toolbar.add(box);
		toolbar.add(textField);
		toolbar.add(button1);
		toolbar.add(button2);
		toolbar.add(button3);
		toolbar.add(button4);
		toolbar.add(button5);
		
		setTitle("sunringove");
		JMenuBar menuBar=new JMenuBar();
		JMenu file=new JMenu("File");
		file.add(item1=new JMenuItem("添加"));
		item1.addActionListener(this);
		file.add(item2=new JMenuItem("删除"));
		item2.addActionListener(this);
		file.addSeparator();
		file.add(item3=new JMenuItem("Exit"));
		item3.addActionListener(this);
		
		menuBar.add(file);
		
		JMenu edit=new JMenu("Edit");
		edit.add(item4=new JMenuItem("刷新"));
		item4.addActionListener(this);
		edit.add(item5=new JMenuItem("修改"));
		item5.addActionListener(this);
		edit.add(item6=new JMenuItem("查找"));
		item6.addActionListener(this);
			
		menuBar.add(edit);
		
		
		button1.addActionListener(this);
		button2.addActionListener(this);
		button3.addActionListener(this);
		button4.addActionListener(this);
		button5.addActionListener(this);
		textField.addActionListener(this);
				
		setJMenuBar(menuBar);
		
		//built table		
		for(int i=0;i<index;i++){
			
			String	temp[]={	member[i].getName(),
								member[i].getID(),
								member[i].getGender(),
								member[i].getYear(),
								member[i].getMajor(),
								member[i].getDepartment(),
								member[i].getLeague(),
								member[i].getenterTime(),
								member[i].getquitTime()};
			
			for(int j=0;j<temp.length;j++){	
					data[i][j]=temp[j];
			}
		
		}
					
		table=new JTable(data,choics); 
		table.setPreferredScrollableViewportSize(new Dimension(640,400)); 
		table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); 
		
		JScrollPane scrollPane=new JScrollPane(table); 
		getContentPane().add(scrollPane,BorderLayout.CENTER); 
		getContentPane().add(toolbar,BorderLayout.NORTH); 
		
		setTitle("SimpleTable"); 
		pack(); 
		setVisible(true); 
		addWindowListener(this); 
		} 
		
		

		public void actionPerformed(ActionEvent e) {
			
			String value=e.getActionCommand();
			nowOperate=value;
			hasActive=false;
				
			 if(value.equals("Exit")){
				 System.exit(1);
			 }
						
			if(value.equals("查找"))
		    {
				  searchKey=box.getSelectedItem().toString();
				  searchValue=textField.getText();
				  setActiveTrue();
			}
			 
			 if(value.equals("刷新"))
			 {
				  setActiveTrue();
			 }
			 			 		 
			 if(value.equals("删除"))
			 {
				 	if(table.getSelectedRow()==-1){
				 		 JOptionPane.showMessageDialog(this,"没有记录被选中!","message",JOptionPane.INFORMATION_MESSAGE);
				 	}
				 	else{
					 	member=new Member(table.getValueAt(table.getSelectedRow(),0).toString(),
															 			table.getValueAt(table.getSelectedRow(),1).toString(),
															 			table.getValueAt(table.getSelectedRow(),2).toString(),
															 			table.getValueAt(table.getSelectedRow(),3).toString(),
															 			table.getValueAt(table.getSelectedRow(),4).toString(),
															 			table.getValueAt(table.getSelectedRow(),5).toString(),
															 			table.getValueAt(table.getSelectedRow(),6).toString(),
															 			table.getValueAt(table.getSelectedRow(),7).toString(),
															 			table.getValueAt(table.getSelectedRow(),8)+"");
						 	
						 	int n=JOptionPane.showConfirmDialog(this,table.getValueAt(table.getSelectedRow(),0).toString()+" "+table.getValueAt(table.getSelectedRow(),1).toString()+" 记录将会被删除!确定?","question",JOptionPane.YES_NO_OPTION);
							if(n==JOptionPane.NO_OPTION)
							{
				                
							}
				            else{
									if(n==JOptionPane.YES_OPTION)
									{
										 JOptionPane.showMessageDialog(this,"记录已删除!","message",JOptionPane.INFORMATION_MESSAGE);
										 setActiveTrue();
									}
				            }
				 	}
			 }		
			 
			if(value.equals("添加"))
			 {
				 EditFrame editFrame=new EditFrame(this);
				 editFrame.setVisible(true);
				 editFrame.setisAdd();	
			 }
			
			
			if(value.equals("修改")){
				
				if(table.getSelectedRow()==-1){
			 		 JOptionPane.showMessageDialog(this,"没有记录被选中!","message",JOptionPane.INFORMATION_MESSAGE);
			 	}
				else{
						
					member=new Member(table.getValueAt(table.getSelectedRow(),0).toString(),
				 			table.getValueAt(table.getSelectedRow(),1).toString(),
				 			table.getValueAt(table.getSelectedRow(),2).toString(),
				 			table.getValueAt(table.getSelectedRow(),3).toString(),
				 			table.getValueAt(table.getSelectedRow(),4).toString(),
				 			table.getValueAt(table.getSelectedRow(),5).toString(),
				 			table.getValueAt(table.getSelectedRow(),6).toString(),
				 			table.getValueAt(table.getSelectedRow(),7).toString(),
				 			table.getValueAt(table.getSelectedRow(),8)+"");
					  
					delID=table.getValueAt(table.getSelectedRow(),1).toString();
					EditFrame editFrame=new EditFrame(this);
					frameOperator=new FrameOperator(editFrame);
					frameOperator.seteFrameMember(member);
					editFrame.setVisible(true);
							
				}
			}
			
		} 
		
		//	************************************************************************************
		//获取ID
		//************************************************************************************
		public String getdelID(){
			return delID;
		}
		
		//	************************************************************************************
		//获取查找的项目
		//************************************************************************************
		public String getsearchKey(){
			return searchKey;
		}
		
		//	************************************************************************************
		//获取查找的值
		//************************************************************************************
		public String getsearchValue(){
			return searchValue;
		}
		
		//	************************************************************************************
		//设置member
		//************************************************************************************
		public void setMember(Member member){
			this.member=member;
		}
		
		//	************************************************************************************
		//返回当前member
		//************************************************************************************
		public Member getMember(){
			return member;
		}
		
		//	************************************************************************************
		//返回当前member
		//************************************************************************************
		public int getIndex(){
			return index;
		}
		
		//************************************************************************************
		//返回当前members
		//************************************************************************************
		public Member[] getMembers(){
			return members;
		}
		
		//	************************************************************************************
		//设置活动状态为true
		//************************************************************************************
		public void setActiveTrue(){
			hasActive=true;
		}
		
		//	************************************************************************************
		//设置活动状态为flase
		//************************************************************************************
		public void setActiveFalse(){
			hasActive=false;
		}
		
		//	************************************************************************************
		//返回当前的活动状态
		//************************************************************************************
		public boolean hasActive(){
			return hasActive;
		}
		
		//	************************************************************************************
		//获得当前的操作
		//************************************************************************************
		public String getNowOperate(){
			return nowOperate;
		}
		
		//	************************************************************************************
		//窗口事件处理
		//************************************************************************************
		public void windowOpened(WindowEvent arg0) {}
		public void windowClosing(WindowEvent arg0) {
			System.exit(1);
		}
		public void windowIconified(WindowEvent arg0) {}
		public void windowDeiconified(WindowEvent arg0) {	}
		public void windowActivated(WindowEvent arg0) {}
		public void windowDeactivated(WindowEvent arg0) {}
		public void windowClosed(WindowEvent arg0) {}
  
} 

⌨️ 快捷键说明

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