public class Employee {
private int id
private String name
private int age
private String email
public int getId() {
return id
}
public void setId(int id) {
this.id = id
}
public String getName() {
return name
}
public void setName(String name) {
this.name = name
}
public int getAge() {
return age
}
public void setAge(int age) {
this.age = age
}
public String getEmail() {
return email
}
public void setEmail(String email) {
this.email = email
}
}
Manager类:
import java.util.ArrayList
import java.util.List
public class Manager {
public static List<Employee>employees = new ArrayList<Employee>()
public static void addEmployee(Employee employee){
employees.add(employee)
}
public static void deleteEmployee(Employee employee){
employees.remove(employee)
}
public static void updateEmployee(Employee employee){
int len = employees.size()
for(int i=0i<leni++){
Employee e = employees.get(i)
if(e.getId() == employee.getId()){
deleteEmployee(e)
addEmployee(employee)
}
}
}
public static Employee selectEmployeeById(int id){
int len = employees.size()
if(len!=0){
Employee emp = new Employee()
for(int i=0i<leni++){
Employee e = employees.get(i)
if(e.getId() == id){
emp = e
}
}
return emp
}else{
return null
}
}
public static Employee selectEmployeeByName(String name){
int len = employees.size()
if(len!=0){
Employee emp = new Employee()
for(int i=0i<leni++){
Employee e = employees.get(i)
if(e.getName().equals(name)){
emp = e
}
}
return emp
}else{
return null
}
}
public static void printEmployees(){
int len = employees.size()
if(len != 0){
for(int i=0i<leni++){
System.out.println(employees.get(i).getId()+":\t"+
employees.get(i).getName()+"\t"+
employees.get(i).getAge()+"\t"+
employees.get(i).getEmail())
}
}else{
System.out.println("无员工")
}
}
}
测试EmpManaTest类:
public class EmpManaTest {
public static void main(String[] args) {
Employee e = new Employee()
e.setId(1)
e.setName("zz")
e.setAge(20)
e.setEmail("zz@163.com")
Manager.addEmployee(e)
Employee e2 = new Employee()
e2.setId(2)
e2.setName("scof")
e2.setAge(18)
e2.setEmail("scofield@mail.com")
Manager.addEmployee(e2)
System.out.println("添加员工后:")
Manager.printEmployees()
System.out.println("----------------------------------------------")
Employee emp = new Employee()
emp.setId(1)
emp.setName("virus")
emp.setAge(30)
emp.setEmail("virus@163.com")
Manager.updateEmployee(emp)
System.out.println("修改员工后:")
Manager.printEmployees()
System.out.println("----------------------------------------------")
System.out.println("查询员工ByID:")
Employee empSelectId = Manager.selectEmployeeById(1)
System.out.println(empSelectId.getName())
System.out.println("----------------------------------------------")
System.out.println("查询员工ByName:")
Employee empSelectName = Manager.selectEmployeeByName("virus")
System.out.println(empSelectName.getEmail())
System.out.println("----------------------------------------------")
System.out.println("删除一个员工后:")
Manager.deleteEmployee(emp)
Manager.printEmployees()
}
}
这个是不是你想要的...........
这是我以前的课程设计,我把代码摘录一部分出来,希望对你有帮助!/**
*MyFrame.java
*author:the fourth group
*version: 2007/1/27
*说明:该程序负责系统登陆框的哪者设置和实
*该应用程差轮序为首先显示的程序
*/
package com.java
import java.awt.Container
import java.awt.event.ActionEvent
import java.awt.event.ActionListener
import java.awt.event.ItemEvent
import java.awt.event.ItemListener
import javax.swing.ButtonGroup
import javax.swing.ImageIcon
import javax.swing.JButton
import javax.swing.JFrame
import javax.swing.JLabel
import javax.swing.JOptionPane
import javax.swing.JPasswordField
import javax.swing.JRadioButton
import javax.swing.JTextField
//import java.util.*
public class MyFrame implements ActionListener ,ItemListener{
//登陆界面属性
String userName
Container con
JLabel lab1,lab2,lab3,lab4
JTextField tf1
JPasswordField tf2
JRadioButton cb1,cb2,cb3
JButton bu1,bu2,bu3
JFrame fr1
public MyFrame(){
fr1=new JFrame()
con=fr1.getContentPane()
con.setLayout(null)
JLabel lab1=new JLabel("账号")
lab1.setBounds(20,70,50,20)
con.add(lab1)
lab2=new JLabel("密码")
lab2.setBounds(20,100,50,20)
con.add(lab2)
tf1=new JTextField()
tf1.setBounds(80,70,160,20)
con.add(tf1)
tf2=new JPasswordField()
tf2.setEchoChar('●')
tf2.setBounds(80,100,160,20)
con.add(tf2)
ButtonGroup cg1=new ButtonGroup()
cb1=new JRadioButton("普通虚缓信会员")
cb1.setBounds(15,135,80,20)
cb1.addItemListener(this) //普通会员
con.add(cb1)
cb2=new JRadioButton("图书管理员")
cb2.setBounds(90,135,102,20)
cb2.addItemListener(this)
con.add(cb2)
cb3=new JRadioButton("系统管理员")
cb3.setBounds(190,135,120,20)
cb3.addItemListener(this)
con.add(cb3)
cg1.add(cb1)
cg1.add(cb2)
cg1.add(cb3)
bu1=new JButton("登陆")
bu1.addActionListener(this)
bu1.setBounds(10,170,60,20)
con.add(bu1)
bu2=new JButton("取消")
bu2.setBounds(110,170,60,20)
con.add(bu2)
// bu1.addActionListener(new ActionListener(){
// public void actionPerformed(ActionEvent e){
////tf1.setText("")
////tf2.setText("")
////itemStateChanged()
// }
// })
bu2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
tf1.setText("")
tf2.setText("")
//new Operator().showframe()
}
})
bu3=new JButton("注册")
bu3.setBounds(210,170,60,20)
// con.add(bu3)
bu3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
// Face2()
}
})
lab3=new JLabel(new ImageIcon("2.jpg"))
lab3.setBounds(0,0,300,60)
con.add(lab3)
lab4=new JLabel(new ImageIcon("1.jpg"))
lab4.setBounds(0,0,300,230)
con.add(lab4)
fr1.setBounds(305,100,300,230)
fr1.setTitle("图书管理系统java版")
fr1.setResizable(false)
fr1.setVisible(true)
}
public void itemStateChanged(ItemEvent e){
//if(cb1.isSelected()){
//// p.showframe()
// try{
//// p.menu0.setEnabled(false)
////
//// p.menuItem6.setEnabled(false)
//// p.menuItem7.setEnabled(false)
//}catch(Exception d){}
//
//// p.menuItem3.setEnabled(false)
//// p.menuItem5.setEnabled(false)
//// p.menuItem6.setEnabled(false)
// }
// else if(cb2.isSelected()){
//// p.showframe()
//try{
//p.menu2.setEnabled(false)
// }catch(Exception d){}
//}
// else if(cb3.isSelected()){
//// p.showframe()
// }
}
public void actionPerformed(ActionEvent e){
//Operator p=new Operator()
if(e.getSource()==bu2)
{
this.setEnable("else")
}
else if(e.getSource()==bu1)
{
char[] password=tf2.getPassword() //获得密码
String passwordSTR=new String(password)
if(tf1.getText().equals("wp")&tf2.getText().equals("456")&!cb1.isSelected()){
JOptionPane.showMessageDialog(null,"请检查你的权限 !")
}
if(tf1.getText().equals("wp")&tf2.getText().equals("456")&cb1.isSelected()){
JOptionPane.showMessageDialog(null,"恭喜你提交成功")
fr1.setVisible(false)
// Operator s= new Operator("设计")//普通用户
//s.ti()
}
if(tf1.getText().equals("wp")&tf2.getText().equals("123456")&cb1.isSelected()){
JOptionPane.showMessageDialog(null,"恭喜你提交成功")
fr1.setVisible(false)
// Operator s=new Operator("设计")//普通用户
//s.ti()
}
if(tf1.getText().equals("王琼琨")&tf2.getText().equals("123456")&cb1.isSelected()){
JOptionPane.showMessageDialog(null,"恭喜你提交成功")
fr1.setVisible(false)
//Operator s= new Operator("设计")//普通用户
//s.ti()//普通用户
}
if(tf1.getText().equals("陈银山")&tf2.getText().equals("123456")&cb3.isSelected()){
fr1.setVisible(false)
JOptionPane.showMessageDialog(null,"恭喜你提交成功")//高级管理员
//new Operator("设计")//普通用户
}
if(tf1.getText().equals("刘凡")&tf2.getText().equals("6598")&cb2.isSelected()){
JOptionPane.showMessageDialog(null,"恭喜你提交成功")//图书管路元
fr1.setVisible(false)
//Operator s= new Operator("设计")//图书挂历员 用户
//s.ti1()
}
if(tf1.getText().trim().equals(""))
{
JOptionPane.showMessageDialog(null,"用户名不能为空!")
return
}
if(passwordSTR.equals(""))
{
JOptionPane.showMessageDialog(null,"密码不能为空!")
return
}
else{
userName=tf1.getText().trim()
}
String strSQL
strSQL="select * from users where 用户名='"+
tf1.getText().trim()+"'and 密码='"+
passwordSTR+"'"
//rs=db.getResult(strSQL)
boolean isExist=false
try
{
//isExist=rs.first()
}
catch(Exception sqle)
{
System.out.println(sqle.toString())
}
if(!isExist)
{
JOptionPane.showMessageDialog(null,"用户名不存在或者密码不正确!")
System.out.print("连接失败")
// this.setEnable("else")
}
else
{
//try
//{
////rs.first()
////this.setEnable(rs.getString("权限").trim())//设置权限
//// db.closeConnection()//DataBase
//}
//catch(SQLException sqle2)
//{
//System.out.println(sqle2.toString())
//}
}
}
}
/**
* 设置登录用户的权限
*
*/
public void setEnable(String powerType)
{
/**
* 根据不同用户设置相应权限
*/
//Operator p=new Operator()
if(powerType.trim().equals("系统管理员"))
{
System.out.println ("系统管理员")
//p.showframe()
}
else if(powerType.trim().equals("书籍管理员"))
{
System.out.println ("书籍管理员")
//p.showframe()
//p.menuItem6.setEnabled(false)
}
else if(powerType.trim().equals("else"))
{
System.out.println ("其他")
//p.showframe()
//p.menu0.setEnabled(false)
//p.menu2.setEnabled(false)
}
}
/**
* 登陆
*/
public static void main(String args []){
new MyFrame()
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)