求Java编的登录界面代码:登录后分别进入管理员界面及用户界面,依据是数据库中的用户名和密码分三个包,自己建个包,导进去就ok了,数据库是access的 。
package 登录;
import java.awt.EventQueue;
public class Cilent {
private JFrame frame;
private JTextField textField;
private JPasswordField passwordField;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Cilent window = new Cilent();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Cilent() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setTitle("登陆界面");
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
frame.setResizable(false);
JLabel lblNewLabel = new JLabel("用户名");
lblNewLabel.setBounds(38, 43, 80, 34);
frame.getContentPane().add(lblNewLabel);
textField = new JTextField();
textField.setBounds(155, 42, 227, 37);
frame.getContentPane().add(textField);
textField.setColumns(10);
JLabel label = new JLabel("密 码");
label.setBounds(38, 115, 80, 34);
frame.getContentPane().add(label);
passwordField = new JPasswordField();
passwordField.setBounds(155, 115, 227, 37);
frame.getContentPane().add(passwordField);
JButton btnNewButton = new JButton("登 录");
btnNewButton.setBounds(60, 187, 115, 34);
frame.getContentPane().add(btnNewButton);
btnNewButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
UserCheck UC=new UserCheck(textField.getText(),String.valueOf(passwordField.getPassword()));
if(UC.getI()!=0)//有此用户
{
frame.setVisible(false);
}
else
{
textField.setText("");
passwordField.setText("");
}
}
});
JButton button = new JButton("取 消");
button.setBounds(242, 187, 115, 34);
frame.getContentPane().add(button);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
textField.setText("");
passwordField.setText("");
}
});
}
}
/*****************************************************************/
package 登录;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import 操作处理.UsersCL;
/**@author 20111024
* 检测登录的用户在数据库中有无,若没有,则提示没有此用户,
* 若有,则判断级别:普通用户还是管理员 。
*/
public class UserCheck {
private int i=0;//用户级别:0不是用户、1是管理员、2是普通用户
UserCheck(String name ,String password)
{
String jdriver="sun.jdbc.odbc.JdbcOdbcDriver";
String connectDB="jdbc:odbc:Students";
Statement stmt=null;
ResultSet rs=null;
Connection con=null;
try {
Class.forName(jdriver);
con=DriverManager.getConnection(connectDB);
stmt=con.createStatement();
String query="select * from users where name='" name "' and passwd='" password "'";
rs=stmt.executeQuery(query);
if(rs.next())
{
//数据库中有此用户,访问成功
i=Integer.parseInt(rs.getString(3));
UsersCL UL=new UsersCL(i);
}
else
{
i=0;//没有用户是默认是0级
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public int getI() {
return i;
}
}
/********************************************************************************************/
package 操作处理;
import java.awt.EventQueue;
public class UsersCL implements ActionListener{
private JFrame frame;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_3;
private int i=0;
private JLabel label_3;
private JTextField textField_4;
public UsersCL(int i) {
this.i=i;
frame = new JFrame();
frame.setTitle("用户处理界面");
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
frame.setResizable(false);
frame.setVisible(true);
JLabel lblNewLabel = new JLabel("学 号");
lblNewLabel.setBounds(24, 32, 74, 29);
frame.getContentPane().add(lblNewLabel);
JLabel label = new JLabel("姓 名");
label.setBounds(24, 71, 74, 29);
frame.getContentPane().add(label);
JLabel label_1 = new JLabel("年 龄");
label_1.setBounds(24, 110, 74, 29);
frame.getContentPane().add(label_1);
label_3 = new JLabel("性 别");
label_3.setBounds(24, 149, 74, 29);
frame.getContentPane().add(label_3);
JLabel label_2 = new JLabel("状 态");
label_2.setBounds(24, 195, 74, 29);
frame.getContentPane().add(label_2);
textField = new JTextField();
textField.setBounds(101, 34, 113, 25);
frame.getContentPane().add(textField);
textField.setColumns(10);
textField_1 = new JTextField();
textField_1.setColumns(10);
textField_1.setBounds(101, 73, 113, 25);
frame.getContentPane().add(textField_1);
textField_2 = new JTextField();
textField_2.setColumns(10);
textField_2.setBounds(101, 112, 113, 25);
frame.getContentPane().add(textField_2);
textField_3 = new JTextField();
textField_3.setEditable(false);
textField_3.setColumns(10);
textField_3.setBounds(101, 199, 288, 25);
frame.getContentPane().add(textField_3);
textField_4 = new JTextField();
textField_4.setColumns(10);
textField_4.setBounds(101, 149, 113, 25);
frame.getContentPane().add(textField_4);
if(1==i)
{
JButton btnNewButton = new JButton("追 加");
btnNewButton.setBounds(276, 41, 113, 29);
frame.getContentPane().add(btnNewButton);
btnNewButton.addActionListener(this);
btnNewButton.setActionCommand("追加");
JButton button_1 = new JButton("删 除");
button_1.setBounds(276, 145, 113, 29);
frame.getContentPane().add(button_1);
button_1.addActionListener(this);
button_1.setActionCommand("删除");
}
JButton button = new JButton("查 询");
button.setBounds(276, 91, 113, 29);
frame.getContentPane().add(button);
button.addActionListener(this);
button.setActionCommand("查询");
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String name,age,sex,query=null;
int num,age1,count=0;
num=Integer.parseInt(textField.getText());
name=textField_1.getText();
age1=Integer.parseInt(textField_2.getText());
sex=textField_4.getText();
if(e.getActionCommand().equals("追加"))
{
query="insert into students values(" num "," "'" name "'," age1 ",'" sex "');";
count=1;
}
else if(e.getActionCommand().equals("查询"))
{
query="select * from students where XSB=" num ";";
count=2;
}
else if(e.getActionCommand().equals("删除"))
{
query="delete from students where XSB=" num " and name=" "'" name "'";
count=3;
}
Statement stmt=null;
ResultSet rs=null;
Connection con=null;
String jdriver="sun.jdbc.odbc.JdbcOdbcDriver";
String connectDB="jdbc:odbc:Students";
String query1=null;
try {
Class.forName(jdriver);
con=DriverManager.getConnection(connectDB);
stmt=con.createStatement();
if(count==1)
{
query1="select * from students where XSB=" num ";";
rs=stmt.executeQuery(query1);
if(rs.next())
textField_3.setText("已经由此记录,不能追加!");
else
{
stmt.executeUpdate(query);
textField_3.setText("已经追加完成!");
}
}
else if(2==count)
{
stmt.executeQuery(query);
rs=stmt.executeQuery(query);
if(rs.next())
{
textField_3.setText("已查找到此记录!");
}
else
{
textField_3.setText("没有此记录,可以追加!");
}
}
else if(3==count)
{
query1="select * from students where XSB=" num " and name=" "'" name "'";
rs=stmt.executeQuery(query1);
if(rs.next())
{
stmt.executeUpdate(query);
textField_3.setText("已删除此记录!");
}
else
textField_3.setText("无此记录!");
}
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
finally{
//关闭资源
if(stmt!=null){
try {
stmt.close();
} catch (Exception e2) {
// TODO: handle exception
}
stmt=null;
}
if(con!=null){
try {
con.close();
} catch (Exception e2) {
// TODO: handle exception
}
con=null;
}
}
}
}
java公交线路管理系统//写了两个小时啊,兄弟,要采纳java公交系统登录代码我啊
//Site(站点类)
package transit;
import java.util.ArrayList;
import java.util.List;
public class Site
{
private Integer id; // 给每个站点分配一个ID
private String name; // 站点java公交系统登录代码的名字
private ListRoute list; // 经过该站点的线路
public Site()
{
super();
}
public Site(Integer id, String name)
{
super();
this.id = id;
this.name = name;
this.list = new ArrayListRoute();
}
public Integer getId()
{
return id;
}
public void setId(Integer id)
{
this.id = id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public ListRoute getList()
{
return list;
}
public void setList(ListRoute list)
{
this.list = list;
}
// 添加线路
public boolean addRoute(Route route)
{
return this.getList().add(route);
}
// 删除线路
public boolean removeRoute(Route route)
{
return this.getList().remove(route);
}
@Override
public String toString()
{
return name;
}
@Override
public boolean equals(Object obj)
{
if (obj instanceof Site)
{
Site s = (Site) obj;
return this.id == s.getId()this.name.equals(s.getName());
}
return false;
}
}
//线路类
package transit;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class Route
{
private Integer id; // 给每个线路分配一个ID
private String name; // 线路名称
private ListSite list; // 线路所包含的站点
private Date startDate; // 发班时间,从首站点算起
private Date endDate; // 收班时间,从首站点算起
public Route()
{
super();
}
public Route(Integer id, String name, Date startDate, Date endDate)
{
super();
this.id = id;
this.name = name;
this.startDate = startDate;
this.endDate = endDate;
this.list = new ArrayListSite();
}
public Integer getId()
{
return id;
}
public void setId(Integer id)
{
this.id = id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public ListSite getList()
{
return list;
}
public void setList(ListSite list)
{
this.list = list;
}
public Date getStartDate()
{
return startDate;
}
public void setStartDate(Date startDate)
{
this.startDate = startDate;
}
public Date getEndDate()
{
return endDate;
}
public void setEndDate(Date endDate)
{
this.endDate = endDate;
}
public boolean isHasThisSite(Site site)
{
for (Site l_site : this.getList())
{
if (l_site.equals(site))
{
return true;
}
}
return false;
}
// 添加站点,成功返回true
public boolean addSite(Site site)
{
return this.getList().add(site);
}
// 移除站点,成功返回true
public boolean removeSite(Site site)
{
return this.getList().remove(site);
}
@Override
public String toString()
{
return name;
}
}
//公交系统类
package transit;
import java.util.ArrayList;
import java.util.List;
public class TransitSystem
{
/**
* 1)增加、修改、删除一个条公交线路信息 。
* 2)增加、修改、删除公交站点信息 。
* 3)按条件显示公交线路信息(条件有按线路名称、途经车站等) 。
*/
private ListRoute routeList ;//系统所管理的线路
private ListSite siteList;//系统所管理的站点
public TransitSystem(){
routeList = new ArrayListRoute();
siteList = new ArrayListSite();
}
//增加一条线路
public void addRoute(Route route){
if(!routeList.add(route)){
throw new RuntimeException("系统中已存在该线路");
}
}
//修改一条线路
public void updateRoute(Route route){
//根据route 的id 获取已存在系统中的route
Route l_route = getRoute(route.getId());
if(l_route!=null){
//注入值
l_route.setName(route.getName());
l_route.setList(route.getList());
l_route.setStartDate(route.getStartDate());
l_route.setEndDate(route.getEndDate());
}else{
throw new RuntimeException("线路id不匹配,无法修改");
}
}
//获取该系统中的线路,根据id获取
public Route getRoute(Integer id){
Route route2 = null;
for (Route route : this.getRouteList())
{
if(route.getId().equals(id)){
route2 = route;
}
}
return route2;
}
//删除一条线路,根据对象删除
public void removeRoute(Route route){
if(!this.getRouteList().remove(route)){
throw new RuntimeException(route.getId() "线路不存在");
}
}
//增加一条公交站点
public void addSite(Site site){
if(!this.siteList.add(site)){
throw new RuntimeException(site.getId() "站点已存在");
}
}
//删除一条公交站点
public void removeSite(Site site){
if(!this.getSiteList().remove(site)){
throw new RuntimeException(site.getId() "站点不存在");
}
}
//修改一条公交站点
public void updateSite(Site site){
//根据route 的id 获取已存在系统中的route
Site l_site = getSite(site.getId());
if(l_site!=null){
//注入值
l_site.setName(site.getName());
l_site.setList(site.getList());
}else{
throw new RuntimeException("站点id不匹配,无法修改");
}
}
//获取该系统中的公交站点,根据id获取
public Site getSite(Integer id){
Site site2 = null;
for (Site site : this.getSiteList())
{
if(site.getId().equals(id)){
site2 = site;
}
}
return site2;
}
//按线路名称查询公交线路信息
public Route getRouteByName(String name){
for (Route route : this.getRouteList())
{
if(route.getName().equals(name)){
return route;
}
}
return null;
}
//根据途经车站查询公交线路
public ListRoute getRouteBySite(Site site){
return site.getList();
}
public ListRoute getRouteList()
{
return routeList;
}
public void setRouteList(ListRoute routeList)
{
this.routeList = routeList;
}
public ListSite getSiteList()
{
return siteList;
}
public void setSiteList(ListSite siteList)
{
this.siteList = siteList;
}
}
//测试类
package transit;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Random;
public class _Test
{
public static void main(String[] args) throws ParseException
{
TransitSystem system = new TransitSystem();
SimpleDateFormat format = new SimpleDateFormat("hh:MM");
Date startDate = format.parse("07:30");
Date endDate = format.parse("22:30");
// 向系统中添加10条线路,20个站点
for (int i = 0; i20; i)
{
if (i10)
{
system.addRoute(new Route(i, "线路"i, startDate, endDate));
}
system.addSite(new Site(i, "站点"i));
}
ListSite siteList = system.getSiteList();
// 为系统中的站点添加线路
for (Route route : system.getRouteList())
{
// 每条线路 随机添加N个站点
int n = new Random().nextInt(siteList.size());
for (int i = 0; in; i)
{
// 每个站点也是随机,如重复,则添加失败
int x = new Random().nextInt(siteList.size());
if (!route.isHasThisSite(siteList.get(x)))
{
route.addSite(siteList.get(x));
// 同时该站点也添加该线路
siteList.get(x).addRoute(route);
}
}
}
// 查询所有的线路所包含的站点
for (Route route : system.getRouteList())
{
System.out
.println(route.getName()" :对应的站点集合java公交系统登录代码:"route.getList());
}
// 查询所有的站点对应的线路
for (Site site : system.getSiteList())
{
System.out.println("站点"site.getName()" :对应的线路集合: "
site.getList());
}
}
}
登陆界面的java代码怎么写?import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
class LoginFrm extends JFrame implements ActionListener
{
JLabel lbl1=new JLabel("用户名");
JLabel lbl2=new JLabel("密码");
JTextField txt=new JTextField(15);
JPasswordField pf=new JPasswordField();
JButton btn1=new JButton("确定");
JButton btn2=new JButton("取消");
public LoginFrm()
{
this.setTitle("登陆");
JPanel jp=(JPanel)this.getContentPane();
jp.setLayout(new GridLayout(3,2,10,10));
jp.add(lbl1);jp.add(txt);
jp.add(lbl2);jp.add(pf);
jp.add(btn1);jp.add(btn2);
btn1.addActionListener(this);
btn2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==btn1)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")java公交系统登录代码;
Connection con=DriverManager.getConnection("jdbc:odbc:MyDB","","");
Statement cmd=con.createStatement();
ResultSet rs=cmd.executeQuery("select * from loginAndpassword where login='" txt.getText() "' and password='" pf.getText() "'");
if(rs.next())
{
JOptionPane.showMessageDialog(null,"登陆成功java公交系统登录代码!");
}
else
JOptionPane.showMessageDialog(null,"用户名或密码错误java公交系统登录代码!");
} catch(Exception ex){}
if(ae.getSource()==btn2)
{
txt.setText("");
pf.setText("");
}
}
}
public static void main(String arg[])
{
JFrame.setDefaultLookAndFeelDecorated(true);
LoginFrm frm=new LoginFrm();
frm.setSize(400,200);
frm.setVisible(true);
}
}
JAVA中密码登陆代码怎么写看一下apache httpclientjava公交系统登录代码的包java公交系统登录代码,现成java公交系统登录代码的代码
【java公交系统登录代码 java公交车信息管理系统代码】关于java公交系统登录代码和java公交车信息管理系统代码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。
推荐阅读
- 跨境电商如何跟卖,跨境电商如何跟卖家聊天
- 我的世界游戏开发小说,我的世界游戏开发公司
- linux堆栈打印命令 linux查看堆栈调用信息
- 现在黑鲨手机推荐什么,黑鲨什么手机最好
- 好货内购小程序徐州注册,好货内购是什么怎么注册
- 公众号微网站怎么制作教程,微信公众号制作网页
- windows导航系统的简单介绍
- gis怎么下载高精度DEM,arcgis如何下载地图
- 陆磊区块链,区块链陆军