你要先學(xué)會截圖哦,你發(fā)的看不清楚,重新寫了一個你參考參考!
創(chuàng)新互聯(lián)2013年開創(chuàng)至今,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目網(wǎng)站制作、網(wǎng)站建設(shè)網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元岑鞏做網(wǎng)站,已為上家服務(wù),為岑鞏各地企業(yè)和個人服務(wù),聯(lián)系電話:18980820575
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("注冊賬戶");
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("賬號: ");
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布局與其它語言相比難度較大,建議你將兩張圖片PS成一張圖片,做為背景,加入到JFRAME中,以降低難度。
要是這個你喜歡,不要忘記多給我加分?。。。?/p>
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;//表示權(quán)限
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("系統(tǒng)登錄");
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,?"登錄成功!用戶權(quán)限是adimistrator");
power="adminstrator";
}
else?if((f1.getText()).equals("snake")(f2.getText()).equals("123456"))
{
JOptionPane.showMessageDialog(null,?"登錄成功!登錄成功!用戶權(quán)限是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);
}
}
}
import?java.awt.Dimension;
import?java.awt.Toolkit;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?javax.swing.JButton;
import?javax.swing.JFrame;
import?javax.swing.JLabel;
import?javax.swing.JOptionPane;
import?javax.swing.JPasswordField;
import?javax.swing.JTextField;
public?class?Test26?{
public?static?void?main(String[]?args)?{
final?String?userName?=?"abc";
final?String?passwrod?=?"123";
JFrame?jFrame?=?new?JFrame("登陸界面");
Dimension?dimension?=?Toolkit.getDefaultToolkit().getScreenSize();
jFrame.setBounds(((int)dimension.getWidth()?-?200)?/?2,?((int)dimension.getHeight()?-?300)?/?2,?200,?150);
jFrame.setResizable(false);
jFrame.setLayout(null);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel?label1?=?new?JLabel("姓名");
label1.setBounds(10,?10,?100,?30);
jFrame.add(label1);
JLabel?label2?=?new?JLabel("密碼");
label2.setBounds(10,?40,?100,?30);
jFrame.add(label2);
final?JTextField?text1?=?new?JTextField();
text1.setBounds(50,?15,?130,?20);
jFrame.add(text1);
final?JPasswordField?text2?=?new?JPasswordField();
text2.setBounds(50,?45,?130,?20);
jFrame.add(text2);
JButton?button?=?new?JButton("Login");
button.setBounds(10,?75,?170,?40);
button.addActionListener(new?ActionListener()?{
@Override
public?void?actionPerformed(ActionEvent?e)?{
if(userName.equals(text1.getText())??passwrod.equals(text2.getText()))?{
JOptionPane.showMessageDialog(null,?"登陸成功誤",?"提示",?JOptionPane.INFORMATION_MESSAGE);
}?else?{
JOptionPane.showMessageDialog(null,?"錯誤",?"提示",?JOptionPane.ERROR_MESSAGE);
text1.setText("");
text2.setText("");
}
}
});
jFrame.add(button);
jFrame.setVisible(true);
}
}
我有一個微信公眾號,經(jīng)常會分享一些Java技術(shù)相關(guān)的干貨,還有一些學(xué)習資源。
如果你喜歡我的分享,可以用微信搜索“Java團長”或者“javatuanzhang”關(guān)注。
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
class LoginFrm extends JFrame implements ActionListener
{
JLabel lbl1=new JLabel("用戶名");
JLabel lbl2=new JLabel("密碼");
JTextField txt=new JTextField(15);
JPasswordField pf=new JPasswordField();
JButton btn1=new JButton("確定");
JButton btn2=new JButton("取消");
public LoginFrm()
{
this.setTitle("登陸");
JPanel jp=(JPanel)this.getContentPane();
jp.setLayout(new GridLayout(3,2,10,10));
jp.add(lbl1);jp.add(txt);
jp.add(lbl2);jp.add(pf);
jp.add(btn1);jp.add(btn2);
btn1.addActionListener(this);
btn2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==btn1)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:MyDB","","");
Statement cmd=con.createStatement();
ResultSet rs=cmd.executeQuery("select * from loginAndpassword where login='"+txt.getText()+"' and password='"+pf.getText()+"'");
if(rs.next())
{
JOptionPane.showMessageDialog(null,"登陸成功!");
}
else
JOptionPane.showMessageDialog(null,"用戶名或密碼錯誤!");
} catch(Exception ex){}
if(ae.getSource()==btn2)
{
txt.setText("");
pf.setText("");
}
}
}
public static void main(String arg[])
{
JFrame.setDefaultLookAndFeelDecorated(true);
LoginFrm frm=new LoginFrm();
frm.setSize(400,200);
frm.setVisible(true);
}
}