只是參考,需要自己需改!
望都ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)建站的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書合作)期待與您的合作!
package?com.ivory.view;
import?java.awt.*;
import?java.awt.event.*;
import?java.io.*;
import?javax.imageio.ImageIO;
import?javax.swing.*;
import?com.ivory.common.User;
import?com.ivory.sql.UserServer;
public?class?AddUser?extends?JDialog?implements?ActionListener
{
JLabel?jl1,jl2,jl3,jl4,jl5,jl6,jl7,jl8,jl9;
JTextField?jtf1,jtf2,jtf3,jtf4,jtf5,jtf6,jtf7,jtf8;
JButton?jb1,jb2;
Font?f1=new?Font("宋體",Font.PLAIN,16);
User?user;
public?AddUser(User?u)?
{?
Container?ct=new?Container();
jl1=new?JLabel("賬號");
jl1.setFont(f1);
jl1.setBounds(10,?60,?100,?30);
jl2=new?JLabel("密碼");
jl2.setFont(f1);
jl2.setBounds(10,?110,?100,?30);
jl3=new?JLabel("密碼");
jl3.setFont(f1);
jl3.setBounds(10,?160,?100,?30);
jl4=new?JLabel("姓名");
jl4.setFont(f1);
jl4.setBounds(10,?210,?100,?30);
jl5=new?JLabel("性別");
jl5.setFont(f1);
jl5.setBounds(10,?260,?100,?30);
jl6=new?JLabel("班級");
jl6.setFont(f1);
jl6.setBounds(10,?310,?100,?30);
jl7=new?JLabel("Tel");
jl7.setFont(f1);
jl7.setBounds(10,?370,?100,?30);
jl8=new?JLabel("成績");
jl8.setFont(f1);
jl8.setBounds(10,?410,?100,?30);
jl9=new?JLabel("注冊用戶");
jl9.setFont(f1);
jl9.setBounds(100,?10,?100,?30);
jb1=new?JButton(new?ImageIcon("image\\queding.jpg"));
jb1.setBounds(40,?460,?70,?30);
jb1.addActionListener(this);
jb1.setActionCommand("queding");
jb2=new?JButton(new?ImageIcon("image\\quxiao.jpg"));
jb2.setBounds(200,?460,?70,?30);
jb2.addActionListener(this);
jb2.setActionCommand("quxiao");
jtf1=new?JTextField(20);
jtf1.setBounds(50,?60,?200,?30);
jtf2=new?JTextField(20);
jtf2.setBounds(50,?110,?200,?30);
jtf3=new?JTextField(10);
jtf3.setBounds(50,?160,?200,?30);
jtf4=new?JTextField(20);
jtf4.setBounds(50,?210,?200,?30);
jtf5=new?JTextField(15);
jtf5.setBounds(50,?260,?200,?30);
jtf6=new?JTextField(20);
jtf6.setBounds(50,?310,?200,?30);
jtf7=new?JTextField(10);
jtf7.setBounds(50,?360,?200,?30);
jtf8=new?JTextField(20);
jtf8.setBounds(50,?410,?200,?30);
jtf8.setText("100");
jtf8.setEditable(false);
ct.add(jl9);ct.add(jl1);ct.add(jl2);
ct.add(jl3);ct.add(jl4);ct.add(jl5);
ct.add(jl6);ct.add(jl7);ct.add(jl8);
ct.add(jtf1);ct.add(jtf2);ct.add(jtf3);
ct.add(jtf4);ct.add(jtf5);ct.add(jtf6);
ct.add(jtf7);ct.add(jtf8);
ct.add(jb1);ct.add(jb2);
BackIamge?bi=new?BackIamge();
bi.setBounds(0,0,300,500);
ct.add(bi);
this.add(ct);
this.setSize(300,500);
this.setUndecorated(true);
this.setLocation(500,?100);
this.setVisible(true);
}
//定義一個內(nèi)部類(背景圖片)
class?BackIamge?extends?JPanel
{
Image?im;
public?BackIamge()
{
try?{
im=ImageIO.read(new?File("image//add.jpg"));
}?catch?(IOException?e)?{
//?TODO?Auto-generated?catch?block
e.printStackTrace();
}
}
//定義paint方法
public?void?paintComponent(Graphics?g)
{?
//畫出背景圖片
g.drawImage(im,?0,0,300,500,this);
}
}
@Override
public?void?actionPerformed(ActionEvent?e)?{
//?TODO?Auto-generated?method?stub
if(e.getActionCommand().equals("queding"))
{
User?u=new?User();
u.setUser(jtf1.getText());
u.setPassword(jtf2.getText());
u.setPassword(jtf3.getText());
u.setNumName(jtf4.getText());
u.setNumSex(jtf5.getText());
u.setNumClass(jtf6.getText());
u.setNumTel(jtf7.getText());
u.setNumMark(jtf8.getText());
u.setMessage("add");
if(!jtf2.getText().equals(jtf3.getText()))
{
JOptionPane.showMessageDialog(null,?"密碼不一致");
}
else
{
if(u.getMessage().equals("1"))
{
JOptionPane.showMessageDialog(null,?"注冊成功!");
this.dispose();
}else?
{
JOptionPane.showMessageDialog(null,?"注冊失敗!");
}
}
}
else?if(e.getActionCommand().equals("quxiao"))
{
this.dispose();
}
}
}
效果圖
參考代碼和注釋
import?java.awt.*;
import?java.awt.event.*;
import?java.io.*;
import?javax.swing.*;
//該窗口繼承自JFrame,?實(shí)現(xiàn)了ActionListener接口
public?class?SingUpFrame?extends?JFrame?implements?ActionListener?{
//定義需要的組件
JTextField?jtfName,?jtfEmail;?
JPasswordField?jpf;
JRadioButton?jrb1,?jrb2;
JComboBoxString?jcb;
JButton?jbReset,?jbSingUp;
//常量
static?final?String?NEW_LINE?=?System.getProperty("line.separator");//?獲取系統(tǒng)的換行符
static?final?String?FILE_PATH?=?"d:/users.txt";//指定文件的路徑
//構(gòu)造器
public?SingUpFrame()?{
JPanel?jp1?=?new?JPanel();
JLabel?jl1?=?new?JLabel("賬號");
jtfName?=?new?JTextField(15);
jp1.add(jl1);
jp1.add(jtfName);
JPanel?jp2?=?new?JPanel();
JLabel?jl2?=?new?JLabel("密碼");
jpf?=?new?JPasswordField(15);
jp2.add(jl2);
jp2.add(jpf);
JPanel?jp3?=?new?JPanel();
JLabel?jl3?=?new?JLabel("郵箱");
jtfEmail?=?new?JTextField(15);
jp3.add(jl3);
jp3.add(jtfEmail);
JPanel?jp4?=?new?JPanel();
JLabel?jl4?=?new?JLabel("性別");
ButtonGroup?bg?=?new?ButtonGroup();
jrb1?=?new?JRadioButton("男");
jrb1.setSelected(true);//?默認(rèn)選中男性
jrb2?=?new?JRadioButton("女");
bg.add(jrb1);
bg.add(jrb2);
jp4.add(jl4);
jp4.add(jrb1);
jp4.add(jrb2);
JLabel?jl5?=?new?JLabel("年齡");
String[]?ary?=?new?String[12];
for?(int?i?=?18;?i??30;?i++)?{//?18~30可供選中的范圍
ary[i?-?18]?=?i?+?"";
}
jcb?=?new?JComboBoxString(ary);
jp4.add(jl5);
jp4.add(jcb);
JPanel?jpc?=?new?JPanel(new?GridLayout(4,?1));//?4行1列布局
jpc.add(jp1);
jpc.add(jp2);
jpc.add(jp3);
jpc.add(jp4);
add(jpc);
JPanel?jps?=?new?JPanel();
jbReset?=?new?JButton("重填");
jbReset.addActionListener(this);//給按鈕添加響應(yīng)
jbSingUp?=?new?JButton("確定");
jbSingUp.addActionListener(this);//給按鈕添加響應(yīng)
jps.add(jbReset);
jps.add(jbSingUp);
add(jps,?BorderLayout.SOUTH);
setTitle("注冊窗口");//?窗口標(biāo)題
setSize(300,?285);//?窗口大小
setLocationRelativeTo(null);//?窗口居中
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//?當(dāng)窗口關(guān)閉時,程序結(jié)束
}
@Override
public?void?actionPerformed(ActionEvent?e)?{
JButton?jb?=?(JButton)?e.getSource();
if?(jb?==?jbReset)?{
jtfName.setText("");
jpf.setText("");
jtfEmail.setText("");
jrb1.setSelected(true);
jcb.setSelectedIndex(0);//?選中第1個選項(xiàng)(18)
}?else?if?(jb?==?jbSingUp)?{
String?name?=?jtfName.getText().trim();
String?pswd?=?new?String(jpf.getPassword());
String?email?=?jtfEmail.getText().trim();
String?xb?=?jrb1.isSelected()???"男"?:?"女";
String?age?=?(String)?jcb.getSelectedItem();
if(name.equals("")||pswd.equals("")||email.equals(""))?{//對輸入的信息進(jìn)行一個簡單的判斷
JOptionPane.showMessageDialog(null,?"請完整填寫所有的信息",?"提示",JOptionPane.WARNING_MESSAGE);??
return;
}
StringBuffer?sb?=?new?StringBuffer();
sb.append("賬號:"?+?name?+?NEW_LINE?+?"密碼:"?+?pswd?+?NEW_LINE?+?"郵箱:"?+?email?+?NEW_LINE?+?"性別:"?+?xb
+?NEW_LINE?+?"年齡:"?+?age+NEW_LINE);
boolean?flag?=?saveInfo(sb.toString());
if(flag)?{
JOptionPane.showMessageDialog(null,?"注冊成功?,保存成功");
}else?{
JOptionPane.showMessageDialog(null,?"Sorry!保存失敗.注冊出現(xiàn)了問題...",?"IO錯誤",JOptionPane.ERROR_MESSAGE);
}
}
}
//方法:保存信息到文件
public?boolean?saveInfo(String?info)?{
FileWriter?fw;
try?{
fw?=?new?FileWriter(FILE_PATH,?true);//追加文字到文件尾部
fw.write(info);
fw.close();
}?catch?(IOException?e)?{
e.printStackTrace();
return?false;//IO異常,保存不成功
}
return?true;//保存成功
}
//main方法
public?static?void?main(String[]?args)?{
new?SingUpFrame().setVisible(true);?//創(chuàng)建窗口并可見
}
}
界面建議用可視化來做,美觀且便捷。下面這個是完全用代碼寫的,僅供參考。
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.sql.*;
public class Register extends JFrame {
JLabel jl1 = new JLabel("用戶名");
JTextField jt1 = new JTextField();
JLabel jl2 = new JLabel("郵箱");
JTextField jt2 = new JTextField();
JLabel jl3 = new JLabel("密碼");
JPasswordField jpw1 = new JPasswordField();
JLabel jl4 = new JLabel("密碼確認(rèn)");
JPasswordField jpw2 = new JPasswordField();
JButton register = new JButton("注冊");
JButton clean = new JButton("清空");
public Register(){
setLayout(new GridLayout(5,2));
add(jl1);
add(jt1);
add(jl2);
add(jt2);
add(jl3);
add(jpw1);
add(jl4);
add(jpw2);
add(register);
add(clean);
String name = jt1.getText();
String email = jt2.getText();
String pw = jpw1.getText();
register.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/db","root","");
Statement sta = con.createStatement();
sta.executeUpdate("INSERT INTO register VALUES(name,email,pw)");
JOptionPane.showMessageDialog(null,"注冊成功","提示",JOptionPane.INFORMATION_MESSAGE);
}
catch(Exception ex){
ex.getStackTrace();
}
}
});
clean.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
jt1.setText("");
jt2.setText("");
jpw1.setText("");
jpw2.setText("");
}
});
}
public static void main(String[] args){
Register frame = new Register();
frame.setTitle("用戶注冊");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,400);
frame.setVisible(true);
}
}
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class TestLogin implements ActionListener {
JTextField jtf1 = new JTextField(15);
JPasswordField jtf2 = new JPasswordField(15);
JTextField jtf3 = new JTextField(15);
JLabel jl0 = new JLabel("歡迎注冊!");
String result = "";
@Override
public void actionPerformed(ActionEvent e) {
String comn = e.getActionCommand();
if ("提交".equals(comn)) {
FileInputStream fis;
try {
fis = new FileInputStream("D:\\Program File\\image\\input.txt");
byte[] b = new byte[1024];
while (true) {
int num = fis.read(b);
if (num == -1)
break;
result = result + new String(b, 0, num);
}
fis.close();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
String[] s = result.split(";", 0);
String name = jtf1.getText();
String password = jtf2.getText();
String email = jtf3.getText();
String temp = name + "," + password + "," + email + ";";
boolean flag = true;
for (int i = 0; i s.length; i++) {
String[] name0 = s[i].split(",", 0);
if (name.equals(name0[0])) {
jl0.setText("你輸入的用戶名重復(fù)啦!請重新輸入");
flag = false;
jtf1.setText("");
jtf2.setText("");
jtf3.setText("");
jtf1.requestFocus();
break;
}
}
if (flag) {
try {
FileOutputStream fos = new FileOutputStream(
"D:\\Program File\\image\\input.txt", true);
fos.write(temp.getBytes());
fos.close();
jl0.setText("恭喜你!注冊成功!");
jtf1.setText("");
jtf2.setText("");
jtf3.setText("");
jtf1.requestFocus();
} catch (Exception ae) {
ae.printStackTrace();
}
}
} else if ("清空".equals(comn)) {
jtf1.setText("");
jtf2.setText("");
jtf3.setText("");
jtf1.requestFocus();
}
}
public TestLogin() {
JFrame jf = new JFrame("登錄界面");
GridLayout gl = new GridLayout(5, 1);
jf.setLayout(gl);
JPanel[] jp = new JPanel[5];
for (int i = 0; i jp.length; i++) {
jp[i] = new JPanel();
jf.add(jp[i]);
}
jp[0].add(jl0);
JLabel jl1 = new JLabel("用戶名:");
jp[1].add(jl1);
jp[1].add(jtf1);
JLabel jl2 = new JLabel(" 密碼: ");
jp[2].add(jl2);
jp[2].add(jtf2);
JLabel jl3 = new JLabel(" Email:");
jp[3].add(jl3);
jp[3].add(jtf3);
JButton jb1 = new JButton("提交");
jp[4].add(jb1);
jb1.addActionListener(this);
JButton jb2 = new JButton("清空");
jp[4].add(jb2);
jb2.addActionListener(this);
jf.setLocation(300, 200);
jf.pack();
jf.setVisible(true);
jf.setDefaultCloseOperation(jf.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new TestLogin();
}
}
這個應(yīng)該就是你想要的答案!
網(wǎng)站標(biāo)題:java郵箱注冊界面代碼 java郵箱驗(yàn)證碼登陸
文章位置:http://jinyejixie.com/article40/doseiho.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、動態(tài)網(wǎng)站、網(wǎng)站內(nèi)鏈、網(wǎng)站改版、微信公眾號、網(wǎng)站排名
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)