📄 mingregister.java
字号:
package com.neworiental.mj.mingregister;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.PrintStream;
import javax.swing.text.BadLocationException;
public class mingregister extends javax.swing.JFrame {
String sex;
String text1;
String text2;
String text3;
public mingregister() {
super("欢迎来到光明顶!");
initComponents();
}
private void initComponents() {
buttonGroup1 = new javax.swing.ButtonGroup();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jRadioButton1 = new javax.swing.JRadioButton();
if (jRadioButton1.isSelected()) {
sex = "男";
}
jRadioButton2 = new javax.swing.JRadioButton();
if (jRadioButton2.isSelected()) {
sex = "女";
}
jButton1 = new javax.swing.JButton();
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
text1 = jTextField1.getText();
text2 = jTextField2.getText();
text3 = jTextField3.getText();
if (text2.equals(text3) && text1 != null) {
try {
xieru();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
});
jButton2 = new javax.swing.JButton();
jButton2.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
mingregister.this.setVisible(false);
JFrame fa = new JFrame();
fa.setVisible(true);
// 返回到登录界面
}
});
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(153, 153, 255));
setResizable(false);
jLabel1.setText("请输入注册用户名:");
jLabel2.setText("请设置密码:");
jLabel3.setText("请再次输入密码:");
buttonGroup1.add(jRadioButton1);
buttonGroup1.add(jRadioButton2);
jRadioButton1.setText("男");
jRadioButton1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,
0, 0, 0));
jRadioButton1.setMargin(new java.awt.Insets(0, 0, 0, 0));
jRadioButton1.setName("man");
jRadioButton2.setText("女");
jRadioButton2.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,
0, 0, 0));
jRadioButton2.setMargin(new java.awt.Insets(0, 0, 0, 0));
jRadioButton2.setName("man");
jButton1.setText("注册进入聊天室");
jButton2.setText("返回登录界面");
jLabel4.setText("性别:");
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup().addContainerGap(47, Short.MAX_VALUE)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jLabel2).add(jLabel1).add(jLabel3).add(jLabel4).add(jButton1))
.add(9, 9, 9)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING,false)
.add(jTextField3)
.add(jTextField2)
.add(jTextField1,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,165,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addContainerGap(74,Short.MAX_VALUE))
.add(org.jdesktop.layout.GroupLayout.TRAILING,layout.createSequentialGroup().add(14,14,14)
.add(jRadioButton1)
.add(46,46,46)
.add(jRadioButton2)
.add(97,97,97)))
.add(layout.createSequentialGroup().add(60,60,60)
.add(
jButton2)
.addContainerGap()))));
layout
.setVerticalGroup(layout
.createParallelGroup(
org.jdesktop.layout.GroupLayout.LEADING)
.add(
layout
.createSequentialGroup()
.add(24, 24, 24)
.add(
layout
.createParallelGroup(
org.jdesktop.layout.GroupLayout.BASELINE)
.add(
jTextField1,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(
jLabel1,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
29,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(
org.jdesktop.layout.LayoutStyle.RELATED)
.add(
layout
.createParallelGroup(
org.jdesktop.layout.GroupLayout.BASELINE)
.add(
jTextField2,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(
jLabel2,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
23,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(
org.jdesktop.layout.LayoutStyle.RELATED)
.add(
layout
.createParallelGroup(
org.jdesktop.layout.GroupLayout.BASELINE)
.add(
jTextField3,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(
jLabel3,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
24,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(19, 19, 19)
.add(
layout
.createParallelGroup(
org.jdesktop.layout.GroupLayout.BASELINE)
.add(jRadioButton1)
.add(
jLabel4,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
27,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jRadioButton2))
.add(32, 32, 32)
.add(
layout
.createParallelGroup(
org.jdesktop.layout.GroupLayout.BASELINE)
.add(jButton2).add(
jButton1))
.addContainerGap(43, Short.MAX_VALUE)));
pack();
}
public static void main(String args[]) {
mingregister z = new mingregister();
z.setVisible(true);
}
private void xieru() throws Exception {
FileWriter file = new FileWriter("D:\\yhxx.txt", true);
BufferedWriter bw = new BufferedWriter(file);
bw.write(text1+"="+ text2);
bw.newLine() ;
bw.close() ;
ClientChat cc = new ClientChat(jTextField1.getText().trim());
cc.initComponent() ;
mingregister.this.setVisible(false);
// 跳到聊天界面
}
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JRadioButton jRadioButton2;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -