package Day2;
import Project1.Text1;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class LT extends JFrame {
public LT(){
this.setSize(550, 550);
this.setTitle("欢迎来到xxx聊天室");
this.setLocationRelativeTo(null);
this.setResizable(false);//设置窗口是否可以放大或缩小
//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel jPanel = new JPanel(new BorderLayout());
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
JButton jButton = new JButton("发送");
jButton.setFont(new Font("宋体", Font.BOLD, 20));
JTextArea Area = new JTextArea(6, 40);
Area.setLineWrap(true);
JScrollPane jScrollPane=new JScrollPane(Area);
jPanel2.add(jScrollPane);
jPanel2.add(jButton);
jButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String s = Area.getText();
if (s.length() == 0) {
JOptionPane.showMessageDialog(null, "请重新输入");
}
}
});
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
int a=JOptionPane.showConfirmDialog(null,"确定要退出聊天室吗","提示信息",JOptionPane.OK_CANCEL_OPTION);
if(a==0){
new Text1();
dispose();
}
}
});
jPanel.add(jPanel1, BorderLayout.CENTER);
jPanel.add(jPanel2, BorderLayout.SOUTH);
this.add(jPanel);
this.setVisible(true);
}
}
package Day2;
import Project1.Text1;
import Project1.Text3;
import sun.applet.Main;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class DL extends JFrame {
public DL(){
this.setSize(400, 450);//设置窗口大小
this.setTitle("欢迎登录");//设置标题
this.setLocationRelativeTo(null);
this.setResizable(false);//设置窗口是否可以放大或缩小
//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel jPanel=new JPanel(new GridLayout(4,1));
JPanel jPanel1=new JPanel(new FlowLayout());
JLabel jLabel=new JLabel("欢迎登录");
jLabel.setFont(new Font("楷体", 10, 40));
JPanel jPanel2=new JPanel(new FlowLayout());
//创建账号
JLabel jLabel1=new JLabel("账号");
jLabel1.setFont(new Font("宋体", Font.BOLD, 15));
JTextField jTextField=new JTextField(25);
JPanel jPanel3=new JPanel(new FlowLayout());
//创建密码
JLabel jLabel2=new JLabel("密码");
jLabel2.setFont(new Font("宋体", Font.BOLD, 15));
JPasswordField jPasswordField=new JPasswordField(25);
JPanel jPanel4=new JPanel(new FlowLayout(FlowLayout.CENTER,40,5));
JButton jButton=new JButton("登录");
JButton jButton1=new JButton("注册");
jButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String s1= jTextField.getText();
String s2=new String(jPasswordField.getPassword());
if(s1.length()==0&&s2.length()==0){
JOptionPane.showMessageDialog(null, "请重新输入账号");
}else
if(!(s1.matches("[0-9A-z]+"))||!(s2.matches("[0-9A-z]+"))){
JOptionPane.showMessageDialog(null, "账号密码只能由数字,字母组成");
}else{
JOptionPane.showMessageDialog(null, "登录成功");
new Text3();
dispose();
}
}
});
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
JOptionPane.showConfirmDialog(null,"确定要退出登录吗","提示信息",JOptionPane.OK_CANCEL_OPTION);
}
});
jPanel4.add(jButton);
jPanel4.add(jButton1);
jPanel3.add(jLabel2);
jPanel3.add(jPasswordField);
jPanel2.add(jLabel1);
jPanel2.add(jTextField);
jPanel1.add(jLabel);
jPanel.add(jPanel1);
jPanel.add(jPanel2);
jPanel.add(jPanel3);
jPanel.add(jPanel4);
this.add(jPanel);
this.setVisible(true);
}
public static void main(String[] args) {
new DL();
}
}