📄 register.java
字号:
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(trueNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(countryField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(favField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(telField, javax.swing.GroupLayout.DEFAULT_SIZE, 24, Short.MAX_VALUE)
.addComponent(jLabel6))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(submitBtn)
.addComponent(resetBtn))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(myWebLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void formMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseMoved
// TODO add your handling code here:
myWebLabel.setForeground(Color.BLUE);
}//GEN-LAST:event_formMouseMoved
private void myWebLabelMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_myWebLabelMouseMoved
// TODO add your handling code here:
if(evt.getSource()==myWebLabel){
myWebLabel.setForeground(Color.RED);
myWebLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}else{
myWebLabel.setForeground(Color.BLUE);
}
}//GEN-LAST:event_myWebLabelMouseMoved
private void myWebLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_myWebLabelMouseClicked
try {
// TODO add your handling code here:
Runtime.getRuntime().exec(
"rundll32 url.dll,FileProtocolHandler http://club.gamvan.com/");
} catch (IOException ex) {
this.dispose();
}
}//GEN-LAST:event_myWebLabelMouseClicked
private void resetBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetBtnActionPerformed
// 用来重新设置个人信息
usernameField.setText(null);
passwordField.setText(null);
trueNameField.setText(null);
countryField.setText(null);
favField.setText(null);
telField.setText(null);
confPassword.setText(null);
}//GEN-LAST:event_resetBtnActionPerformed
private void submitBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_submitBtnActionPerformed
// 用来提交个人注册信息
//首先要检测用户名和密码是否为空
if(usernameField.getText().equals("")||passwordField.getPassword().equals("")||
confPassword.getPassword().equals("")){
JOptionPane.showMessageDialog(this,"抱歉,用户名或者密码不能为空","注册提示",
JOptionPane.INFORMATION_MESSAGE);
if(usernameField.getText().equals("")){
usernameLabel.setForeground(Color.RED);
}
if(passwordField.getPassword().equals("")){
passwordLabel.setForeground(Color.red);
}
if(confPassword.getPassword().equals("")){
confPasswordLabel.setForeground(Color.RED);
}
}else{
String str=new String(passwordField.getPassword());
String str2=new String(confPassword.getPassword());
if(!str.equalsIgnoreCase(str2)){
JOptionPane.showMessageDialog(this,"对不起,两次输入的密码不一致,请重新输入!","注册失败",
JOptionPane.INFORMATION_MESSAGE);
confPasswordLabel.setForeground(Color.RED);
passwordLabel.setForeground(Color.RED);
return;
}
try {
Socket clientSocket=new Socket("192.168.1.111",6544);
dataIn=new ObjectInputStream(clientSocket.getInputStream());
dataOut=new ObjectOutputStream(clientSocket.getOutputStream());
clientSocket.setSoTimeout(5000);
dataOut.writeObject("注册信息");
dataOut.flush();
sendRegisterMsg();
String result = (String) dataIn.readObject();
if(result.equalsIgnoreCase("注册成功")){
JOptionPane.showMessageDialog(this,"恭喜你已经成功注册!","注册成功",
JOptionPane.INFORMATION_MESSAGE);
dispose();
}else if(!result.equalsIgnoreCase("注册失败")&&
!result.equalsIgnoreCase("注册成功")){
JOptionPane.showMessageDialog(this,"对不起,现在还不行,请过后再试试看!","注册失败",
JOptionPane.INFORMATION_MESSAGE);
}
if(result.equalsIgnoreCase("注册失败")){
JOptionPane.showMessageDialog(this,"对不起,ID已经存在了,换一个试试看吧!","注册失败",
JOptionPane.INFORMATION_MESSAGE);
}
} catch (UnknownHostException ex) {
ex.printStackTrace();
System.exit(0);
} catch (IOException ex) {
ex.printStackTrace();
System.exit(0);
}catch(ClassNotFoundException ex){
ex.printStackTrace();
System.exit(0);
}
}
}//GEN-LAST:event_submitBtnActionPerformed
/*
*向服务器端发送注册信息
*/
private void sendRegisterMsg() throws IOException{
//将密码转换成字符串型
String password=new String(passwordField.getPassword());
//首先发送用户名和密码
dataOut.writeObject(usernameField.getText());
dataOut.flush();
dataOut.writeObject(password);
dataOut.flush();
//发送其他用户注册信息
dataOut.writeObject(trueNameField.getText());
dataOut.flush();
dataOut.writeObject(countryField.getText());
dataOut.flush();
dataOut.writeObject(favField.getText());
dataOut.flush();
dataOut.writeObject(telField.getText());
dataOut.flush();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Register().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPasswordField confPassword;
private javax.swing.JLabel confPasswordLabel;
private javax.swing.JTextField countryField;
private javax.swing.JTextField favField;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel myWebLabel;
private javax.swing.JPasswordField passwordField;
private javax.swing.JLabel passwordLabel;
private javax.swing.JButton resetBtn;
private javax.swing.JButton submitBtn;
private javax.swing.JTextField telField;
private javax.swing.JTextField trueNameField;
private javax.swing.JTextField usernameField;
private javax.swing.JLabel usernameLabel;
// End of variables declaration//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -