?? loginframe.java
字號(hào):
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("動(dòng)物園管理系統(tǒng)");
JLabel label_1 = new JLabel(" userid ");
JLabel label_2 = new JLabel("password");
System.out.println("1" + label_1.getLocation());//測(cè)試
b_subit.addActionListener(this);
b_reset.addActionListener(this);
this.setResizable(false);
this.setSize(360,200);
this.setLocation(300,240); //設(shè)置框架尺寸
this.setBackground(Color.LIGHT_GRAY); //設(shè)置框架背景顏色
this.setLocation(300,240); //框架顯示在屏幕的位置
this.setLayout(new FlowLayout()); //框架流布局,居中
this.add(new JLabel(" "));
this.add(label_1); //創(chuàng)建標(biāo)簽,添加到框架上
this.add(loginname ); //創(chuàng)建文本行
this.add(this.blank1);
this.add(label_2);
this.add(password); //創(chuàng)建20列的文本行
this.add(this.blank2);
this.add(this.blank3);
this.add(b_subit); //創(chuàng)建按鈕
this.add(b_reset);
this.addWindowListener(new WinClose());
// this.pack();
}
public void actionPerformed(ActionEvent e) //單擊按鈕時(shí)觸發(fā)執(zhí)行
{
if (e.getSource()==b_subit)
{ if(loginname.getText().equals("admin")&&password.getText().equals("123"))
{userjframe.setVisible(true);
loginframe.setVisible(false);
}
else {JOptionPane.showMessageDialog(this,"原始默認(rèn)登陸就是對(duì)的,誰(shuí)讓你改的.\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) //單擊窗口關(guān)閉按鈕時(shí)觸發(fā)并執(zhí)行
{ //實(shí)現(xiàn)WindowListener接口中的方法
System.exit(0); //結(jié)束程序運(yùn)行
}
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) { }
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -