1、java設計登錄界面
掃描文件我理解為持久化到磁碟。
題主應該學下軟工裡面如何描述需求
2、java設計用戶登錄界面,無須設置事件處理過程(僅做界面設計)?
那你使用java本身Swing的那個包,設計相應的界面,然後自己把那個界面布置好之後就可以了。
3、求用JAVA設計的簡單的登陸界面代碼
<%@ page language="java" pageEncoding="UTF-8"%>
<HTML>
<HEAD>
<TITLE>車友信息管理系統</TITLE>
<LINK href="images/public.css" type=text/css rel=stylesheet>
<LINK href="images/login.css" type=text/css rel=stylesheet>
<STYLE type=text/css>
</STYLE>
<script type="text/javascript">
function changeValidateCode(obj) {
//獲取當前的時間作為參數,無具體意義
var timenow = new Date().getTime();
//每次請求需要一個不同的參數,否則可能會返回同樣的驗證碼
//這和瀏覽器的緩存機制有關系,也可以把頁面設置為不緩存,這樣就不用這個參數了。
obj.src="rand.action?d="+timenow;
}
</script>
</HEAD>
<BODY onload="fon()">
<form id=login name="fr" method="post" action="loginpurview"
onsubmit="return func()">
<DIV id=div1>
<TABLE id=login height="100%" cellSpacing=0 cellPadding=0 width=800
align=center>
<TBODY>
<TR id=main>
<TD>
<TABLE height="100%" cellSpacing=0 cellPadding=0 width="100%">
<TBODY>
<TR>
<TD colSpan=4>
</TD>
</TR>
<TR height=30>
<TD width=380>
</TD>
<TD>
</TD>
<TD>
</TD>
<TD>
</TD>
</TR>
<TR height=40>
<TD rowSpan=4>
</TD>
<TD>
用戶名:
</TD>
<TD>
<INPUT class=textbox id="txtUserName" type="text" name="username">
</TD>
<TD width=120>
</TD>
</TR>
<TR height=40>
<TD>
密 碼:
</TD>
<TD>
<INPUT class=textbox id=txtUserPassword type="password"
name="password">
</TD>
<TD width=120>
</TD>
</TR>
<TR height=40>
<TD>
驗證碼:
</TD>
<td colspan="4" class="top_hui_text">
<input type="text" name="str" id="user2" style="width:100px; height:17px; background-color:#87adbf; border:solid 1px #153966; font-size:12px; color:#283439; " >
<img src="rand.action" onclick="changeValidateCode(this)" title="點擊圖片刷新驗證碼" /></td>
</TD>
</TR>
<TR height=40>
<TD align=left>
<div align="left"><INPUT id=btnLogin type=submit value=" 登 錄 " name=btnLogin/></div>
</TD>
<TD align=center>
<div align="center"><INPUT id=btnLogin1 type=reset value=" 重置 " name=btnLogin1 onclick="return reset1()"/></div>
</TD>
<TD align=right>
<div align="right"><a href="register.jsp">注冊</a></div>
</TD>
<TD width=120>
</TD>
</TR>
<TR height=110>
<TD colSpan=4>
</TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
<TR id=root height=104>
<TD>
</TD>
</TR>
</TBODY>
</TABLE>
</DIV>
<DIV id=div2 style="DISPLAY: none"></DIV>
</CONTENTTEMPLATE>
</form>
</BODY>
</HTML>
<script>
function func(){
var username = fr.username.value;
var password = fr.password.value;
if(username==""){
alert("用戶名不能為空");
return false;
}else if(password==""){
alert("密碼不能為空");
return false;
}else if(username.indexOf("'")!=-1)
{
alert("您的用戶名中含有非法字元,請重新輸入");
return false;
}
else if(password.indexOf("'")!=-1)
{
alert("您的密碼中含有非法字元,請重新 輸入");
return false;
}else
{
return form_submit();
}
}
function reset1()
{
fr.reset();1
return false;
}
</script>
一個完整的jsp頁面,直接復制就行
4、用Java設計一個登錄頁面,不用連接資料庫,只要把用戶和密碼信息存放在文本裡面,怎樣設計代碼???
/* 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
你修改一下吧,從記事本獲得用戶名判斷一下就行了
5、急求!!用java設計登陸頁面
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Dimension;
import javax.swing.JButton;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JLabel;
public class Login implements ActionListener{
private JFrame jFrame = null; // @jve:decl-index=0:visual-constraint="168,33"
private JPanel jContentPane = null;
private JButton login = null;
private JButton exit = null;
private JTextField userName = null;
private JPasswordField password = null;
private JLabel uname = null;
private JLabel passwordLable = null;
/**
* This method initializes jFrame
*
* @return javax.swing.JFrame
*/
private JFrame getJFrame() {
(jFrame == null) {
jFrame = new JFrame();
jFrame.setSize(new Dimension(447, 235));
jFrame.setContentPane(getJContentPane());
}
return jFrame;
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
passwordLable = new JLabel();
passwordLable.setBounds(new Rectangle(115, 79, 56, 33));
passwordLable.setText("密 碼:");
uname = new JLabel();
uname.setBounds(new Rectangle(113, 28, 58, 31));
uname.setText("用戶名:");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getLogin(), null);
jContentPane.add(getExit(), null);
jContentPane.add(getUserName(), null);
jContentPane.add(getPassword(), null);
jContentPane.add(uname, null);
jContentPane.add(passwordLable, null);
}
return jContentPane;
}
/**
* This method initializes login
*
* @return javax.swing.JButton
*/
private JButton getLogin() {
if (login == null) {
login = new JButton();
login.setBounds(new Rectangle(130, 131, 70, 32));
login.setText("登錄");
login.addActionListener(this);
}
return login;
}
/**
* This method initializes exit
*
* @return javax.swing.JButton
*/
private JButton getExit() {
if (exit == null) {
exit = new JButton();
exit.setBounds(new Rectangle(216, 131, 73, 32));
exit.setText("退出");
exit.addActionListener(this);
}
return exit;
}
/**
* This method initializes userName
*
* @return javax.swing.JTextField
*/
private JTextField getUserName() {
if (userName == null) {
userName = new JTextField();
userName.setBounds(new Rectangle(189, 28, 133, 31));
}
return userName;
}
/**
* This method initializes password
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getPassword() {
if (password == null) {
password = new JPasswordField();
password.setBounds(new Rectangle(189, 79, 133, 33));
}
return password;
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == login) {
String userNameString = userName.getText();
String userPassword = new String(password.getPassword());
if (userNameString != null && userNameString.equals("123") && userPassword != null && userPassword.equals("123")) {
System.out.println("登錄成功");
JOptionPane.showMessageDialog(jFrame, "登錄成功");
}else {
System.out.println("登錄失敗");
JOptionPane.showMessageDialog(jFrame, "登錄失敗");
}
}
if (e.getSource() == exit) {
System.exit(0);
}
}
public static void main(String[] args) {
Login login = new Login();
JFrame jFrame = login.getJFrame();
jFrame.setVisible(true);
jFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
}
主要實現的方法是在actionPerformed這個方法中,給登錄按鈕和退出按鈕添加事件:login.addActionListener(this);exit.addActionListener(this);
6、java用戶登錄界面的設計?
import javax.swing.*;
import java.awt.*;
public class Frame extends JFrame {
public static void main(String[] args) {
new Frame();
}
public Frame() throws HeadlessException {
Container contentPanel = this.getContentPane();
JPanel headerPanel = new JPanel();
headerPanel.setLayout(new FlowLayout());
headerPanel.add(new JLabel("歡迎進入學生成績管理系統"));
JPanel centerPanel = new JPanel();
centerPanel.setLayout(new GridLayout(2, 2));
centerPanel.add(new JLabel("用戶名", JLabel.CENTER));
centerPanel.add(new JTextField());
centerPanel.add(new JLabel("密碼", JLabel.CENTER));
centerPanel.add(new JTextField());
JPanel footerPanel = new JPanel();
footerPanel.setLayout(new FlowLayout());
footerPanel.add(new JButton("登錄"));
footerPanel.add(new JButton("取消"));
contentPanel.add(headerPanel, BorderLayout.NORTH);
contentPanel.add(centerPanel, BorderLayout.CENTER);
contentPanel.add(footerPanel, BorderLayout.SOUTH);
this.setTitle("Login");
this.setBounds(0, 0, 300, 200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
}
7、急求!!要求用java設計登陸頁面
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Dimension;
import javax.swing.JButton;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JLabel;
public class Login implements ActionListener{
JFrame jFrame = null; // @jve:decl-index=0:visual-constraint="168,33"
private JPanel jContentPane = null;
private JButton login = null;
private JButton exit = null;
private JTextField userName = null;
private JPasswordField password = null;
private JLabel uname = null;
private JLabel passwordLable = null;
/**
* This method initializes jFrame
*
* @return javax.swing.JFrame
*/
private JFrame getJFrame() {
if (jFrame == null) {
jFrame = new JFrame();
jFrame.setSize(new Dimension(447, 235));
jFrame.setContentPane(getJContentPane());
}
return jFrame;
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
passwordLable = new JLabel();
passwordLable.setBounds(new Rectangle(115, 79, 56, 33));
passwordLable.setText("密 碼:");
uname = new JLabel();
uname.setBounds(new Rectangle(113, 28, 58, 31));
uname.setText("用戶名:");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getLogin(), null);
jContentPane.add(getExit(), null);
jContentPane.add(getUserName(), null);
jContentPane.add(getPassword(), null);
jContentPane.add(uname, null);
jContentPane.add(passwordLable, null);
}
return jContentPane;
}
/**
* This method initializes login
*
* @return javax.swing.JButton
*/
private JButton getLogin() {
if (login == null) {
login = new JButton();
login.setBounds(new Rectangle(130, 131, 70, 32));
login.setText("登錄");
login.addActionListener(this);
}
return login;
}
/**
* This method initializes exit
*
* @return javax.swing.JButton
*/
private JButton getExit() {
if (exit == null) {
exit = new JButton();
exit.setBounds(new Rectangle(216, 131, 73, 32));
exit.setText("退出");
exit.addActionListener(this);
}
return exit;
}
/**
* This method initializes userName
*
* @return javax.swing.JTextField
*/
private JTextField getUserName() {
if (userName == null) {
userName = new JTextField();
userName.setBounds(new Rectangle(189, 28, 133, 31));
}
return userName;
}
/**
* This method initializes password
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getPassword() {
if (password == null) {
password = new JPasswordField();
password.setBounds(new Rectangle(189, 79, 133, 33));
}
return password;
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == login) {
String userNameString = userName.getText();
String userPassword = new String(password.getPassword());
if (userNameString != null && userNameString.equals("123") && userPassword != null && userPassword.equals("123")) {
System.out.println("登錄成功");
JOptionPane.showMessageDialog(jFrame, "登錄成功");
}else {
System.out.println("登錄失敗");
JOptionPane.showMessageDialog(jFrame, "登錄失敗");
}
}
if (e.getSource() == exit) {
System.exit(0);
}
}
public static void main(String[] args) {
Login login = new Login();
JFrame jFrame = login.getJFrame();
jFrame.setVisible(true);
jFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
}
主要實現的方法是在actionPerformed這個方法中,給登錄按鈕和退出按鈕添加事件:login.addActionListener(this);exit.addActionListener(this);
8、求用JAVA編寫的登陸界面!
這是我剛做的,JAVA布局與其它語言相比難度較大,建議你將兩張圖片PS成一張圖片,做為背景,加入到JFRAME中,以降低難度。
要是這個你喜歡,不要忘記多給我加分啊!!!
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class LoginIn extends JFrame{
JTextField f1;
JTextField f2;
JButton b1;
JButton b2;
String power;//表示許可權
String imgePath = "e:/workspace/GUI/14.gif";
JPanel p5;
Image img = Toolkit.getDefaultToolkit().createImage(imgePath);
LoginIn(){
Container cp=getContentPane();
Label l1=new Label("用戶:");
Label l2=new Label("密碼:");
JPanel p1=new JPanel();
JPanel p2=new JPanel();
JPanel p3=new JPanel();
JPanel p4=new JPanel();
p5=new JPanel(){
protected void paintChildren(Graphics g) {
g.drawImage(img,0,0,this);
super.paintChildren(g);
}
};
f1=new JTextField(15);
f2=new JPasswordField(15);
b1=new JButton("登錄");
b2=new JButton("重置");
p1.setBackground(Color.orange);
p2.add(l1);
p2.add(f1);
p2.setBorder(new MatteBorder(0,0,0,0,Color.BLACK));
p2.setBackground(Color.ORANGE);
p3.add(l2);
p3.add(f2);
p3.setBackground(Color.ORANGE);
p3.setBorder(new MatteBorder(0,0,0,0,Color.BLACK));
p4.add(b1);
p4.add(b2);
p4.setBorder(new MatteBorder(-3,-3,-3,-3,Color.CYAN));
p4.setBackground(Color.ORANGE);
p5.setLayout(new FlowLayout(FlowLayout.CENTER,20,20));
p5.add(p2);
p5.add(p3);
p5.add(p4);
cp.add(p5,BorderLayout.CENTER);
b1.addActionListener(new Enter());
b2.addActionListener(new ReWrite());
addWindowListener(new winClose());
}
public static void main(String[] args) {
LoginIn log=new LoginIn();
log.setTitle("系統登錄");
log.setSize(360,250);
log.setVisible(true);
}
class Enter implements ActionListener{
public void actionPerformed(ActionEvent e)
{
if((f1.getText()).equals("admin")&&(f2.getText()).equals("123"))
{
JOptionPane.showMessageDialog(null, "登錄成功!用戶許可權是adimistrator");
power="adminstrator";
}
else if((f1.getText()).equals("snake")&&(f2.getText()).equals("123456"))
{
JOptionPane.showMessageDialog(null, "登錄成功!登錄成功!用戶許可權是user");
power="adminstrator";
}
else JOptionPane.showMessageDialog(null, "登錄失敗,請重新登錄!");
}
}
class ReWrite implements ActionListener{
public void actionPerformed(ActionEvent e)
{
f1.setText("");
f2.setText("");
f1.requestFocus();
}
}
class winClose extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
(e.getWindow()).dispose();
System.exit(0);
}
}
}
9、求用 java 設計一個 登錄頁面 設計圖 在下面
/*
* LoginForm.java
*
*/
import java.awt.Toolkit;
/**
*
* @author LynK
*/
public class LoginForm extends javax.swing.JFrame {
private static final long serialVersionUID = 1L;
/** Creates new form LoginForm */
public LoginForm() {
initComponents();
int x = (int) ((Toolkit.getDefaultToolkit().getScreenSize().getWidth() - this
.getWidth()) / 2);
int y = (int) ((Toolkit.getDefaultToolkit().getScreenSize().getHeight() - this
.getHeight()) / 2);
this.setLocation(x, y);
}
/**
* 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();
jSeparator1 = new javax.swing.JSeparator();
jPanel2 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jPasswordField1 = new javax.swing.JPasswordField();
jComboBox1 = new javax.swing.JComboBox();
jSeparator2 = new javax.swing.JSeparator();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("\u7cfb\u7edf\u767b\u5f55");
setResizable(false);
jLabel1.setFont(new java.awt.Font("微軟雅黑", 0, 36));
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("\u56fe\u4e66\u7ba1\u7406\u7cfb\u7edf 9.34");
jLabel2.setFont(new java.awt.Font("微軟雅黑", 0, 14));
jLabel2.setText("\u7528\u6237\u540d:");
jLabel3.setFont(new java.awt.Font("微軟雅黑", 0, 14));
jLabel3.setText("\u5bc6 \u7801:");
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
"超級管理員", "普通用戶" }));
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(
jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout
.setHorizontalGroup(jPanel2Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
jPanel2Layout
.createSequentialGroup()
.addGap(61, 61, 61)
.addGroup(
jPanel2Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel3))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
jPanel2Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING,
false)
.addComponent(
jComboBox1,
0,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(
jPasswordField1,
javax.swing.GroupLayout.DEFAULT_SIZE,
145,
Short.MAX_VALUE))
.addGap(96, 96, 96)));
jPanel2Layout
.setVerticalGroup(jPanel2Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
jPanel2Layout
.createSequentialGroup()
.addContainerGap(16, Short.MAX_VALUE)
.addGroup(
jPanel2Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(
jComboBox1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
jPanel2Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(
jPasswordField1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap()));
jButton1.setText("\u767b\u5f55");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("\u53d6\u6d88");
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(
jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout
.setHorizontalGroup(jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addContainerGap()
.addComponent(
jLabel1,
javax.swing.GroupLayout.PREFERRED_SIZE,
352,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
.addComponent(jSeparator1,
javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE, 376,
Short.MAX_VALUE)
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addContainerGap()
.addComponent(
jPanel2,
javax.swing.GroupLayout.PREFERRED_SIZE,
352,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
.addComponent(jSeparator2,
javax.swing.GroupLayout.DEFAULT_SIZE, 376,
Short.MAX_VALUE)
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addGap(74, 74, 74)
.addComponent(jButton1)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED,
110, Short.MAX_VALUE)
.addComponent(jButton2).addGap(78, 78,
78)));
jPanel1Layout
.setVerticalGroup(jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addContainerGap()
.addComponent(
jLabel1,
javax.swing.GroupLayout.PREFERRED_SIZE,
52,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
jSeparator1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
jPanel2,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(
jSeparator2,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(29, 29, 29)
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addContainerGap(36, 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.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)));
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();
}// </editor-fold>
//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
/**
* 以下就可處理業務
*/
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
/**
* @param args
* the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new LoginForm().setVisible(true);
}
});
}
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPasswordField jPasswordField1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JSeparator jSeparator2;
// End of variables declaration//GEN-END:variables
}
10、java如何做一個可以登陸網頁的程序
你如果要簡單,在login頁面加三個表單標簽,一個text,一個password,一個submit,外面框個form標簽,action指定到你程序後台,跳到資料庫驗證,然後返回結果,將用戶名密碼提交到後台驗證方法很多,樓上講的struts是其中一種,但是如果你連登陸都不知道做,還是先別用struts了,直接將action跳到另一個頁面,另一個頁面獲取login頁面的用戶名和密碼,
login.jsp中寫
<from action ="logindo.jsp">
用戶名:<input type="text" name="username"><br>
密碼:<input type="password" name="password"><br>
<input type = "submit" value="登陸">
</from>
logindo.jsp中寫
<%
String username = request.getParamenter("username");//獲取登陸頁面穿過來的用戶名
String password= request.getParamenter("password");//獲取登錄頁面傳過來的密碼
.login(username,password);//跑到程序後台驗證用戶名密碼錯誤
%>
其他的我就不寫了,大致都寫完了,希望對你有幫助,別忘記採納