import java.util.Scanner;
創(chuàng)新互聯(lián)成立于2013年,是專(zhuān)業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元岳塘做網(wǎng)站,已為上家服務(wù),為岳塘各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:13518219792
public class Logon {
private static final char username = '青';
private static final int password = 123;
private static final Scanner san = new Scanner(System.in);
public static void main(String[] args) {
char iname;
int ipass;
System.out.print("請(qǐng)輸入用戶(hù)名: ");
iname = san.next().charAt(0);
System.out.print("請(qǐng)輸入密碼: ");
ipass = san.nextInt();
if(Logon.username == iname Logon.password == ipass) {
System.out.println("歡迎你, " + Logon.username);
} else {
System.out.println("對(duì)不起, 你不是" + Logon.username);
}
}
}
在JSP中確定密碼是否相同的方法是通過(guò)js實(shí)現(xiàn)的。
將onchange事件添加到兩個(gè)文本框中,并在文本框的內(nèi)容發(fā)生更改時(shí)觸發(fā)事件,并在此事件中寫(xiě)入判斷。
下面是步驟:
公共DOCTYPE HTML”- / / / / W3C XHTML 1.0 DTD過(guò)渡/ / EN " " "
HTML XMLNS = " "
頭
meta HTTP - equiv =“Content -type”內(nèi)容=“文本/HTML”。Charset = gb2312 "/ 。
script type = "text/javascript" 。
函數(shù)checkpwd () {
Var p1 =文檔。Form1。Pwd1。價(jià)值;//獲取密碼框的值。
Var p2 =文檔。Form1。Pwd2。價(jià)值;//獲取重新輸入的密碼值。
{if (p1 = = ")
警告(“請(qǐng)輸入您的密碼!”);//密碼被檢測(cè)為空,輸入//被記錄。
文檔。Form1。Pwd1。關(guān)注();//專(zhuān)注于密碼框。
返回錯(cuò)誤;//退出檢測(cè)功能。
}//如果允許一個(gè)空密碼,此條件可以被撤銷(xiāo)。
如果(p1 !=p2){//確定輸入值是否相同,并顯示錯(cuò)誤消息。
文檔。GetElementByIdx_x(“味精”)。InnerHTML =“兩個(gè)輸入密碼不一致,請(qǐng)重新輸入”;//在div中顯示錯(cuò)誤消息。
返回錯(cuò)誤;
密碼是一樣的,你可以繼續(xù)下一步。
form name = "form1" 。
代碼:
確認(rèn)密碼:——onchange事件觸發(fā)檢測(cè)——。
div id = "MSG" style = "color: red " / div 。
/形式
The / body 。
/ HTML 。
分類(lèi): 電腦/網(wǎng)絡(luò) 程序設(shè)計(jì) 其他編程語(yǔ)言
問(wèn)題描述:
就是有個(gè)對(duì)話框,輸入的時(shí)候顯示的是星號(hào)。謝謝
解析:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class C {
public static void main( String[] args ) {
JFrame f = new JFrame( );
f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
f.setSize( 300, 140 );
f.setLocation( 250, 250 );
Container c = f.getContentPane( );
c.setLayout( new FlowLayout( ) );
JPasswordField
c.add( new JLabel( "Enter your password into this JPasswordField: " ) );
JPasswordField jpf = new JPasswordField( 10 );
jpf.addActionListener(
new ActionListener( ) {
public void actionPerformed( ActionEvent e ) {
Object pwd =
new String( ( ( JPasswordField ) e.getSource( ) ).getPassword( ) );
JOptionPane.showMessageDialog( null, "Your password is " + pwd );
}
}
);
c.add( jpf );
TextField
c.add( new JLabel( "Or enter your password into this TextField: " ) );
TextField tf = new TextField( 12 );
tf.setEchoChar( '*' );
tf.addActionListener(
new ActionListener( ) {
public void actionPerformed( ActionEvent e ) {
Object pwd = ( ( ( TextField ) e.getSource( ) ).getText( ) );
JOptionPane.showMessageDialog( null, "Your password is " + pwd );
}
}
);
c.add( tf );
f.setVisible( true );
}
}