📄 loginframe.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LoginFrame extends JFrame implements ActionListener
{
JButton b_subit =new JButton("submit");
JButton b_reset =new JButton(" exit ");
JLabel blank1=new JLabel(" ");
JLabel blank2=new JLabel(" ");
JLabel blank3=new JLabel(" ");
TextField loginname = new TextField ("admin",25);
JPasswordField password = new JPasswordField("123",18);
static UserJFrame userjframe = new UserJFrame();
static LoginFrame loginframe = new LoginFrame();
public LoginFrame()
{
super("动物园管理系统");
JLabel label_1 = new JLabel(" userid ");
JLabel label_2 = new JLabel("password");
System.out.println("1" + label_1.getLocation());//测试
b_subit.addActionListener(this);
b_reset.addActionListener(this);
this.setResizable(false);
this.setSize(360,200);
this.setLocation(300,240); //设置框架尺寸
this.setBackground(Color.LIGHT_GRAY); //设置框架背景颜色
this.setLocation(300,240); //框架显示在屏幕的位置
this.setLayout(new FlowLayout()); //框架流布局,居中
this.add(new JLabel(" "));
this.add(label_1); //创建标签,添加到框架上
this.add(loginname ); //创建文本行
this.add(this.blank1);
this.add(label_2);
this.add(password); //创建20列的文本行
this.add(this.blank2);
this.add(this.blank3);
this.add(b_subit); //创建按钮
this.add(b_reset);
this.addWindowListener(new WinClose());
// this.pack();
}
public void actionPerformed(ActionEvent e) //单击按钮时触发执行
{
if (e.getSource()==b_subit)
{ if(loginname.getText().equals("admin")&&password.getText().equals("123"))
{userjframe.setVisible(true);
loginframe.setVisible(false);
}
else {JOptionPane.showMessageDialog(this,"原始默认登陆就是对的,谁让你改的.\n呵呵") ;
System.out.println(loginname.getText().equals("admin"));}
}
if (e.getSource()==b_reset){
System.exit(0);
}
}
public static void main(String arg[])
{
loginframe.setVisible(true); //显示框架
// System.out.println(myzoo.showmessage());
}
}
class WinClose implements WindowListener
{
public void windowClosing(WindowEvent e) //单击窗口关闭按钮时触发并执行
{ //实现WindowListener接口中的方法
System.exit(0); //结束程序运行
}
public void windowOpened(WindowEvent e) { }
public void windowActivated(WindowEvent e) { }
public void windowDeactivated(WindowEvent e) { }
public void windowClosed(WindowEvent e) { }
public void windowIconified(WindowEvent e) { }
public void windowDeiconified(WindowEvent e) { }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -