import java.util.Scanner;
創(chuàng)新互聯(lián)憑借專(zhuān)業(yè)的設(shè)計(jì)團(tuán)隊(duì)扎實(shí)的技術(shù)支持、優(yōu)質(zhì)高效的服務(wù)意識(shí)和豐厚的資源優(yōu)勢(shì),提供專(zhuān)業(yè)的網(wǎng)站策劃、成都網(wǎng)站建設(shè)、做網(wǎng)站、網(wǎng)站優(yōu)化、軟件開(kāi)發(fā)、網(wǎng)站改版等服務(wù),在成都10余年的網(wǎng)站建設(shè)設(shè)計(jì)經(jīng)驗(yàn),為成都上1000+中小型企業(yè)策劃設(shè)計(jì)了網(wǎng)站。
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);
}
}
}
import?java.awt.Dimension;
import?java.awt.Toolkit;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?javax.swing.JButton;
import?javax.swing.JFrame;
import?javax.swing.JLabel;
import?javax.swing.JOptionPane;
import?javax.swing.JPasswordField;
import?javax.swing.JTextField;
public?class?Test26?{
public?static?void?main(String[]?args)?{
final?String?userName?=?"abc";
final?String?passwrod?=?"123";
JFrame?jFrame?=?new?JFrame("登陸界面");
Dimension?dimension?=?Toolkit.getDefaultToolkit().getScreenSize();
jFrame.setBounds(((int)dimension.getWidth()?-?200)?/?2,?((int)dimension.getHeight()?-?300)?/?2,?200,?150);
jFrame.setResizable(false);
jFrame.setLayout(null);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel?label1?=?new?JLabel("姓名");
label1.setBounds(10,?10,?100,?30);
jFrame.add(label1);
JLabel?label2?=?new?JLabel("密碼");
label2.setBounds(10,?40,?100,?30);
jFrame.add(label2);
final?JTextField?text1?=?new?JTextField();
text1.setBounds(50,?15,?130,?20);
jFrame.add(text1);
final?JPasswordField?text2?=?new?JPasswordField();
text2.setBounds(50,?45,?130,?20);
jFrame.add(text2);
JButton?button?=?new?JButton("Login");
button.setBounds(10,?75,?170,?40);
button.addActionListener(new?ActionListener()?{
@Override
public?void?actionPerformed(ActionEvent?e)?{
if(userName.equals(text1.getText())??passwrod.equals(text2.getText()))?{
JOptionPane.showMessageDialog(null,?"登陸成功誤",?"提示",?JOptionPane.INFORMATION_MESSAGE);
}?else?{
JOptionPane.showMessageDialog(null,?"錯(cuò)誤",?"提示",?JOptionPane.ERROR_MESSAGE);
text1.setText("");
text2.setText("");
}
}
});
jFrame.add(button);
jFrame.setVisible(true);
}
}
我有一個(gè)微信公眾號(hào),經(jīng)常會(huì)分享一些Java技術(shù)相關(guān)的干貨,還有一些學(xué)習(xí)資源。
如果你喜歡我的分享,可以用微信搜索“Java團(tuán)長(zhǎng)”或者“javatuanzhang”關(guān)注。
可以自行參考下面的代碼,自行編寫(xiě):
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.println("用戶(hù)名:");
String username=input.next();
System.out.println("密碼:");
String password=input.next();
if(username='aaaaa'password='888888');
{
System.out.println("登錄成功!");
}
else
{
System.out.println("登錄失敗!");
}
}