?? loginwindow.java
字號:
package com.lovo.event;
import java.awt.Container;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.ServerSocket;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class LoginWindow extends JFrame{
public void init()
{ //界面窗口
this.setSize(400, 300);
this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
this.setTitle("登陸");
this.setLocationRelativeTo(null);
}
//成員變量
JTextField userText;
JPasswordField userPwdText;
JButton button1;
JButton button2;
int port = 0;
public LoginWindow()
{ //具體設置
init();
Container contentPane = this.getContentPane();
contentPane.setLayout(null);
JLabel jl1 = new JLabel();
jl1.setText("用戶名:");
jl1.setBounds(new Rectangle(94, 98, 42, 15));
userText = new JTextField();
userText.setBounds(162, 98, 81, 21);
JLabel jl2 = new JLabel();
jl2.setText("密 碼:");
jl2.setBounds(new Rectangle(94, 146, 42, 15));
userPwdText = new JPasswordField();
userPwdText.setBounds(new Rectangle(162, 146, 81, 25));
button1 = new JButton();
button1.setBounds(new Rectangle(108, 210, 63, 25));
button1.addActionListener(new ActionListener()
{//事件監聽
public void actionPerformed(ActionEvent e)
{
try
{//轉換
port = Integer.parseInt(userText.getText().trim());
if(null != userPwdText.getPassword() && userPwdText.getPassword().length!=0)
{
LoginWindow.this.dispose();
new ChatWindow(port);//設置
}
}
catch(NumberFormatException e1)
{
userText.setText("用戶名輸入有誤");
}
}
});
button1.setText("登陸");
//事件監聽
button2 = new JButton();
button2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
);
//加入組件
button2.setBounds(new Rectangle(197, 210, 63, 25));
button2.setText("取消");
contentPane.add(jl1);
contentPane.add(userText);
contentPane.add(jl2);
contentPane.add(userPwdText);
contentPane.add(button1);
contentPane.add(button2);
this.setVisible(true);
}
public static void main(String[] args) {
new LoginWindow();//完成
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -