📄 loginframe.java
字号:
import java.awt.Color;
import java.awt.Font;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
/**
* author sunringove
* data 2007-01-17
* 登陆窗口
*/
public class LoginFrame extends JFrame implements ActionListener,WindowListener{
private static final long serialVersionUID = 1L;
private JButton loginButton,exitButton;
private TextField userName,inputPassWord;
private JLabel name,passWord,welcome;
private JMenuBar menuBar=new JMenuBar();
private JMenuItem item1,item2;
public String uName,pWord;
public boolean active=false;
public LoginFrame()
{
this.setBackground(new Color(212,208,200));
setSize(550,440);
setResizable(false);
setTitle("sunringove");
setLocation(180,80);
getContentPane().setLayout(null);
JMenu file=new JMenu("File");
item1=new JMenuItem("log in");
file.add(item1);
file.addSeparator();
item2=new JMenuItem("Exit");
file.add(item2);
menuBar.add(file);
setJMenuBar(menuBar);
loginButton=new JButton("log in");
loginButton.setBounds(185,270,80,30);
loginButton.setFont(new Font("黑体",Font.PLAIN,14));
getContentPane().add(loginButton);
exitButton=new JButton("Exit");
exitButton.setBounds(300,270,80,30);
exitButton.setFont(new Font("黑体",Font.PLAIN,14));
getContentPane().add( exitButton);
welcome=new JLabel("社团成员管理客户端登陆");
welcome.setFont(new Font("微软雅黑",Font.PLAIN,25));
welcome.setBounds(170,85,300,30);
getContentPane().add(welcome);
name=new JLabel("name");
name.setFont(new Font("黑体",Font.PLAIN,15));
name.setBounds(170,150,60,30);
getContentPane().add(name);
passWord=new JLabel("password");
passWord.setFont(new Font("黑体",Font.PLAIN,15));
passWord.setBounds(170,185,80,30);
getContentPane().add(passWord);
userName=new TextField();
inputPassWord=new TextField();
inputPassWord.setEchoChar('*');
userName.setBounds(255,160,130,23);
inputPassWord.setBounds(255,190,130,23);
getContentPane().add(userName);
getContentPane().add(inputPassWord);
exitButton.addActionListener(this);
loginButton.addActionListener(this);
userName.addActionListener(this);
inputPassWord.addActionListener(this);
item1.addActionListener(this);
item2.addActionListener(this);
inputPassWord.addActionListener(this);
addWindowListener(this);
}
// ************************************************************************************
//窗口事件处理
//************************************************************************************
public void windowClosing( WindowEvent event )
{
System.exit(0);
}
public void windowActivated (WindowEvent event) { }
public void windowClosed (WindowEvent event) { }
public void windowDeactivated (WindowEvent event) { }
public void windowDeiconified (WindowEvent event) { }
public void windowIconified (WindowEvent event) { }
public void windowOpened (WindowEvent event) { }
public void actionPerformed(ActionEvent e)
{
String value=e.getActionCommand();
if(value.equals("Exit"))
{
System.exit(0);
}
else
{
uName=userName.getText();
pWord=inputPassWord.getText();
active=true;
}
}
// ************************************************************************************
//获取输入的名字
//************************************************************************************
public String getName(){
return uName;
}
// ************************************************************************************
//获取输入的密码
//************************************************************************************
public String getPassWord(){
return pWord;
}
// ************************************************************************************
//获取当前的状态
//************************************************************************************
public boolean hasActive(){
return active;
}
// ************************************************************************************
//置空输入栏
//************************************************************************************
public void resetInput(){
userName.setText(null);
inputPassWord.setText(null);
active=false;
}
// ************************************************************************************
//转到警告页面
//************************************************************************************
public void gotoAlterPage(){
JOptionPane.showMessageDialog(this,"Wrong name or passWord input!","warning",JOptionPane.WARNING_MESSAGE);
}
// ************************************************************************************
//转到欢迎界面
//************************************************************************************
public void gotoVertifyPage(){
JOptionPane.showMessageDialog(this,"legel user!","welcome",JOptionPane.WARNING_MESSAGE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -