{
//输入提示信息
string LoginID = Console.ReadLine().Trim()
Console.WriteLine("请输入密码:")
string LoginPwd = Console.ReadLine().Trim()
//定义一个空字符串
string message = string.Empty
//判断用户名和密码不为空时
if (!CheckUser(LoginID, LoginPwd, ref message))
{
//显示message并返回
Console.WriteLine(message)
return
}
//用户名和密码不正确时
if (!dbh.Login(LoginID, LoginPwd, ref message))
{
//显示message并返回
Console.WriteLine(message)
return
}
//用户名和密码正确时显示登录成功信息
Console.WriteLine("登录成功!")
//调用菜单方法
ShowMainMenu()
}
/* Main.java*
* Created on __DATE__, __TIME__
*/
import javax.swing.JOptionPane
/**
*
* @author __USER__
*/
public class Main extends javax.swing.JFrame {
/** Creates new form Main */
public Main() {
initComponents()
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel() //标签
jLabel1 = new javax.swing.JLabel()
jLabel2 = new javax.swing.JLabel()
jLabel3 = new javax.swing.JLabel()
jButton1 = new javax.swing.JButton() //登录按钮
jButton2 = new javax.swing.JButton() //
jTextField1 = new javax.swing.JTextField() //文本框
jTextField2 = new javax.swing.JTextField()
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE) //关闭时的 *** 作,即退出程序
setTitle("登录界面") //设置标题:欢迎使用股票管理系统
setResizable(false) //设置窗口不可调节大小
jLabel1.setFont(new java.awt.Font("微软雅黑", 0, 18)) //设置标签的字体
jLabel1
.setText("您好,请输入信息")
jLabel2.setText("用户名")
jLabel3.setText("用户密码")
jButton1.setText("登录")
jButton1.addActionListener(new java.awt.event.ActionListener() { //采用匿名内部类来实现按钮监听功能
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt)
}
})
jButton2.setText("退出")
jButton2.addActionListener(new java.awt.event.ActionListener() { //同上
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt)
}
})
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout( //层次布局管理器,下面n长的代码,就是设置位置,自己看吧,呵呵,这个必须的,就不多写了
jPanel1)
jPanel1.setLayout(jPanel1Layout)
jPanel1Layout
.setHorizontalGroup(jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()
.addContainerGap(159, Short.MAX_VALUE)
.addComponent(jLabel1).addGap(140, 140,
140))
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addGap(110, 110, 110)
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel3))
.addGap(54, 54, 54)
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addComponent(
jTextField2,
javax.swing.GroupLayout.DEFAULT_SIZE,
191,
Short.MAX_VALUE)
.addGap(
112,
112,
112))
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addComponent(
jTextField1,
javax.swing.GroupLayout.PREFERRED_SIZE,
191,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())))
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addGap(141, 141, 141)
.addComponent(
jButton1,
javax.swing.GroupLayout.PREFERRED_SIZE,
68,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(89, 89, 89)
.addComponent(
jButton2,
javax.swing.GroupLayout.PREFERRED_SIZE,
72,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(145, Short.MAX_VALUE)))
jPanel1Layout
.setVerticalGroup(jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(55, 55, 55)
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(
jTextField1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(41, 41, 41)
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(
jTextField2,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(43, 43, 43)
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
jButton1,
javax.swing.GroupLayout.PREFERRED_SIZE,
33,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
jButton2,
javax.swing.GroupLayout.PREFERRED_SIZE,
33,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(48, Short.MAX_VALUE)))
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane())
getContentPane().setLayout(layout)
layout.setHorizontalGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addGroup(
layout.createSequentialGroup().addContainerGap().addComponent(
jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap()))
layout.setVerticalGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addGroup(
layout.createSequentialGroup().addContainerGap().addComponent(
jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)))
pack()
setLocationRelativeTo(null) //居中
}// </editor-fold>
//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { //事件处理,不建议这样做
// TODO add your handling code here:
String name = this.jTextField1.getText().trim() //获得用户名,去空格
String password = this.jTextField2.getText().trim() //获得密码,去空格
if (name.equals("admin") &&password.equals("123456")) { //如果符合条件.....其实这里应该去和数据库关联,这是死代码
// Showinformation sf=new Showinformation() //我估计是另外一个框架,就是登录成功之后的框架
// sf.setVisible(true)
// sf.show() //这个方法就直接秒杀,不用了,因为sf.setVisible(true)已经被调用了,这里就多次一举了
} else { //用户名或者密码验证失败
JOptionPane.showMessageDialog(this, "用户名或者密码错误啦~", "提示", //提示框
JOptionPane.INFORMATION_MESSAGE)
this.jTextField1.setText("") //清空输入框
this.jTextField2.setText("")
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { //事件处理,其实可以将jButton1ActionPerformed放在一起处理,只要获得按钮的标签内容 (JButton)(evt.getSuorse()).getText()就做对比就ko了
// TODO add your handling code here:
System.exit(0)
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() { //好方法,呵呵使用该方式的原因是:awt是单线程模式的,所有awt的组件只能在(推荐方式)事件处理线程中访问,从而保证组件状态的可确定性。java核心编程技术中每个实例基本都用到了
public void run() {
new Main().setVisible(true)
}
})
}
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JButton jButton1
private javax.swing.JButton jButton2
private javax.swing.JLabel jLabel1
private javax.swing.JLabel jLabel2
private javax.swing.JLabel jLabel3
private javax.swing.JPanel jPanel1
private javax.swing.JTextField jTextField1
private javax.swing.JTextField jTextField2}
// End of variables declaration//GEN-END:variables
你修改一下吧,从记事本获得用户名判断一下就行了
登陆页面:<form name="form1" method="post" action="LogCheck.asp">
<table width="71%" border="1" cellspacing="0" cellpadding="5" align="center" bordercolordark="#CCCCCC" bordercolorlight="#000000">
<tr bgcolor="#CCCCCC">
<td height="22" align="center" valign="middle" bgcolor="#CCCCCC" colspan="2"> 登陆</td>
</tr>
<tr valign="middle" bgcolor="#eeeeee">
<td bgcolor="#eeeeee" height="92" width="95%" align="center" style="BORDER-Right-WIDTH: 0px"><%=str%>
<li>用户名:<input type="text" name="username" class="tx" style="width:70px" onMouseOver="this.select()"/></li>
<br/><br/>
<li>密 码:<input type="password" name="psw" class="tx" style="width:70px"/></li>
</td><td style="BORDER-Left-WIDTH: 0px"> </td>
</tr>
<tr align="center" valign="middle" bgcolor="#eeeeee">
<td bgcolor="#eeeeee" height="24" colspan="2">
<input type="submit" name="Submit1" value="· 提交 ·" class="bt"/>
<input type="reset" name="Reset1" value="· 重置 ·" class="bt"/>
</td>
</tr>
</table>
</form>
LogCheck.asp判断页面
<%'此处是验证登录身份
dim comeFrom,loginfo
dim username,psw
comeFrom = Request.ServerVariables("HTTP_REFERER")
loginfo = session("log")
if loginfo <>"ok" then
username = Request.Form("username")
psw = Request.Form("psw")
if (username="machao" and psw="letmein") or (username="我行我素" and psw="")then
session("log") = "ok"
session.Timeout = 5
elseif username<>"" then
session("log") = "err"
else
session("log") = ""
end if
elseif Request.QueryString("action")="LogOut" then
session("log") = ""
end if
'判断完毕后进行跳转
'response.Redirect(comeFrom)
response.Redirect("section.htm")
%>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)