?? logon.java
字號:
/*
* logon.java
*
* Created on 2007年12月19日, 下午7:55
*/
/**
*
* @author Admin
*/
import java.io.*;
import java.net.*;
import javax.swing.*;
public class logon extends javax.swing.JFrame {
public static Socket clientskt= null;
/** Creates new form logon */
public logon() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" 生成的代碼 ">//GEN-BEGIN:initComponents
private void initComponents() {
logonLable = new javax.swing.JLabel();
usernameTF = new javax.swing.JTextField();
usernameLable = new javax.swing.JLabel();
newNameBtn = new javax.swing.JButton();
passwordLable = new javax.swing.JLabel();
logonBtn = new javax.swing.JButton();
usernameExplainLable = new javax.swing.JLabel();
passwordExplainLable = new javax.swing.JLabel();
passwordJPF = new javax.swing.JPasswordField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("SuperWhisper beta1");
setResizable(false);
logonLable.setText("Log on");
usernameLable.setText("Username");
newNameBtn.setText("new user");
newNameBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
newNameBtnActionPerformed(evt);
}
});
passwordLable.setText("Password");
logonBtn.setText("log on");
logonBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
logonBtnActionPerformed(evt);
}
});
usernameExplainLable.setText("characters and numbers only and 8 at most");
passwordExplainLable.setText("characters and numbers only and 10 at most");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(314, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(logonBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(newNameBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(24, 24, 24))
.addGroup(layout.createSequentialGroup()
.addGap(30, 30, 30)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(passwordLable)
.addComponent(passwordExplainLable, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(logonLable, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(usernameLable, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(usernameTF)
.addComponent(usernameExplainLable, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(passwordJPF))
.addGap(150, 150, 150))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(25, 25, 25)
.addComponent(logonLable)
.addGap(27, 27, 27)
.addComponent(usernameLable)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(usernameTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(usernameExplainLable)
.addGap(17, 17, 17)
.addComponent(passwordLable)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(passwordJPF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(passwordExplainLable)
.addGap(10, 10, 10)
.addComponent(logonBtn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(newNameBtn)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void request()
{
try{
clientskt = new Socket("127.0.0.1", 2000);
DataOutputStream dos = new DataOutputStream(clientskt.getOutputStream());
dos.writeBytes("1");
dos.close();
clientskt.close();
}catch(UnknownHostException uhex)
{
System.err.println(uhex);
}catch(IOException ioex)
{
System.err.println(ioex);
}
}
private String receive()
{
String recString = "";
try{
clientskt = new Socket("127.0.0.1", 2001);
BufferedReader binReader = new BufferedReader(new InputStreamReader(clientskt.getInputStream()));
recString = binReader.readLine();
System.out.println(recString);//
binReader.close();
clientskt.close();
}catch(UnknownHostException ex){
System.err.println(ex);
}catch(IOException ex){
System.err.println(ex);
}
return recString;
}
private void logonAndnewuser(int mode, String username, String password, String sessionkey)
{
try{
clientskt = new Socket("127.0.0.1", 2000);
DataOutputStream dos = new DataOutputStream(clientskt.getOutputStream());
dos.writeBytes(""+mode+username+"&"+password+"&"+sessionkey);
dos.close();
clientskt.close();
}catch(UnknownHostException uhex)
{
System.err.println(uhex);
}catch(IOException ioex)
{
System.err.println(ioex);
}
}
private void newNameBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newNameBtnActionPerformed
// TODO 將在此處添加您的處理代碼:
this.setVisible(false);
new register().setVisible(true);
}//GEN-LAST:event_newNameBtnActionPerformed
private void logonBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logonBtnActionPerformed
// TODO 將在此處添加您的處理代碼:
String username = usernameTF.getText();
String password = String.valueOf(passwordJPF.getPassword());
String mes = "";
request();
mes = receive();
if(mes.equals("1&fffff"));
{
logonAndnewuser(0, username, password, "123456");
}
mes = receive();
if(mes.equals("welcome"))
{
this.setVisible(false);
new clientWindow().setVisible(true);
}
}//GEN-LAST:event_logonBtnActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new logon().setVisible(true);
}
});
}
// 變量聲明 - 不進行修改//GEN-BEGIN:variables
private javax.swing.JButton logonBtn;
private javax.swing.JLabel logonLable;
private javax.swing.JButton newNameBtn;
private javax.swing.JLabel passwordExplainLable;
private javax.swing.JPasswordField passwordJPF;
private javax.swing.JLabel passwordLable;
private javax.swing.JLabel usernameExplainLable;
private javax.swing.JLabel usernameLable;
private javax.swing.JTextField usernameTF;
// 變量聲明結束//GEN-END:variables
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -