📄 directorframe[anank].java
字号:
import javax.swing.*;
import java.awt.*;
import java.sql.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.table.* ;
import javax.swing.event.ListSelectionListener ;//用ListSelectionListener和ListSelectionEvent的时候好像要单独引入!~
import javax.swing.event.ListSelectionEvent ;
import javax.swing.table.* ;
import javax.swing.tree.* ;
public class DirectorFrame
{
public DirectorFrame()
{
JFrame.setDefaultLookAndFeelDecorated(true);//把JFrame设置城修饰的外观!
final JFrame frame = new JFrame("登录系统") ;
frame.setSize(360, 200) ;
//
GridBagLayout gbl = new GridBagLayout() ;
GridBagConstraints gbc = new GridBagConstraints() ;
Container content = frame.getContentPane() ;
content.setLayout(gbl) ;
//
JLabel lblName = new JLabel("用户名", SwingConstants.LEFT) ;
gbc.gridx = 0 ;
gbc.gridy = 0 ;
gbc.insets = new Insets(10, 0, 20, 15) ;
gbl.setConstraints(lblName, gbc) ;
content.add(lblName) ;
gbc.insets = new Insets(0, 0, 0, 0) ;
//
final JTextField txtName = new JTextField(15) ;
txtName.setText("请在这里输入用户名") ;
txtName.selectAll() ;
gbc.gridx++ ;
gbc.gridy = gbc.gridy ;
gbc.insets = new Insets(10, 15, 20, 0) ;
gbl.setConstraints(txtName, gbc) ;
content.add(txtName) ;
gbc.insets = new Insets(0, 0, 0, 0) ;
//
final JLabel lblPassword = new JLabel("密码" , SwingConstants.LEFT) ;
gbc.gridx = 0 ;
gbc.gridy++ ;
gbc.insets = new Insets(10, 0, 20, 15) ;
gbl.setConstraints(lblPassword, gbc) ;
content.add(lblPassword) ;
gbc.insets = new Insets(0, 0, 0, 0) ;
//
final JPasswordField txtPassword = new JPasswordField(15) ;
//txtPassword.setText("请在这里输入密码") ;
gbc.gridx++ ;
gbc.gridy = gbc.gridy ;
gbc.insets = new Insets(10, 15, 20, 0) ;
gbl.setConstraints(txtPassword, gbc) ;
content.add(txtPassword) ;
gbc.insets = new Insets(0, 0, 0, 0) ;
//
txtName.addFocusListener(new FocusListener()
{
public void focusGained(FocusEvent e)
{
txtName.selectAll() ;
}
public void focusLost(FocusEvent e){}
}) ;//监听类结束!
txtPassword.addFocusListener(new FocusListener()
{
public void focusGained(FocusEvent e)
{
txtPassword.selectAll() ;
}
public void focusLost(FocusEvent e){}
}) ;//监听类结束!
//
final JButton btnLogOn = new JButton("登录") ;
btnLogOn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(!txtName.getText().trim().equals("anank"))
{
JOptionPane.showMessageDialog(null, "没有此用户!") ;
return ;
}
if(!txtPassword.getText().trim().equals("123456"))
{
JOptionPane.showMessageDialog(null, "密码错误!") ;
return ;
}
new MainFrame() ;
frame.setVisible(false) ;
frame.dispose() ;
}
}) ;//监听类结束!
gbc.gridx = 0 ;
gbc.gridy++ ;
gbc.ipadx = 30;
gbc.ipady = -4 ;
gbc.insets = new Insets(0, 0, 0, 0) ;
gbl.setConstraints(btnLogOn, gbc) ;
content.add(btnLogOn) ;
//
final JButton btnCancel = new JButton("取消") ;
btnCancel.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
frame.setVisible(false) ;
frame.dispose() ;
System.exit(0) ;
}
}) ;//监听类结束!
gbc.gridx++ ;
gbc.gridy = gbc.gridy ;
gbc.ipadx = 30 ;
gbc.ipady = -4 ;
gbc.insets = new Insets(0, 92, 0, 0) ;
gbl.setConstraints(btnCancel, gbc) ;
content.add(btnCancel) ;
///////////////////////////////////////////////
//frame.pack() ;
frame.setLocation(200, 200) ;
frame.setResizable(false) ;
frame.setVisible(true) ;
}
public static void main(String args[])
{
new DirectorFrame() ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -