?? logindemo.java
字號:
package chapter14;
import javax.swing.*;
public class LoginDemo extends JFrame
{
//聲明組件
JLabel lblTitle,lblUser,lblPass;
JTextField txtUser;
JPasswordField pwdPass;
JButton btnLogin,btnExit;
JPanel pnlMain;
//構造方法
public LoginDemo()
{
//調用父類構造函數
super("用戶登錄");
pnlMain=new JPanel();
//設置JFrame的容器為pnlMain
this.getContentPane().add(pnlMain);
//實例化組件
lblTitle=new JLabel(new ImageIcon("welcome.gif"));
lblUser=new JLabel("用戶名:");
txtUser=new JTextField(12);
lblPass=new JLabel("密碼:");
pwdPass=new JPasswordField(12);
//"登錄"按鈕
Icon imgLogin=new ImageIcon("login.gif");
btnLogin=new JButton("登錄(L)",imgLogin);
btnLogin.setMnemonic('L');
btnLogin.setToolTipText("點擊登錄");
//"退出"按鈕
Icon imgExit=new ImageIcon("exit.gif");
btnExit=new JButton("退出(X)",imgExit);
btnExit.setMnemonic('X');
btnExit.setToolTipText("退出登錄");
//添加組件到面板
pnlMain.add(lblTitle);
pnlMain.add(lblUser);
pnlMain.add(txtUser);
pnlMain.add(lblPass);
pnlMain.add(pwdPass);
pnlMain.add(btnLogin);
pnlMain.add(btnExit);
//設置窗口屬性
setSize(225,200);
setResizable(false);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
//主方法
public static void main(String args[])
{
new LoginDemo();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -