📄 enroll.java
字号:
package investcompanyclient;import java.awt.FlowLayout;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.KeyEvent;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.IOException;import java.io.InputStreamReader;import java.io.OutputStreamWriter;import java.io.PrintWriter;import javax.swing.JButton;import javax.swing.JFormattedTextField;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField;import javax.swing.SwingConstants;import javax.swing.WindowConstants;import javax.swing.SwingUtilities;import java.net.*;import java.awt.*;import java.io.*;import java.util.*;import javax.swing.*;import java.awt.event.*;/** * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI * Builder, which is free for non-commercial use. If Jigloo is being used * commercially (ie, by a corporation, company or business for any purpose * whatever) then you should purchase a license for each developer using Jigloo. * Please visit www.cloudgarden.com for details. Use of Jigloo implies * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR * ANY CORPORATE OR COMMERCIAL PURPOSE. */public class enroll extends javax.swing.JFrame implements ActionListener ,KeyListener{ private JPanel jPanel1; private JLabel jLabel2; private JTextField jTextField1; private JLabel jLabel1; private JLabel jLabel4; private JLabel jLabel8; private JButton jButton3; private JPanel Radiobuttons; private JButton jButton2; private JButton jButton1; private JPanel jPanel9; private JPanel jPanel8; private JTextField jTextField5; private JTextField jTextField4; private JTextField jTextField3; private JTextField jTextField2; private JLabel jLabel7; private JLabel jLabel6; private JLabel jLabel5; private JPasswordField jPasswordField2; private JPasswordField jPasswordField1; private JLabel jLabel3; private JPanel jPanel7; private JPanel jPanel6; private JPanel jPanel5; private JPanel jPanel4; private JPanel jPanel3; private JPanel jPanel2; private Socket socket; private BufferedReader in; private JRadioButton investbutton; private JRadioButton devbutton; private PrintWriter out; private String type; /** * Auto-generated main method to display this JFrame */ /* * public static void main(String[] args) { SwingUtilities.invokeLater(new * Runnable() { public void run() { enroll inst = new enroll(); * inst.setLocationRelativeTo(null); inst.setVisible(true); } }); } */ public enroll(Socket s) { super(); socket = s; type = ""; try { in = new BufferedReader(new InputStreamReader(socket .getInputStream())); out = new PrintWriter(new BufferedWriter(new OutputStreamWriter( socket.getOutputStream())), true); } catch (IOException e) { System.out.println(e); } initGUI(); } private void initGUI() { try { GridLayout thisLayout = new GridLayout(9, 1); thisLayout.setHgap(5); thisLayout.setVgap(5); thisLayout.setColumns(1); thisLayout.setRows(9); getContentPane().setLayout(thisLayout); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.setTitle("\u6ce8\u518c\u4e2d"); this.setLocation(new java.awt.Point(400, 180)); { jPanel1 = new JPanel(); FlowLayout jPanel1Layout = new FlowLayout(); getContentPane().add(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setAlignment(FlowLayout.LEFT); jPanel1Layout.setAlignment(FlowLayout.LEFT); { jLabel1 = new JLabel(); jPanel1.add(jLabel1); jLabel1.setText("ID:"); jLabel1.setPreferredSize(new java.awt.Dimension(130, 36)); jLabel1.setHorizontalAlignment(SwingConstants.RIGHT); } { jTextField1 = new JTextField(); jPanel1.add(jTextField1); jTextField1 .setPreferredSize(new java.awt.Dimension(391, 42)); } } { jPanel2 = new JPanel(); FlowLayout jPanel2Layout = new FlowLayout(); getContentPane().add(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setAlignment(FlowLayout.RIGHT); jPanel2Layout.setAlignment(FlowLayout.LEFT); { jLabel2 = new JLabel(); jPanel2.add(jLabel2); jLabel2.setText("\u5bc6\u7801\uff1a"); jLabel2.setPreferredSize(new java.awt.Dimension(136, 33)); jLabel2.setHorizontalAlignment(SwingConstants.RIGHT); } { jPasswordField1 = new JPasswordField(); jPanel2.add(jPasswordField1); jPasswordField1.setPreferredSize(new java.awt.Dimension( 388, 34)); } } { jPanel3 = new JPanel(); getContentPane().add(jPanel3); FlowLayout jPanel3Layout = new FlowLayout(); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setAlignment(FlowLayout.LEFT); jPanel3Layout.setAlignment(FlowLayout.LEFT); { jLabel3 = new JLabel(); jPanel3.add(jLabel3); jLabel3.setText("\u786e\u8ba4\u5bc6\u7801\uff1a"); jLabel3.setPreferredSize(new java.awt.Dimension(139, 38)); jLabel3.setFocusTraversalPolicyProvider(true); jLabel3.setHorizontalAlignment(SwingConstants.RIGHT); } { jPasswordField2 = new JPasswordField(); jPanel3.add(jPasswordField2); jPasswordField2.setPreferredSize(new java.awt.Dimension( 393, 36)); } } { jPanel4 = new JPanel(); FlowLayout jPanel4Layout = new FlowLayout(); getContentPane().add(jPanel4); jPanel4.setLayout(jPanel4Layout); { jLabel4 = new JLabel(); jPanel4.add(jLabel4); jLabel4.setText("\u6ce8\u518c\u516c\u53f8\u540d"); jLabel4.setPreferredSize(new java.awt.Dimension(137, 27)); jLabel4.setHorizontalAlignment(SwingConstants.RIGHT); } { jTextField2 = new JTextField(); jPanel4.add(jTextField2); jTextField2 .setPreferredSize(new java.awt.Dimension(393, 29)); } jPanel4Layout.setAlignment(FlowLayout.LEFT); jPanel4Layout.setAlignment(FlowLayout.LEFT); } { jPanel5 = new JPanel(); FlowLayout jPanel5Layout = new FlowLayout(); getContentPane().add(jPanel5); jPanel5.setLayout(jPanel5Layout); { jLabel5 = new JLabel(); jPanel5.add(jLabel5); jLabel5.setText("\u6ce8\u518c\u8d44\u91d1"); jLabel5.setHorizontalAlignment(SwingConstants.RIGHT); jLabel5.setPreferredSize(new java.awt.Dimension(142, 30)); } { jTextField3 = new JTextField(); jTextField3.addKeyListener(this); jPanel5.add(jTextField3); jTextField3 .setPreferredSize(new java.awt.Dimension(416, 30)); } jPanel5Layout.setAlignment(FlowLayout.LEFT); jPanel5Layout.setAlignment(FlowLayout.LEFT); } { jPanel6 = new JPanel(); FlowLayout jPanel6Layout = new FlowLayout(); getContentPane().add(jPanel6); jPanel6.setLayout(jPanel6Layout); { jLabel6 = new JLabel(); jPanel6.add(jLabel6); jLabel6.setText("\u5458\u5de5\u6570\uff1a"); jLabel6.setPreferredSize(new java.awt.Dimension(132, 28)); jLabel6.setHorizontalAlignment(SwingConstants.RIGHT); } { jTextField4 = new JTextField(); jPanel6.add(jTextField4); jTextField4 .setPreferredSize(new java.awt.Dimension(409, 32)); jTextField4.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { jTextField4KeyPressed(evt); } }); } jPanel6Layout.setAlignment(FlowLayout.LEFT); jPanel6Layout.setAlignment(FlowLayout.LEFT); } { jPanel7 = new JPanel(); FlowLayout jPanel7Layout = new FlowLayout(); getContentPane().add(jPanel7); jPanel7.setLayout(jPanel7Layout); { jLabel7 = new JLabel(); jPanel7.add(jLabel7); jLabel7.setText("\u516c\u53f8\u7b80\u4ecb\uff1a"); jLabel7.setHorizontalAlignment(SwingConstants.RIGHT); jLabel7.setPreferredSize(new java.awt.Dimension(136, 26)); } { jTextField5 = new JTextField(); jPanel7.add(jTextField5); jTextField5 .setPreferredSize(new java.awt.Dimension(421, 30)); } jPanel7Layout.setAlignment(FlowLayout.LEFT); jPanel7Layout.setAlignment(FlowLayout.LEFT); } { jPanel8 = new JPanel(); BorderLayout jPanel8Layout = new BorderLayout(); getContentPane().add(jPanel8); jPanel8.setLayout(jPanel8Layout); { jLabel8 = new JLabel(); jPanel8.add(jLabel8, BorderLayout.WEST); jLabel8.setText("\u516c\u53f8\u7c7b\u578b"); jLabel8.setPreferredSize(new java.awt.Dimension(132, 45)); jLabel8.setHorizontalAlignment(SwingConstants.RIGHT); } { Radiobuttons = new JPanel(); Radiobuttons.add(investbutton = new JRadioButton("投资公司")); Radiobuttons.add(devbutton = new JRadioButton("开发公司")); jPanel8.add(Radiobuttons, BorderLayout.CENTER); ButtonGroup group = new ButtonGroup(); group.add(investbutton); group.add(devbutton); investbutton.setMnemonic('I'); devbutton.setMnemonic('d'); investbutton.addActionListener(this); devbutton.addActionListener(this); } } { jPanel9 = new JPanel(); FlowLayout jPanel9Layout = new FlowLayout(); getContentPane().add(jPanel9); jPanel9.setLayout(jPanel9Layout); { jButton1 = new JButton(); jPanel9.add(jButton1); jButton1.setText("\u786e\u5b9a"); jButton1.setPreferredSize(new java.awt.Dimension(79, 22)); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jButton1ActionPerformed(evt); } }); } { jButton2 = new JButton(); jPanel9.add(jButton2); jButton2.setText("\u53d6\u6d88"); jButton2.setPreferredSize(new java.awt.Dimension(82, 22)); jButton2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jButton2ActionPerformed(evt); } }); } { jButton3 = new JButton(); jPanel9.add(jButton3); jButton3.setText("\u9000\u51fa"); jButton3.setPreferredSize(new java.awt.Dimension(78, 22)); jButton3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jButton3ActionPerformed(evt); } }); } } pack(); this.setSize(623, 486); } catch (Exception e) { e.printStackTrace(); } } public void actionPerformed(ActionEvent e) { if (e.getSource() == investbutton) { type = "investor"; } if (e.getSource() == devbutton) { type = "developer"; } } private void jButton2ActionPerformed(ActionEvent evt) { this.dispose(); this.setVisible(false); } private void jButton1ActionPerformed(ActionEvent evt) { String t5 = jTextField5.getText(); String t4 = jTextField4.getText(); String t3 = jTextField3.getText(); String t2 = jTextField2.getText(); String t1 = jTextField1.getText(); String p2 = new String(jPasswordField2.getPassword()); String p1 = new String(jPasswordField1.getPassword()); if(t1.equals("")||t2.equals("")||t3.equals("")||t4.equals("")||t5.equals("")||p1.equals("")||p2.equals("")||type.equals("")) { JOptionPane.showMessageDialog(null, "少输入,请重新操作!"); return; } else if (!p1.equals(p2)) { JOptionPane.showMessageDialog(null, "密码错误请重输"); jPasswordField1.setText(""); jPasswordField2.setText(""); return; } else { String str = "enroll" + "/" + t1 + "/" + p1 +"/"+t2+"/" + type + "/" +t5+"/"+ t3 + "/" + t4 ; out.println(str); try { str = in.readLine(); if(str.equals("idexists")) { JOptionPane.showMessageDialog(null, "用户名已经存在!请重新注册"); jTextField1.setText(""); jTextField2.setText(""); jTextField3.setText(""); jTextField4.setText(""); jTextField5.setText(""); jPasswordField1.setText(""); jPasswordField2.setText(""); } else if (str.equals("eok")) { JOptionPane.showMessageDialog(null, "成功注册!"); jTextField1.setText(""); jTextField2.setText(""); jTextField3.setText(""); jTextField4.setText(""); jTextField5.setText(""); jPasswordField1.setText(""); jPasswordField2.setText(""); } else { JOptionPane.showMessageDialog(null, "注册失败!重试"); jTextField1.setText(""); jTextField2.setText(""); jTextField3.setText(""); jTextField4.setText(""); jTextField5.setText(""); jPasswordField1.setText(""); jPasswordField2.setText(""); } } catch (IOException e) { } } } private void jButton3ActionPerformed(ActionEvent evt) { this.dispose(); this.setVisible(false); } public void keyPressed(KeyEvent e) { if((e.getKeyCode()<KeyEvent.VK_0||e.getKeyCode()>KeyEvent.VK_9)&&(e.getKeyCode()!=KeyEvent.VK_PERIOD)&&(e.getKeyCode()!=KeyEvent.VK_BACK_SPACE)) { JOptionPane.showMessageDialog(null,"请输入数字","警告",JOptionPane.WARNING_MESSAGE); jTextField3.setText(""); } } public void keyReleased(KeyEvent e) { // TODO Auto-generated method stub } public void keyTyped(KeyEvent e) { // TODO Auto-generated method stub } private void jTextField4KeyPressed(KeyEvent e) { if((e.getKeyCode()<KeyEvent.VK_0||e.getKeyCode()>KeyEvent.VK_9)&&(e.getKeyCode()!=KeyEvent.VK_PERIOD)&&(e.getKeyCode()!=KeyEvent.VK_BACK_SPACE)) { JOptionPane.showMessageDialog(null,"请输入数字","警告",JOptionPane.WARNING_MESSAGE); jTextField4.setText(""); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -