java管理員設(shè)置的代碼 java管理員設(shè)置的代碼在哪里

編寫管理員類Manger,使用show()方法返回管理員信息。java代碼

public?class?Manger{

創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),延津企業(yè)網(wǎng)站建設(shè),延津品牌網(wǎng)站建設(shè),網(wǎng)站定制,延津網(wǎng)站建設(shè)報價,網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,延津網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。

private?String?name;

private?String?code;

//構(gòu)造函數(shù)

public?Manger(String?name,String?code){

this.name?=?name;

this.code?=?code;

}

public?void?show(){

System.out.println("管理員信息用戶名為:"+this.name+"????密碼為:"+this.code);

}

public class MainTest{

//測試主方法

public static void main(){

Manger objManger = new?Manger("jadebird","0000");

objManger.show();

}

}

求Java編的登錄界面代碼:登錄后分別進入管理員界面及用戶界面,依據(jù)是數(shù)據(jù)庫中的用戶名和密碼

分三個包,自己建個包,導(dǎo)進去就ok了,數(shù)據(jù)庫是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

* 檢測登錄的用戶在數(shù)據(jù)庫中有無,若沒有,則提示沒有此用戶,

* 若有,則判斷級別:普通用戶還是管理員。

*/

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())

{

//數(shù)據(jù)庫中有此用戶,訪問成功

i=Integer.parseInt(rs.getString(3));

UsersCL UL=new UsersCL(i);

}

else

{

i=0; //沒有用戶是默認(rèn)是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("學(xué) 號");

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("狀 態(tài)");

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("已經(jīng)由此記錄,不能追加!");

else

{

stmt.executeUpdate(query);

textField_3.setText("已經(jīng)追加完成!");

}

}

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{

//關(guān)閉資源

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 管理員身份Runtime.getRuntime().exec

很簡單,用runas的方式來執(zhí)行。

比如以administrator的身份來啟動記事本:?

Runtime.getRuntime().exec("cmd?/C?cmd.exe?runAs?/user:administrator?notepad");

JAVA怎么實現(xiàn)輸入密碼錯誤三次就會被鎖定,需要管理員解鎖的代碼?

用While和一個計數(shù)變量,以下是偽代碼

定義計數(shù)變量并歸零

定義狀態(tài)變量并歸零

while(計數(shù)變量3且狀態(tài)變量為真)

{

輸入密碼

if(密碼正確)

{

狀態(tài)變量設(shè)定為真

}

else

{

計數(shù)變量+1

密碼框清空

}

}

if(狀態(tài)變量不為真) /說明前面的循環(huán)結(jié)束是因為輸錯了三次

{

提示:請管理員解鎖

【密碼輸入過程與上方用while循環(huán)類似】

}

else

{

(剩余操作)

}

Java代碼 求注釋 管理員登錄

package com.action;

import java.util.List;

import java.util.Map;

import org.apache.struts2.ServletActionContext;

import com.dao.TAdminDAO;

import com.model.TAdmin;

import com.opensymphony.xwork2.ActionSupport;

import com.util.Pagination;

public class adminAction extends ActionSupport

{

private int userId;//用戶id

private String userName;//用戶名

private String userPw;//用戶密碼

private String message;

private String path;

private int index=1;

private TAdminDAO adminDAO;//dao聲明

public String adminAdd()//增加用戶方法

{

TAdmin admin=new TAdmin();

admin.setUserName(userName);

admin.setUserPw(userPw);

adminDAO.save(admin);//調(diào)用dao方法

this.setMessage("操作成功");

this.setPath("adminManage.action");

return "succeed";//返回值

}

public String adminManage()//查找所有管理員

{

List adminList=adminDAO.findAll();

Map request=(Map)ServletActionContext.getContext().get("request");

request.put("adminList", adminList);//將列表存入adminList

return ActionSupport.SUCCESS;

}

public String adminManageFenye()//管理員列表的分頁查詢

{

List adminList=adminDAO.findAll();

int pageSize=3;

int fromIndex = (index - 1) * pageSize;

int toIndex = Math.min(fromIndex + pageSize, adminList.size());

List adminListFenye = adminList.subList(fromIndex, toIndex);

Pagination p = new Pagination();//創(chuàng)建 分頁對象

p.setIndex(index);//設(shè)置頁數(shù)

p.setPageSize(pageSize);

p.setTotle(adminList.size());//設(shè)置總共的條數(shù)

p.setData(adminListFenye);//設(shè)置數(shù)據(jù)

p.setPath("adminManageFenye.action?");//跳轉(zhuǎn)的路徑

Map request=(Map)ServletActionContext.getContext().get("request");

request.put("page", p);

return ActionSupport.SUCCESS;

}

名稱欄目:java管理員設(shè)置的代碼 java管理員設(shè)置的代碼在哪里
本文路徑:http://muchs.cn/article36/hjsepg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器網(wǎng)站設(shè)計公司、網(wǎng)站維護網(wǎng)站導(dǎo)航、外貿(mào)網(wǎng)站建設(shè)、微信公眾號

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

綿陽服務(wù)器托管