📄 login.java
字号:
package com.chatroom;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.Reader;
import java.nio.channels.ReadableByteChannel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class Login extends JFrame {
private JPasswordField passwordField;
private JTextField textField;
public static Login login;
private Register register;
JOptionPane optionPane;
/**
* Launch the application
*
* @param args
*/
public static void main(String args[]) {
login = new Login();
login.setVisible(true);
}
/**
* Create the frame
*/
public Login() {
super("登录");
getContentPane().setBackground(Color.PINK);
getContentPane().setLayout(null);
setBounds(100, 100, 360, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
final JLabel label = new JLabel();
label.setForeground(Color.BLUE);
label.setBackground(Color.BLACK);
label.setText("用户名");
label.setBounds(66, 74, 120, 30);
getContentPane().add(label);
textField = new JTextField();
textField.setBounds(143, 75, 144, 30);
getContentPane().add(textField);
final JLabel label_1 = new JLabel();
label_1.setForeground(Color.BLUE);
label_1.setText("密码");
label_1.setBounds(66, 140, 120, 30);
getContentPane().add(label_1);
passwordField = new JPasswordField();
passwordField.setForeground(Color.RED);
passwordField.setBounds(143, 141, 144, 30);
getContentPane().add(passwordField);
final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
/*
* int i=0; if (textField.getText().length()==0) {
* optionPane.showMessageDialog(null, "用户名不能为空"); } else { i++; }
* if (passwordField.getPassword().length==0) {
* optionPane.showMessageDialog(null, "密码不能为空"); } else { i++; }
*/
try {
boolean a =true;
File f = new File("e:\\order.txt");
FileReader fw = new FileReader(f);
BufferedReader bw = new BufferedReader(fw);
for(int i=0;i<register.personNumber;i++){
String readMessage = bw.readLine();
System.out.println(readMessage);
}
//bw.close();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
});
button.setBackground(Color.CYAN);
button.setText("登录");
button.setBounds(195, 235, 120, 30);
getContentPane().add(button);
final JButton button_1 = new JButton();
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
toRegister();
}
});
button_1.setBackground(Color.CYAN);
button_1.setForeground(Color.BLACK);
button_1.setText("注册");
button_1.setBounds(32, 235, 120, 30);
getContentPane().add(button_1);
final JLabel label_2 = new JLabel();
label_2.setBackground(Color.BLACK);
label_2.setForeground(Color.YELLOW);
label_2.setFont(new Font("华文行楷", Font.BOLD | Font.ITALIC, 26));
label_2.setText(" 友谊聊天室");
label_2.setBounds(0, 0, 354, 56);
getContentPane().add(label_2);
//
}
private void toRegister() {
// TODO Auto-generated method stub
if (this.isVisible()) {
this.setVisible(false);
register = new Register();
register.setVisible(true);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -