プログラミングのアイデア:
最初は、ログインページ、登録ページ、およびホーム・ページです
データは、テーブルに格納することができる、すなわち、登録されたユーザは、グラフィックス・フレーム内のデータを入力することができ
データがあるかどうかを確認するために、バックエンドのすべてのデータを取得します
ランダム符号を生成し、認証コード表示の入力を要求に対応
最後に、ログインを完了するために
出典:
パッケージyanzhengma。
輸入java.awt.event.ActionEvent。
輸入java.awt.event.ActionListener。
輸入java.awt.event.ActionListener。
輸入javax.swing.JButtonの。
輸入javax.swing.JFrame;
輸入javax.swing.JLabel。
輸入javax.swing.JOptionPane;
輸入javax.swing.JPanel。
輸入javax.swing.JPasswordField。
輸入javax.swing.JTextField。
輸入javax.swing.JFrame;
輸入javax.swing.JLabel。
輸入javax.swing.JOptionPane;
輸入javax.swing.JPanel。
輸入javax.swing.JPasswordField。
輸入javax.swing.JTextField。
パブリッククラスインターフェースのJFrame {延び
プライベート静的最終長いのserialVersionUID = 1Lと、
プライベート静的最終長いのserialVersionUID = 1Lと、
プライベート静的な文字列レコード。
パブリック静的無効メイン(文字列[] args){
新しいインターフェイス()。
}
新しいインターフェイス()。
}
インターフェイスを公開(){
// JFrameのインスタンスを作成し
たJFrameフレーム=新しいJFrameのを( "ログインしてください:");
// JFrameのインスタンスを作成し
たJFrameフレーム=新しいJFrameのを( "ログインしてください:");
//设置フレーム大小
frame.setLocation(500、300)。
frame.setSize(400、200)。
frame.setResizable(偽);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)。
frame.setLocation(500、300)。
frame.setSize(400、200)。
frame.setResizable(偽);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)。
//パネル作成
)(JPanelのパネル=新しいJPanelのを。
)(JPanelのパネル=新しいJPanelのを。
//パネルの追加
frame.add(パネル)。
frame.add(パネル)。
//パネルの特定の形態を設定し
placeComponents(パネル)。
placeComponents(パネル)。
//設定インターフェースが表示され
frame.setVisible(TRUE)。
frame.setVisible(TRUE)。
}
公共ボイドplaceComponents(JPanelのパネル){
//パネルクリア
panel.setLayout(null)を、
panel.setLayout(null)を、
//ユーザコンポーネント作成
JLabelのuserLabel =新しいJLabelの( "ユーザ名:");
userLabel.setBounds(10、20、80、25である);
(userLabel)panel.add。
JLabelのuserLabel =新しいJLabelの( "ユーザ名:");
userLabel.setBounds(10、20、80、25である);
(userLabel)panel.add。
//入力するユーザのためのテキストフィールドを作成し
(20)のJTextField =新しい新しいuserTextにJTextFieldのを、
userText.setBounds(100、20、165、25である);
(userText)panel.add。
(20)のJTextField =新しい新しいuserTextにJTextFieldのを、
userText.setBounds(100、20、165、25である);
(userText)panel.add。
//パスワードコンポーネント作成
JLabelのpasswordLabel =新しいJLabelの( "パスワード");
passwordLabel.setBounds(10、50、80、25);
(passwordLabel)panel.add。
JLabelのpasswordLabel =新しいJLabelの( "パスワード");
passwordLabel.setBounds(10、50、80、25);
(passwordLabel)panel.add。
//パスワードテキストフィールド作成
のJPasswordField PasswordText =新しい新しいのJPasswordFieldを(20);
passwordText.setBounds(100、50、165、25);
panel.add(PasswordText)。
のJPasswordField PasswordText =新しい新しいのJPasswordFieldを(20);
passwordText.setBounds(100、50、165、25);
panel.add(PasswordText)。
//使用コンポーネント検証コード作成
JLabelのverificationLabel =新しいJLabelの( "検証コード:");
verificationLabel.setBounds(10、80、80、25);
(verificationLabel)panel.add。
JLabelのverificationLabel =新しいJLabelの( "検証コード:");
verificationLabel.setBounds(10、80、80、25);
(verificationLabel)panel.add。
//テキストフィールドコードを作成
=新しい新しいverificationText JTextFieldのJTextFieldの(20)を、
verificationText.setBounds(100、80、80、25);
(verificationText)panel.add。
=新しい新しいverificationText JTextFieldのJTextFieldの(20)を、
verificationText.setBounds(100、80、80、25);
(verificationText)panel.add。
//ランダムな文字列を作成
; = ""文字列結果の
ための(INT I = 0;私は<6; I ++){
int型INTVAL =(INT)(Math.random()* 26で+ 97);
結果=結果+(チャー)INTVAL;
}
レコード=結果。
; = ""文字列結果の
ための(INT I = 0;私は<6; I ++){
int型INTVAL =(INT)(Math.random()* 26で+ 97);
結果=結果+(チャー)INTVAL;
}
レコード=結果。
//使用する確認コード表示部品を作成
JLabelのverificationShowLabel JLabelの新しい新=(結果);
verificationShowLabel.setBounds(200、80、80、25);
(verificationShowLabel)panel.add。
JLabelのverificationShowLabel JLabelの新しい新=(結果);
verificationShowLabel.setBounds(200、80、80、25);
(verificationShowLabel)panel.add。
//ログインボタン作成
JButtonのloginButton =新規のJButtonを( "ログイン");
loginButton.setBounds(10、120、80、25);
panel.add(loginButton)。
JButtonのloginButton =新規のJButtonを( "ログイン");
loginButton.setBounds(10、120、80、25);
panel.add(loginButton)。
//監視するためのボタン
のActionListener =新しい新ourListener1のActionListener(){
公共空のactionPerformed(のActionEvent E){
IF(e.getSource()== loginButton)//が決定していないかどうか、ログインボタンをクリックし
、{
IF(record.equalsIgnoreCase(verificationText.getText ()))//正しい照合コードか否かを判定する
{
IF(StoreroomManager.datelist.size()== 0)//データメモリ空間があるか否かを判定する
{
JOptionPane.showMessageDialogは(NULL) "あなたが登録していない";
userText。 setText( "");
passwordText.setText( "");
のActionListener =新しい新ourListener1のActionListener(){
公共空のactionPerformed(のActionEvent E){
IF(e.getSource()== loginButton)//が決定していないかどうか、ログインボタンをクリックし
、{
IF(record.equalsIgnoreCase(verificationText.getText ()))//正しい照合コードか否かを判定する
{
IF(StoreroomManager.datelist.size()== 0)//データメモリ空間があるか否かを判定する
{
JOptionPane.showMessageDialogは(NULL) "あなたが登録していない";
userText。 setText( "");
passwordText.setText( "");
} //既存の割当日さもなければ、登録ユーザが存在するかどうかを取得
{
物置物置日=新しい新しいは();
date.setUser(userText.getText()); //ユーザ名は、ユーザによって入力され得る
日付。 setPassword(passwordText.getText()); //パスワードは、ユーザーが入力した取得
; StoreroomManager.confirmDate(DATE)
passwordText.setText( "");
verificationText.setText( "");
}
} //このコードは、他の修正されていない
{
PasswordText .setText( "");
verificationText.setText( "");
JOptionPane.showMessageDialog(ヌル、 "コードが正しくない、再入力してください");
//ランダムな文字列を作成し
、文字列の検索結果を= "";
(私は= int型のために0; iは6 <; iは++ ){
INT INTVAL =(INT)(Math.random()* 26 + 97)。
結果=結果+(CHAR)INTVAL。
}
レコード=結果。
verificationShowLabel.setText(結果)。
{
物置物置日=新しい新しいは();
date.setUser(userText.getText()); //ユーザ名は、ユーザによって入力され得る
日付。 setPassword(passwordText.getText()); //パスワードは、ユーザーが入力した取得
; StoreroomManager.confirmDate(DATE)
passwordText.setText( "");
verificationText.setText( "");
}
} //このコードは、他の修正されていない
{
PasswordText .setText( "");
verificationText.setText( "");
JOptionPane.showMessageDialog(ヌル、 "コードが正しくない、再入力してください");
//ランダムな文字列を作成し
、文字列の検索結果を= "";
(私は= int型のために0; iは6 <; iは++ ){
INT INTVAL =(INT)(Math.random()* 26 + 97)。
結果=結果+(CHAR)INTVAL。
}
レコード=結果。
verificationShowLabel.setText(結果)。
}
}
}
}。
loginButton.addActionListener(ourListener1)。
}
}
}。
loginButton.addActionListener(ourListener1)。
//登録ボタン作成し
、JButtonのregisterButton =新しいJButtonの( "登録")
registerButton.setBounds(100、120、80、25);
(registerButton)panel.add。
、JButtonのregisterButton =新しいJButtonの( "登録")
registerButton.setBounds(100、120、80、25);
(registerButton)panel.add。
//对按钮进行监视
のActionListener ourListener2 =新規のActionListener(){
公共ボイドのactionPerformed(のActionEvent E){
IF(e.getSource()== registerButton){
userText.setText( "")。
passwordText.setText( "");
verificationText.setText( "");
新しいRegisterInterface();
}
}
}。
registerButton.addActionListener(ourListener2)。
のActionListener ourListener2 =新規のActionListener(){
公共ボイドのactionPerformed(のActionEvent E){
IF(e.getSource()== registerButton){
userText.setText( "")。
passwordText.setText( "");
verificationText.setText( "");
新しいRegisterInterface();
}
}
}。
registerButton.addActionListener(ourListener2)。
//更新ボタン作成
JButtonのrefreshButton =新しいJButtonのを( "リフレッシュ");
refreshButton.setBounds(250、80、80、25);
panel.add(refreshButton)。
JButtonのrefreshButton =新しいJButtonのを( "リフレッシュ");
refreshButton.setBounds(250、80、80、25);
panel.add(refreshButton)。
監視する//ボタン
のActionListener =新しい新しいourListener3のActionListener(){
公共ボイドのactionPerformed(のActionEvent E){
IF(refreshButtonにe.getSource()==){
passwordText.setTextを( "");
verificationText.setText( "")。
//ランダムな文字列を作成
; = ""文字列検索結果を
するための(INT I = 0;私は<6; I ++){
int型INTVAL =(INT)(Math.random()* 26で+ 97);
結果=結果+(チャー)INTVAL;
}
レコード=結果、
verificationShowLabel.setText(結果)。
のActionListener =新しい新しいourListener3のActionListener(){
公共ボイドのactionPerformed(のActionEvent E){
IF(refreshButtonにe.getSource()==){
passwordText.setTextを( "");
verificationText.setText( "")。
//ランダムな文字列を作成
; = ""文字列検索結果を
するための(INT I = 0;私は<6; I ++){
int型INTVAL =(INT)(Math.random()* 26で+ 97);
結果=結果+(チャー)INTVAL;
}
レコード=結果、
verificationShowLabel.setText(結果)。
}
}
}。
refreshButton.addActionListener(ourListener3)。
}
}
}
}。
refreshButton.addActionListener(ourListener3)。
}
}
//このファイルには、データを格納するためのデータベースと同等です
パッケージyanzhengma。
輸入はjava.util.ArrayList;
輸入はjava.util.List;
輸入はjava.util.List;
輸入javax.swing.JOptionPane;
クラス物置{
プライベート文字列ユーザー;
プライベート文字列のパスワード。
プライベート文字列ユーザー;
プライベート文字列のパスワード。
ボイドSETUSER(文字列str){
ユーザー= STR。
}
ユーザー= STR。
}
ストリングのgetUser(){
リターンユーザー。
リターンユーザー。
}
するsetPassword(文字列str){無効
パスワード= STRと、
}
パスワード= STRと、
}
文字列getPasswordに(){
戻りパスワード。
戻りパスワード。
}
}
クラスStoreroomManager //は、データクラスに対して作用
{
静的リスト<物置> =新しい新しいdatelistのArrayList <物置>(0)。
{
静的リスト<物置> =新しい新しいdatelistのArrayList <物置>(0)。
静的ボイドconfirmDate(物置日)//データを介してログ
{
フラグ= 0のint。
{
フラグ= 0のint。
以下のために(INT i = 0; iは<datelist.size(); iは++){
IF(。date.getUser()equalsIgnoreCase(datelist.get(I).getUser())){
。IF(date.getpassword()equalsIgnoreCase (datelist.get(I).getpassword())){
JOptionPane.showMessageDialog(ヌル、 "登录成功")。
フラグ++;
}
IF(。date.getUser()equalsIgnoreCase(datelist.get(I).getUser())){
。IF(date.getpassword()equalsIgnoreCase (datelist.get(I).getpassword())){
JOptionPane.showMessageDialog(ヌル、 "登录成功")。
フラグ++;
}
}
}
( "データ入力:")のSystem.out.println;
のSystem.out.println( "ユーザ名:" + date.getUser());
のSystem.out.println( "パスワード:" + date.getpassword( ));
のための(INT I = 0;私は<datelist.size();私は++){
するSystem.out.println( "テーブル" +(I + 1)+ " データ");
のSystem.out。 println( "ユーザ名" + datelist.get(I).getUser());
のSystem.out.println( "パスワード" + datelist.get(I).getpassword());
}
(フラグに== 0 IF ){
JOptionPane.showMessageDialog(ヌル、 "ユーザー名またはパスワードが間違っています!");
}
}
( "データ入力:")のSystem.out.println;
のSystem.out.println( "ユーザ名:" + date.getUser());
のSystem.out.println( "パスワード:" + date.getpassword( ));
のための(INT I = 0;私は<datelist.size();私は++){
するSystem.out.println( "テーブル" +(I + 1)+ " データ");
のSystem.out。 println( "ユーザ名" + datelist.get(I).getUser());
のSystem.out.println( "パスワード" + datelist.get(I).getpassword());
}
(フラグに== 0 IF ){
JOptionPane.showMessageDialog(ヌル、 "ユーザー名またはパスワードが間違っています!");
}
}
静的ブールsearchDate(物置日)//登录、遍历数据
{
int型フラグ= 0。
以下のために(INT i = 0; iはdatelist.size()<; iは++){
IF(。date.getUser()に等しい(datelist.get(I).getUser()))
。IF(date.getpassword()に等しいと( datelist.get(I).getpassword()))
フラグ++。
}
(フラグ== 0)の場合に
falseを返します。
他に
trueを返します。
{
int型フラグ= 0。
以下のために(INT i = 0; iはdatelist.size()<; iは++){
IF(。date.getUser()に等しい(datelist.get(I).getUser()))
。IF(date.getpassword()に等しいと( datelist.get(I).getpassword()))
フラグ++。
}
(フラグ== 0)の場合に
falseを返します。
他に
trueを返します。
}
}
//この文書では、クラスのインタフェースとほぼ同じです
パッケージyanzhengma。
輸入java.awt.event.ActionEvent。
輸入java.awt.event.ActionListener。
輸入java.awt.event.ActionListener。
輸入javax.swing.JButtonの。
輸入javax.swing.JFrame;
輸入javax.swing.JLabel。
輸入javax.swing.JOptionPane;
輸入javax.swing.JPanel。
輸入javax.swing.JPasswordField。
輸入javax.swing.JTextField。
輸入javax.swing.JFrame;
輸入javax.swing.JLabel。
輸入javax.swing.JOptionPane;
輸入javax.swing.JPanel。
輸入javax.swing.JPasswordField。
輸入javax.swing.JTextField。
パブリッククラスRegisterInterface {
プライベート静的な文字列レコード。
registerInterfaceパブリック(){
// JFrameのインスタンスの作成
(「登録ページへようこそ:」)=新しいJFrameのJFrameのフレームを、
// JFrameのインスタンスの作成
(「登録ページへようこそ:」)=新しいJFrameのJFrameのフレームを、
//设置フレーム大小
frame.setLocation(500、300)。
frame.setSize(400、200)。
frame.setResizable(偽);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)。
frame.setLocation(500、300)。
frame.setSize(400、200)。
frame.setResizable(偽);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)。
//パネル作成
)(JPanelのパネル=新しいJPanelのを。
)(JPanelのパネル=新しいJPanelのを。
//パネルの追加
frame.add(パネル)。
frame.add(パネル)。
//設定パネルの特定の形態の
placeComponents(パネル、フレーム)。
placeComponents(パネル、フレーム)。
//設定インターフェースが表示され
frame.setVisible(TRUE)。
frame.setVisible(TRUE)。
}
公共のボイドplaceComponents(JPanelのパネル、JFrameのフレーム){
//クリアパネル
panel.setLayout(NULL);
//クリアパネル
panel.setLayout(NULL);
//ユーザコンポーネント作成
JLabelのuserLabel =新しいJLabelの( "ユーザ名:");
userLabel.setBounds(10、20、80、25である);
(userLabel)panel.add。
JLabelのuserLabel =新しいJLabelの( "ユーザ名:");
userLabel.setBounds(10、20、80、25である);
(userLabel)panel.add。
//入力するユーザのためのテキストフィールドを作成し
(20)のJTextField =新しい新しいuserTextにJTextFieldのを、
userText.setBounds(100、20、165、25である);
(userText)panel.add。
(20)のJTextField =新しい新しいuserTextにJTextFieldのを、
userText.setBounds(100、20、165、25である);
(userText)panel.add。
//パスワードコンポーネント作成
JLabelのpasswordLabel =新しいJLabelの( "パスワード");
passwordLabel.setBounds(10、50、80、25);
(passwordLabel)panel.add。
JLabelのpasswordLabel =新しいJLabelの( "パスワード");
passwordLabel.setBounds(10、50、80、25);
(passwordLabel)panel.add。
//パスワードテキストフィールド作成
のJPasswordField PasswordText =新しい新しいのJPasswordFieldを(20);
passwordText.setBounds(100、50、165、25);
panel.add(PasswordText)。
のJPasswordField PasswordText =新しい新しいのJPasswordFieldを(20);
passwordText.setBounds(100、50、165、25);
panel.add(PasswordText)。
//使用コンポーネント検証コード作成
JLabelのverificationLabel =新しいJLabelの( "検証コード:");
verificationLabel.setBounds(10、80、80、25);
(verificationLabel)panel.add。
JLabelのverificationLabel =新しいJLabelの( "検証コード:");
verificationLabel.setBounds(10、80、80、25);
(verificationLabel)panel.add。
//テキストフィールドコードを作成
=新しい新しいverificationText JTextFieldのJTextFieldの(20)を、
verificationText.setBounds(100、80、80、25);
(verificationText)panel.add。
=新しい新しいverificationText JTextFieldのJTextFieldの(20)を、
verificationText.setBounds(100、80、80、25);
(verificationText)panel.add。
//ランダムな文字列を作成
; = ""文字列結果の
ための(INT I = 0;私は<6; I ++){
int型INTVAL =(INT)(Math.random()* 26で+ 97);
結果=結果+(チャー)INTVAL;
}
レコード=結果。
; = ""文字列結果の
ための(INT I = 0;私は<6; I ++){
int型INTVAL =(INT)(Math.random()* 26で+ 97);
結果=結果+(チャー)INTVAL;
}
レコード=結果。
//使用する確認コード表示部品を作成
JLabelのverificationShowLabel JLabelの新しい新=(結果);
verificationShowLabel.setBounds(200、80、80、25);
(verificationShowLabel)panel.add。
JLabelのverificationShowLabel JLabelの新しい新=(結果);
verificationShowLabel.setBounds(200、80、80、25);
(verificationShowLabel)panel.add。
//確認ボタン作成
JButtonのconfirmButton =新しいJButtonの( "OK");
confirmButton.setBounds(10、120、80、25);
panel.add(ConfirmButton)を、
JButtonのconfirmButton =新しいJButtonの( "OK");
confirmButton.setBounds(10、120、80、25);
panel.add(ConfirmButton)を、
//モニタ(確認、すなわち、登録ボタン)上のボタン
のActionListener ourListener1のActionListener新しい新=(){
公共ボイドのactionPerformed(のActionEvent E){
のActionListener ourListener1のActionListener新しい新=(){
公共ボイドのactionPerformed(のActionEvent E){
IF(e.getSource()== confirmButton){
IF(record.equalsIgnoreCase(verificationText.getText())){
物置日=新しい物置()。
date.setUser(userText.getText())。
date.setPassword(passwordText.getText())。
もし(StoreroomManager.searchDate(日))
frame.dispose();
他{
StoreroomManager.datelist.add(日付)。
frame.dispose();
}
}他{
JOptionPane.showMessageDialog(ヌル、 "验证码错误、请重新输入")。
verificationText.setText( "");
passwordText.setText( "");
IF(record.equalsIgnoreCase(verificationText.getText())){
物置日=新しい物置()。
date.setUser(userText.getText())。
date.setPassword(passwordText.getText())。
もし(StoreroomManager.searchDate(日))
frame.dispose();
他{
StoreroomManager.datelist.add(日付)。
frame.dispose();
}
}他{
JOptionPane.showMessageDialog(ヌル、 "验证码错误、请重新输入")。
verificationText.setText( "");
passwordText.setText( "");
//ランダムな文字列を作成
; = ""文字列結果の
ための(INT I = 0;私は<6; I ++){
int型INTVAL =(INT)(Math.random()* 26で+ 97);
結果=結果+(チャー)INTVAL;
}
レコード=結果、
verificationShowLabel.setText(結果);
}
; = ""文字列結果の
ための(INT I = 0;私は<6; I ++){
int型INTVAL =(INT)(Math.random()* 26で+ 97);
結果=結果+(チャー)INTVAL;
}
レコード=結果、
verificationShowLabel.setText(結果);
}
}
}
}
}。
confirmButton.addActionListener(ourListener1)。
confirmButton.addActionListener(ourListener1)。
//キャンセルボタン作成
するJButton cancelButton =新規のJButtonを( "キャンセル");
cancelButton.setBounds(100、120、80、25);
(cancelButtonにより)panel.add。
するJButton cancelButton =新規のJButtonを( "キャンセル");
cancelButton.setBounds(100、120、80、25);
(cancelButtonにより)panel.add。
//对按钮进行监视
のActionListener ourListener2 =新しいのActionListener(){
公共空のactionPerformed(のActionEvent e)は{
場合(e.getSource()== cancelButton){
JOptionPane.showMessageDialog(ヌル、 "あなたは私をからかっています!");
frame.dispose();
}
}
}。
cancelButton.addActionListener(ourListener2)。
のActionListener ourListener2 =新しいのActionListener(){
公共空のactionPerformed(のActionEvent e)は{
場合(e.getSource()== cancelButton){
JOptionPane.showMessageDialog(ヌル、 "あなたは私をからかっています!");
frame.dispose();
}
}
}。
cancelButton.addActionListener(ourListener2)。
//更新ボタン作成
JButtonのrefreshButton =新しいJButtonのを( "リフレッシュ");
refreshButton.setBounds(250、80、80、25);
panel.add(refreshButton)。
JButtonのrefreshButton =新しいJButtonのを( "リフレッシュ");
refreshButton.setBounds(250、80、80、25);
panel.add(refreshButton)。
監視する//ボタン
のActionListener =新しい新しいourListener3のActionListener(){
公共ボイドのactionPerformed(のActionEvent E){
IF(refreshButtonにe.getSource()==){
passwordText.setTextを( "");
verificationText.setText( "")。
//ランダムな文字列を作成
; = ""文字列検索結果を
するための(INT I = 0;私は<6; I ++){
int型INTVAL =(INT)(Math.random()* 26で+ 97);
結果=結果+(チャー)INTVAL;
}
レコード=結果、
verificationShowLabel.setText(結果)。
のActionListener =新しい新しいourListener3のActionListener(){
公共ボイドのactionPerformed(のActionEvent E){
IF(refreshButtonにe.getSource()==){
passwordText.setTextを( "");
verificationText.setText( "")。
//ランダムな文字列を作成
; = ""文字列検索結果を
するための(INT I = 0;私は<6; I ++){
int型INTVAL =(INT)(Math.random()* 26で+ 97);
結果=結果+(チャー)INTVAL;
}
レコード=結果、
verificationShowLabel.setText(結果)。
}
}
}。
refreshButton.addActionListener(ourListener3)。
}
}。
refreshButton.addActionListener(ourListener3)。
}
}
}