?? logindialogdemo.java.bak
字號:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LoginDialogDemo extends JFrame
{
JButton button=new JButton("click Me");
JPanel panel=new JPanel(new FlowLayout());
public LoginDialogDemo()
{
final JFrame frame=this;
this.getContentPane().add(panel,BorderLayout.SOUTH);
panel.add(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){showLoginDialog(frame);}});
this.setSize(300,200);
this.setTitle("顯示登錄對話框");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.show();
}
void showLoginDialog(JFrame frame)
{
JPanel p=new JPanel(new GridLayout(0,1));
JTextField tfUserName=new JTextField();
JPasswordField tfPassword=new JPasswordField();
p.add(new JLabel("Username:"));
p.add(tfUserName);
p.add(new JLabel("Password:"));
p.add(tfPassword);
if(JOptionPane.showConfirmDialog(frame,p,"Login",JOptionPane.OK_CANCEL_OPTION,JOptionPane.PLAIN_MESSAGE)==JOptionPane.OK_OPTION)
{
System.out.println("User Name:"+tfUserName.getText());
System.out.println("Password:"+new String(tfPassword.getPassword()));
}
}
public static void main(String[] args)
{
LoginDialogDemo frame=new LoginDialogDemo();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -