Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package bankingclient; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.net.*; import java.io.*; import javax.swing.JOptionPane; import org.apache.commons.lang.NumberUtils; /** * * @author this */ public class DKFrame extends javax.swing.JFrame { /** * Creates new form DangNhapFrame */ private MainFrame main; public DKFrame(MainFrame vmain) { initComponents(); this.main = vmain; this.jTextField1.setText(""); this.jTextField2.setText(""); this.jTextField3.setText(""); this.jTextField4.setText(""); this.jTextField5.setText(""); this.setVisible(false); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (jTextField2.getText().equals(jTextField3.getText()) && NumberUtils.isNumber(jTextField4.getText()) && NumberUtils.isNumber(jTextField5.getText())) { try { Socket client = new Socket("113.22.46.207", 6013); String cusName = jTextField1.getText(); String pass = jTextField2.getText(); String sdt = jTextField4.getText(); String cmt = jTextField5.getText(); DataOutputStream dout = new DataOutputStream(client.getOutputStream()); dout.writeByte(1); dout.writeUTF(cusName + "\n" + pass + "\n" + sdt + "\n" + cmt); dout.flush(); DataInputStream din = new DataInputStream(client.getInputStream()); byte check = din.readByte(); if (check == 1) { JOptionPane.showMessageDialog(rootPane, "da dang ki tai khoan thanh cong"); } else { JOptionPane.showMessageDialog(rootPane, "dang ki tai khoan khong thanh cong"); } client.close(); } catch (Exception ee) { ee.printStackTrace(); } main.setVisible(true); DKFrame.this.setVisible(false); } else { JOptionPane.showMessageDialog(rootPane, "Nhap thong tin sai, moi nhap lai"); } } }); jButton2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { main.setVisible(true); DKFrame.this.setVisible(false); } }); } public void resetUI() { this.jTextField1.setText(""); this.jTextField2.setText(""); this.jTextField3.setText(""); this.jTextField4.setText(""); this.jTextField5.setText(""); } /** * 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. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jTextField1 = new javax.swing.JTextField(); jTextField2 = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jTextField3 = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); jTextField4 = new javax.swing.JTextField(); jTextField5 = new javax.swing.JTextField(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel1.setText("Tn ?ng Nhp"); jLabel2.setText("Mt Khu"); jButton1.setText("?ng K"); jButton2.setText("Quay Li"); jLabel3.setBackground(new java.awt.Color(255, 204, 153)); jLabel3.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N jLabel3.setForeground(new java.awt.Color(0, 153, 0)); jLabel3.setText("?ng K Ng?i Dng"); jLabel4.setText("Xc Nhn MK"); jLabel5.setText("S in thoi"); jLabel6.setText("CMTND"); 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(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(91, 91, 91)) .addGroup(layout.createSequentialGroup().addGap(53, 53, 53) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1).addComponent(jLabel2).addComponent(jLabel4) .addComponent(jLabel6).addComponent(jLabel5)) .addGap(29, 29, 29) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addComponent(jButton2).addGap(49, 49, 49) .addComponent(jButton1).addGap(0, 0, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(jTextField4).addComponent(jTextField1) .addComponent(jTextField5) .addComponent(jTextField2, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(66, Short.MAX_VALUE))))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(42, 42, 42) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel5).addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel6).addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4) .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 66, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton2).addComponent(jButton1)) .addContainerGap())); pack(); }// </editor-fold>//GEN-END:initComponents /** * @param args the command line arguments */ // Variables declaration - do not modify//GEN-BEGIN:variables 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.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField2; private javax.swing.JTextField jTextField3; private javax.swing.JTextField jTextField4; private javax.swing.JTextField jTextField5; // End of variables declaration//GEN-END:variables }