新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
你要先学会截图哦,你发的看不清楚,重新写了一个你参考参考!
创新互联公司专注于龙江网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供龙江营销型网站建设,龙江网站制作、龙江网页设计、龙江网站官网定制、微信小程序开发服务,打造龙江网络公司原创品牌,更为您提供龙江网站排名全网营销落地服务。
import java.awt.GridLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
public class Day30A extends JFrame {
private static final long serialVersionUID = 1L;
private JLabel labelName,labelId,labelPass,labelMoney,labelSelect,labelCar;
private JComboBoxString jcb;
private JPanel jp1,jp2,jp3,jp4,jp5,jp6,jp7;
private ButtonGroup btg;
private JRadioButton jr1,jr2;
Day30A(){
this.setTitle("注册账户");
this.setLayout(new GridLayout(7,1));
this.setSize(300,280);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
init();
this.setVisible(true);
}
private void init() {
String str="卡片类型1,卡片类型2,卡片类型3,卡片类型4,卡片类型5";
jcb=new JComboBox(str.split(","));
labelId=new JLabel("账号: ");
labelName=new JLabel("姓名: ");
labelPass=new JLabel("密码: ");
labelMoney=new JLabel("开户金额:");
labelSelect=new JLabel("存款类型:");
labelCar=new JLabel("卡片类型:");
addFun1();
addFun2();
}
private void addFun2() {
this.add(jp1);
this.add(jp2);
this.add(jp3);
this.add(jp4);
this.add(jp5);
this.add(jp6);
this.add(jp7);
}
private void addFun1() {
jp1=new JPanel();
jp1.add(labelId);
jp1.add(new JTextField(15));
jp2=new JPanel();
jp2.add(labelName);
jp2.add(new JTextField(15));
jp3=new JPanel();
jp3.add(labelPass);
jp3.add(new JTextField(15));
jp4=new JPanel();
jp4.add(labelMoney);
jp4.add(new JTextField(13));
jp5=new JPanel();
jp5.add(labelSelect);
btg=new ButtonGroup();
jr1=new JRadioButton("定期");
jr2=new JRadioButton("活期",true);
btg.add(jr1);
btg.add(jr2);
jp5.add(jr1);
jp5.add(jr2);
jp6=new JPanel();
jp6.add(labelCar);
jp6.add(jcb);
jp7=new JPanel();
jp7.add(new JButton("确定"));
jp7.add(new JButton("取消"));
}
public static void main(String[] args) {
new Day30A();
}
}
分类: 电脑/网络 程序设计 其他编程语言
问题描述:
就是有个对话框,输入的时候显示的是星号。谢谢
解析:
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 );
}
}
import java.util.Scanner;
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("请输入用户名: ");
iname = san.next().charAt(0);
System.out.print("请输入密码: ");
ipass = san.nextInt();
if(Logon.username == iname Logon.password == ipass) {
System.out.println("欢迎你, " + Logon.username);
} else {
System.out.println("对不起, 你不是" + Logon.username);
}
}
}
简单代码如下,原本想用弹窗的,懒得写了:
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
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.JTextField;
public class dengru extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;
private Container c = null;
private JButton jb = null;
public dengru() {
this.setLayout(new FlowLayout());
jb = new JButton("登入");
jb.addActionListener(this);
this.add(jb);
this.setSize(500, 400);
this.setVisible(true);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
public static void main(String[] args) {
new dengru();
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == jb) {
JFrame jf=new JFrame();
c = jf.getContentPane();
c.setLayout(new GridLayout(3,2,2,2));
JLabel jl1 = new JLabel("用户名:");
JLabel jl2 = new JLabel("密 码:");
JTextField jtf1 = new JTextField();
JTextField jtf2 = new JTextField();
jtf1.setSize(200, 40);
jtf2.setSize(200, 40);
c.add(jl1);
c.add(jtf1);
c.add(jl2);
c.add(jtf2);
c.add(new JButton("登入"));
jf.setVisible(true);
jf.setSize(300, 100);
jf.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
}
}
下面是一个简单的登录示例:
代码复制展示:
public class ATMLogin {
public static void main(String[] args) {
// 设置用户名和密码
String username = "gqk";
String password = "520";
// 最多可以登录 3 次
for (int i = 0; i 3; i++) {
// 读取用户输入的用户名和密码
Scanner in = new Scanner(System.in);
System.out.print("请输入用户名:");
String inputUsername = in.nextLine();
System.out.print("请输入密码:");
String inputPassword = in.nextLine();
// 检查用户名和密码是否正确
if (inputUsername.equals(username) inputPassword.equals(password)) {
System.out.println("欢迎" + username + "登录!");
break; // 登录成功,退出循环
} else {
System.out.println("用户名或密码错误,请重新输入!");
}
}
// 如果 3 次登录都失败,则提示用户
System.out.println("卡片已经被锁,请联系客服人员!");
}
}
回答不易望请采纳
1.写一个操作数据库的通用DAO(假设为Dao.java),提供
·加载数据库驱动和获取数据库连接的方法:void getConnection();
·执行查询的方法:ResultSet executeQuery(String sql);
·执行更新的方法:Integer executeUpdate(String sql);
·关闭资源的方法:void releaseResource(Connection con);
2.在你的界面中把用户名和密码取出来
·username = yourTextField.getText();
·password = yourPasswordField.getText();
3.匹配
·验证username、password是否是有效输入值(例如:不能包含特殊字符,不能有注入嫌疑等)
·String sql = "select * from yourTable where username='"+username+"' and password='"+password+"'" ;
·Dao.executeQuery(sql):如果有结果说明合法,否则不合法。
不懂Connect 我