mylogin2.java
来自「java+sql 图书管理系统」· Java 代码 · 共 161 行
JAVA
161 行
package MyLibraryok.MyLogin;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import MyLibraryok.MySwing.*;
import java.awt.event.*;
import MyLibraryok.books.untitled1.Tu;
/**
* <p>Title: 登陆界面</p>
*
* <p>Description: 描述</p>
*
* <p>Copyright: 082401 (c) 2007</p>
*
* <p>Company: 清代IT0824</p>
*
* @author 侯韶君
* @version 2.0
*/
public class MyLogin2 extends JFrame {
static{
try {
UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");
} catch (UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
} catch (IllegalAccessException ex) {
ex.printStackTrace();
} catch (InstantiationException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
}
Dimension screen = getToolkit().getScreenSize(); //得到屏幕尺寸
int myWidth = screen.width / 7;
int myHeight = screen.height / 5;
int px = 3 * myWidth / 7;
int py = myHeight / 5;
Container container = getContentPane(); //得到容器
GridLayout gridLayout1 = new GridLayout(2, 1); //登录窗口布局
public MyLogin2() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
container.setLayout(gridLayout1);
paneldown.setLayout(null);
// paneldown.setBackground(Color.pink);
buttonLogin.setBounds(5 * px + py - 3, py + 5, px + 5, px + 5);
buttonLogin.setFont(new java.awt.Font("Dialog", Font.BOLD, 16));
// buttonLogin.setBorder(border1);
buttonLogin.setText("登录(L)");
buttonLogin.setMnemonic('L');
// buttonLogin.setEnabled(false);
this.getRootPane().requestFocus();
this.getRootPane().setDefaultButton(buttonLogin);
用户名.setFont(new java.awt.Font("Dialog", Font.BOLD, 16));
用户名.setText("用户名:");
用户名.setBounds(py, py - 3, 2 * px, py);
密码.setFont(new java.awt.Font("Dialog", Font.BOLD, 16));
密码.setText("密 码:");
密码.setBounds(py, 3 * py - 13, px, py);
textUserName.setFont(new java.awt.Font("Dialog", Font.PLAIN, 16));
textUserName.requestFocus(true);
//1.4后由FocusTraversalPolicy取代
textUserName.setNextFocusableComponent(password);
textUserName.setToolTipText("");
textUserName.setSelectedTextColor(Color.white);
textUserName.setText("");
textUserName.setBounds(2 * px, py - 3, 3 * px, py);
password.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
password.setNextFocusableComponent(buttonLogin);
password.setSelectedTextColor(Color.white);
password.setText("");
password.setEchoChar('●');
password.setBounds(2 * px, 3 * py - 13, 3 * px, py);
Tu tu = new Tu("Image/loginImage.png");
// this.setIconImage(im.getImage());
container.add(tu);
container.add(paneldown);
paneldown.add(用户名);
paneldown.add(密码);
paneldown.add(textUserName);
paneldown.add(password);
paneldown.add(buttonLogin);
buttonLogin.addActionListener(new MyLoginListener2(this));
setSize(3 * myWidth, 2 * myHeight);
setLocation(2 * myWidth,
myHeight); //设置窗口位置
ImageIcon im = new ImageIcon("Image/loginIcon.png");
this.setIconImage(im.getImage());
this.setResizable(false);
this.addWindowListener(new WindowListener(){
public void windowActivated(WindowEvent e) {
}
public void windowClosed(WindowEvent e) {
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public void windowDeactivated(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowOpened(WindowEvent e) {
}
}
);
setVisible(true);
}
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true);
MyLogin2 mylogin2 = new MyLogin2();
}
// MyImage myImage = new MyImage("login.jpg");
JPanel paneldown = new JPanel();
JLabel 用户名 = new JLabel();
JLabel 密码 = new JLabel();
JTextField textUserName = new JTextField();
JPasswordField password = new JPasswordField();
TitledBorder titledBorder1 = new TitledBorder("");
Border border1 = BorderFactory.createCompoundBorder(BorderFactory.
createEtchedBorder(Color.white, new java.awt.Color(148, 145, 140)),
BorderFactory.createEmptyBorder(2, 2, 2, 2));
ZButton buttonLogin = new ZButton();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?