你要先學(xué)會(huì)截圖哦,你發(fā)的看不清楚,重新寫了一個(gè)你參考參考!
左貢ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)公司的ssl證書銷售渠道,可以享受市場價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:028-86922220(備注:SSL證書合作)期待與您的合作!
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("注冊(cè)賬戶");
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("賬號(hào): ");
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();
}
}
用java做QQ登錄界面的寫法如下:
package ch10;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
1、//定義該類繼承自JFrame,實(shí)現(xiàn)ActionListener接口
public class LoginTest extends JFrame implements ActionListener
{
2、//創(chuàng)建JPanel對(duì)象
private JPanel jp=new JPanel();
3、//創(chuàng)建3個(gè)標(biāo)并加入數(shù)組
JLabel name = new JLabel("請(qǐng)輸入用戶名");
JLabel password = new JLabel("請(qǐng)輸入密碼");
JLabel show = new JLabel("");
private JLabel[] jl={name,password,show};
4、//創(chuàng)建登陸和重置按扭并加入數(shù)組
JButton login = new JButton("登陸");
JButton reset = new JButton("重置");
private JButton[] jb={login,reset};
5、//創(chuàng)建文本框以及密碼框
private JTextField jName=new JTextField();
private JPasswordField jPassword =new JPasswordField();
public LoginTest()
{
6、//設(shè)置布局管理器為空布局,這里自己擺放按鈕、標(biāo)簽和文本框
jp.setLayout(null);
for(int i=0;i2;i++)
{
7、//設(shè)置標(biāo)簽和按扭的位置與大小
jl[i].setBounds(30,20+40*i,180,20);
jb[i].setBounds(30+110*i,100,80,20);
8、//添加標(biāo)簽和按扭到JPanel容器中
jp.add(jl[i]);
jp.add(jb[i]);
//為2個(gè)按鈕注冊(cè)動(dòng)作事件監(jiān)聽器
jb[i].addActionListener(this);
}
9、//設(shè)置文本框的位置和大小,注意滿足美觀并足夠用戶名的長度
jName.setBounds(130,15,100,20);
10、//添加文本框到JPanel容器中
jp.add(jName);
11、//為文本框注冊(cè)動(dòng)作事件監(jiān)聽器
jName.addActionListener(this);
12、//設(shè)置密碼框的位置和大小,注意滿足美觀和足夠密碼的長度
jPassword.setBounds(130,60,100,20);
13、//添加密碼框到JPanel容器中
jp.add(jPassword);
14、//設(shè)置密碼框中的回顯字符,這里設(shè)置美元符號(hào)
jPassword.setEchoChar('$');
15、//為密碼框注冊(cè)動(dòng)作事件監(jiān)聽器
jPassword.addActionListener(this);
16、//設(shè)置用于顯示登陸狀態(tài)的標(biāo)簽大小位置,并將其添加進(jìn)JPanel容器
jl[2].setBounds(10,180,270,20);
jp.add(jl[2]);
17、//添加JPanel容器到窗體中
this.add(jp);
18、//設(shè)置窗體的標(biāo)題、位置、大小、可見性及關(guān)閉動(dòng)作
this.setTitle("登陸窗口");
this.setBounds(200,200,270,250);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
19、//實(shí)現(xiàn)動(dòng)作監(jiān)聽器接口中的方法actionPerformed
public void actionPerformed(ActionEvent e)
{
20、//如果事件源為文本框
if(e.getSource()==jName)
{
21、//切換輸入焦點(diǎn)到密碼框
jPassword.requestFocus();
}
22、//如果事件源為重置按扭
else if(e.getSource()==jb[1])
{
23、//清空姓名文本框、密碼框和show標(biāo)簽中的所有信息
jl[2].setText("");
jName.setText("");
jPassword.setText("");
24、//讓輸入焦點(diǎn)回到文本框
jName.requestFocus();
}
25、//如果事件源為登陸按鈕,則判斷登錄名和密碼是否正確
else
{
26、//判斷用戶名和密碼是否匹配
if(jName.getText().equals("lixiangguo")
String.valueOf(jPassword.getPassword()).equals("19801001"))
{
27、jl[2].setText("登陸成功,歡迎您的到來!");
}
else
{
28、jl[2].setText("對(duì)不起,您的用戶名或密碼錯(cuò)誤!");
}
}
}
public static void main(String[] args)
{
29、//創(chuàng)建LoginTest窗體對(duì)象
new LoginTest();
}
}
Java用戶登陸這塊,主要還是類:
1,邊界布局:BorderLayout。他主要分為五個(gè)布局,是JFrame(頂層容器),JDialog(創(chuàng)建對(duì)話框窗口的類)的默認(rèn)布局方式。其最多容量為5個(gè)組件,超出5個(gè)得用其他的。設(shè)置方式為:BorderLayout.NORTH;BorderLayout.SOUTH;BorderLayout.CENTER;Borderlayout.CENTER;BorderLayout.LEFT;BorderLayout.RIGHT。
2,流式布局:FlowLayout。布局方式為從左到右,從上到下。是JPanel(輕量級(jí)容器)的默認(rèn)面板布局。
3,網(wǎng)格布局:GridLayout。布局方式為行和列組成的網(wǎng)絡(luò)。布局方法:setLayout(new
GridLayout(3,2,3,3));其中強(qiáng)兩位數(shù)字表示三行兩列,后兩位表示行與行的間距為3,列與列的間距為3.
接著,就接觸到JPanel面板。JPanel是非頂層容器,所以,一個(gè)界面只能由一個(gè)JFrame,但是可以有多個(gè)JPanel組件。其默認(rèn)布局方式為流式布局。在JPanel這塊,學(xué)到了用戶登錄界面的設(shè)計(jì)。從而接觸到另外三個(gè)組件:文本框組件:JTextField;密碼框組件:JPasswordField;標(biāo)簽組件:JLabel;復(fù)選框組件:JCheckBox;單選框組件:JRadioButton;按鈕組件JButton。
import javax.swing.JFrame;//框架
import javax.swing.JPanel;//面板
import javax.swing.JButton;//按鈕
import javax.swing.JLabel;//標(biāo)簽
import javax.swing.JTextField;//文本框
import java.awt.Font;//字體
import java.awt.Color;//顏色
import javax.swing.JPasswordField;//密碼框
import java.awt.event.ActionListener;//事件監(jiān)聽
import java.awt.event.ActionEvent;//事件處理
import javax.swing.JOptionPane;//消息窗口public class UserLogIn extends JFrame{
public JPanel pnluser;
public JLabel lbluserLogIn;
public JLabel lbluserName;
public JLabel lbluserPWD;
public JTextField txtName;
public JPasswordField pwdPwd;
public JButton btnSub;
public JButton btnReset;
public UserLogIn(){
pnluser = new JPanel();
lbluserLogIn = new JLabel();
lbluserName = new JLabel();
lbluserPWD = new JLabel();
txtName = new JTextField();
pwdPwd = new JPasswordField();
btnSub = new JButton();
btnReset = new JButton();
userInit();
}
public void userInit(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//設(shè)置關(guān)閉框架的同時(shí)結(jié)束程序
this.setSize(300,200);//設(shè)置框架大小為長300,寬200
this.setResizable(false);//設(shè)置框架不可以改變大小
this.setTitle("用戶登錄");//設(shè)置框架標(biāo)題
this.pnluser.setLayout(null);//設(shè)置面板布局管理
this.pnluser.setBackground(Color.cyan);//設(shè)置面板背景顏色
this.lbluserLogIn.setText("用戶登錄");//設(shè)置標(biāo)簽標(biāo)題
this.lbluserLogIn.setFont(new Font("宋體",Font.BOLD | Font.ITALIC,14));//設(shè)置標(biāo)簽字體
this.lbluserLogIn.setForeground(Color.RED);//設(shè)置標(biāo)簽字體顏色
this.lbluserName.setText("用戶名:");
this.lbluserPWD.setText("密 碼:");
this.btnSub.setText("登錄");
this.btnReset.setText("重置");
this.lbluserLogIn.setBounds(120,15,60,20);//設(shè)置標(biāo)簽x坐標(biāo)120,y坐標(biāo)15,長60,寬20
this.lbluserName.setBounds(50,55,60,20);
this.lbluserPWD.setBounds(50,85,60,25);
this.txtName.setBounds(110,55,120,20);
this.pwdPwd.setBounds(110,85,120,20);
this.btnSub.setBounds(85,120,60,20);
this.btnSub.addActionListener(new ActionListener()//匿名類實(shí)現(xiàn)ActionListener接口
{
public void actionPerformed(ActionEvent e){
btnsub_ActionEvent(e);
}
}
);
this.btnReset.setBounds(155,120,60,20);
this.btnReset.addActionListener(new ActionListener()//匿名類實(shí)現(xiàn)ActionListener接口
{
public void actionPerformed(ActionEvent e){
btnreset_ActionEvent(e);
}
}
);
this.pnluser.add(lbluserLogIn);//加載標(biāo)簽到面板
this.pnluser.add(lbluserName);
this.pnluser.add(lbluserPWD);
this.pnluser.add(txtName);
this.pnluser.add(pwdPwd);
this.pnluser.add(btnSub);
this.pnluser.add(btnReset);
this.add(pnluser);//加載面板到框架
this.setVisible(true);//設(shè)置框架可顯
}
public void btnsub_ActionEvent(ActionEvent e){
String name = txtName.getText();
String pwd = String.valueOf(pwdPwd.getPassword());
if(name.equals("")){
JOptionPane.showMessageDialog(null,"賬號(hào)不能為空","錯(cuò)誤",JOptionPane.ERROR_MESSAGE);
return;
}else if (pwd.equals("")){
JOptionPane.showMessageDialog(null,"密碼不能為空","錯(cuò)誤",JOptionPane.ERROR_MESSAGE);
return;
}else if(true){
this.dispose();
}else{
JOptionPane.showMessageDialog(null,"賬號(hào)或密碼錯(cuò)誤","錯(cuò)誤",JOptionPane.ERROR_MESSAGE);
return;
}
}
public void btnreset_ActionEvent(ActionEvent e){
txtName.setText("");
pwdPwd.setText("");
}
public static void main(String[] args){
new UserLogIn();
}
}
import java.awt.*; \x0d\x0aimport javax.swing.*; \x0d\x0aimport java.awt.event.*; \x0d\x0aimport java.sql.*; \x0d\x0a\x0d\x0aclass LoginFrm extends JFrame implements ActionListener \x0d\x0a{ \x0d\x0aJLabel lbl1=new JLabel("用戶名"); \x0d\x0aJLabel lbl2=new JLabel("密碼"); \x0d\x0aJTextField txt=new JTextField(15); \x0d\x0aJPasswordField pf=new JPasswordField(); \x0d\x0aJButton btn1=new JButton("確定"); \x0d\x0aJButton btn2=new JButton("取消"); \x0d\x0a\x0d\x0apublic LoginFrm() \x0d\x0a{ \x0d\x0athis.setTitle("登陸"); \x0d\x0aJPanel jp=(JPanel)this.getContentPane(); \x0d\x0ajp.setLayout(new GridLayout(3,2,10,10)); \x0d\x0ajp.add(lbl1);jp.add(txt); \x0d\x0ajp.add(lbl2);jp.add(pf); \x0d\x0ajp.add(btn1);jp.add(btn2); \x0d\x0abtn1.addActionListener(this); \x0d\x0abtn2.addActionListener(this); \x0d\x0a} \x0d\x0a\x0d\x0apublic void actionPerformed(ActionEvent ae) \x0d\x0a{ \x0d\x0aif(ae.getSource()==btn1) \x0d\x0a{ \x0d\x0atry \x0d\x0a{ \x0d\x0aClass.forName("sun.jdbc.odbc.JdbcOdbcDriver"); \x0d\x0aConnection con=DriverManager.getConnection("jdbc:odbc:MyDB","",""); \x0d\x0aStatement cmd=con.createStatement(); \x0d\x0aResultSet rs=cmd.executeQuery("select * from loginAndpassword where login='"+txt.getText()+"' and password='"+pf.getText()+"'"); \x0d\x0aif(rs.next()) \x0d\x0a{ \x0d\x0aJOptionPane.showMessageDialog(null,"登陸成功!"); \x0d\x0a} \x0d\x0aelse \x0d\x0aJOptionPane.showMessageDialog(null,"用戶名或密碼錯(cuò)誤!"); \x0d\x0a} catch(Exception ex){} \x0d\x0a\x0d\x0aif(ae.getSource()==btn2) \x0d\x0a{ \x0d\x0atxt.setText(""); \x0d\x0apf.setText(""); \x0d\x0a} \x0d\x0a} \x0d\x0a} \x0d\x0a\x0d\x0apublic static void main(String arg[]) \x0d\x0a{ \x0d\x0aJFrame.setDefaultLookAndFeelDecorated(true); \x0d\x0aLoginFrm frm=new LoginFrm(); \x0d\x0afrm.setSize(400,200); \x0d\x0afrm.setVisible(true); \x0d\x0a} \x0d\x0a}