我已经写好了服务器和客服端的代码~哪位大哥能帮忙写一个登陆界面的代码啊

有没有人在啊,想请分析下,我已经写好了服务器和客服端的代码~哪位大哥能帮忙写一个登陆界面的代码啊
最新回答
恋初雪

2024-10-18 08:00:35

<dd id="uc_member" > <div id="_userlogin"> <div class="userlogin"> <form name="userlogin" action="{dede:global.cfg_memberurl/}/index_do.php" method="POST"> <input type="hidden" name="fmdo" value="login" /> <input type="hidden" name="dopost" value="login" /> <input type="hidden" name="keeptime" value="604800" /> <div class="fb"><span>用户名:</span> <input type="text" name="userid" size="20" class="ipt-txt" /> </div> <div class="fb"><span>密码:</span> <input type="password" name="pwd" size="20" class="ipt-txt" /> </div> {dede:php} if(preg_match("/2/",$safe_gdopen)){ echo '<div class="fb"><span>验证码:</span> <input type="text" name="vdcode" size="8" class="ipt-txt" /> <img id="vdimgck" align="absmiddle" onClick="this.src=this.src+\'?\'" style="cursor:pointer;margin-left:0px;text-transform:uppercase;" alt="看不清?点击更换" src="'.$cfg_cmspath.'/include/vdimgck.php"/></div>'; } {/dede:php} <div class="submit"> <button type="submit" class="btn-1">登录</button> <a href="{dede:global.cfg_memberurl/}/index_do.php?fmdo=user&dopost=regnew" >注册帐号</a> <a href="{dede:global.cfg_memberurl/}/resetpassword.php">忘记密码?</a> </div> </form> </div> </div> <!-- /userlogin --> <script language="javascript" type="text/javascript">CheckLogin();</script> <div class="latestlogin"> <strong>最近登陆的会员</strong> <ul class="e7"> {dede:memberlist row=6 signlen=30} <li><a href="[field:spaceurl/]" target="_blank"><img src="[field:face/]" alt="[field:spacename/]" width="52" height="52" />[field:uname/]</a></li> {/dede:memberlist} </ul> </div> <!-- /latestlogin --> </dd>
你与北诗

2024-10-18 08:00:32

你参考一下吧 我写聊天室的时候写的 用的是Oracle连接 这只是界面
package lts;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class Login extends javax.swing.JFrame {
static String ip;
static String strname;
public Login() {
initComponents();
}
private void initComponents() {

JLabel jLabeluser = new javax.swing.JLabel();
JLabel jLabelpassword = new javax.swing.JLabel();
final JPasswordField jPasswordField = new javax.swing.JPasswordField();
JButton jButtonRegister = new javax.swing.JButton();
JButton jButtonLogin = new javax.swing.JButton();
JButton jButtonReset = new javax.swing.JButton();
JCheckBox jCheckBoxPassword = new javax.swing.JCheckBox();
JCheckBox jCheckBoxLogin = new javax.swing.JCheckBox();
JButton jButtonGetpassword = new javax.swing.JButton();
final JTextField jTextFieldUser = new javax.swing.JTextField();
JButton jButtonConnectSever = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("聊天室登录界面");

jLabeluser.setText("用户名:");

jLabelpassword.setText("密 码:");

jButtonRegister.setText("注册");

jButtonLogin.setText("登录");

jButtonReset.setText("重设");

jCheckBoxPassword.setText("记住密码");

jCheckBoxLogin.setText("自动登录");

jButtonGetpassword.setText("找回密码");

jButtonConnectSever.setText("连接服务器");

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabelpassword)
.addComponent(jLabeluser))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextFieldUser))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButtonGetpassword, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButtonRegister, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jButtonReset, javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jCheckBoxPassword)
.addGap(100, 100, 100)
.addComponent(jCheckBoxLogin)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 6, Short.MAX_VALUE)
.addComponent(jButtonLogin))))
.addGroup(layout.createSequentialGroup()
.addGap(92, 92, 92)
.addComponent(jButtonConnectSever, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(36, 36, 36)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabeluser)
.addComponent(jButtonRegister)
.addComponent(jTextFieldUser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabelpassword)
.addComponent(jPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButtonGetpassword))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jCheckBoxPassword)
.addComponent(jCheckBoxLogin))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 6, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButtonLogin)
.addComponent(jButtonReset))
.addGap(4, 4, 4)
.addComponent(jButtonConnectSever))
);
jButtonRegister.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0){
new RegisterFrame().setVisible(true);
}
});
jButtonLogin.addActionListener(new ActionListener(){
public boolean match(String Username,String Password){
if(Username.equals(jTextFieldUser.getText())&&Password.equals(jPasswordField.getText()))
return true;
else
return false;
}
public void actionPerformed(ActionEvent arg0) {
Connection con;
Statement sql;
ResultSet res;
boolean flag2=false;
try {

Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch(java.lang.ClassNotFoundException e) {
JOptionPane.showMessageDialog(null, e);
}

try{
if(jTextFieldUser.getText().trim().length()==0||jPasswordField.getText().trim().length()==0){
JOptionPane.showMessageDialog(null, "用户名或密码不允许为空");
}
else{
con = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:XE","system","1234");
sql=con.createStatement();
res=sql.executeQuery("select username,password1,ip from usertable");
while(res.next()){
Login.strname=res.getString("username");
String strpassword=res.getString("password1");
Login.ip=res.getString("ip");
boolean flag1=match(strname,strpassword);
if(flag1==true){
flag2=true;
new Client();
//new ChatProgram().setVisible(true);
break;
}
}
if(flag2==false){
JOptionPane.showMessageDialog(null, "用户名不存在或密码错误!");
}
}
}
catch (Exception e) {
JOptionPane.showMessageDialog(null, e+"不存在此用户!");
}
}
});
jButtonReset.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
jTextFieldUser.setText("");
jPasswordField.setText("");
}
});
jButtonGetpassword.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
new GETPassword().setVisible(true);
}
});
jButtonConnectSever.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
new Server().start();
}
});
setLocation(300,200);
pack();
}
public static void main(String args[]) {

try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {
new Login().setVisible(true);
}
});
}
}
//注册类没给你 太长了 粘了发不了
追问
能不能精简一下啊~我只想要注册和登陆就行了~像记住密码~找回密码这些完全可以不要的~一个注册一个登陆就OK了~最好还是SQL数据库的~我们现在只学了这数据库~最好带注释~谢谢了
追答
这下面是登录的实现 登录的时候连接数据库 在数据库里面找到相应的用户名和密码只要存在就可以登录了
其实注册也差不多 原理就是你先连接数据库 然后将相应的用户名和密码写入数据库中就OK了 上面的代码注册类没有给出来 既然你都写到那么多了 我相信你注册不会写不出来的 还有就是连接数据库都是大同小异的 (我这种连接方法要导入驱动包就行了)
jButtonLogin.addActionListener(new ActionListener(){
public boolean match(String Username,String Password){
if(Username.equals(jTextFieldUser.getText())&&Password.equals(jPasswordField.getText()))
return true;
else
return false;
}
public void actionPerformed(ActionEvent arg0) {
Connection con;
Statement sql;
ResultSet res;
boolean flag2=false;
try {

Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch(java.lang.ClassNotFoundException e) {
JOptionPane.showMessageDialog(null, e);
}

try{
if(jTextFieldUser.getText().trim().length()==0||jPasswordField.getText().trim().length()==0){
JOptionPane.showMessageDialog(null, "用户名或密码不允许为空");
}
else{
con = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:XE","system","1234");
sql=con.createStatement();
res=sql.executeQuery("select username,password1,ip from usertable");
while(res.next()){
Login.strname=res.getString("username");
String strpassword=res.getString("password1");
Login.ip=res.getString("ip");
boolean flag1=match(strname,strpassword);
if(flag1==true){
flag2=true;
new Client();
//new ChatProgram().setVisible(true);
break;
}
}
if(flag2==false){
JOptionPane.showMessageDialog(null, "用户名不存在或密码错误!");
}
}
}
catch (Exception e) {
JOptionPane.showMessageDialog(null, e+"不存在此用户!");
}
}
});