bankingclient.TaoTaiKhoanFrame.java Source code

Java tutorial

Introduction

Here is the source code for bankingclient.TaoTaiKhoanFrame.java

Source

/*
 * 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 TaoTaiKhoanFrame extends javax.swing.JFrame {

    /**
     * Creates new form TaoTaiKhoanFrame
     */
    private NewOrOldAccFrame noAcc;
    private String mainCustomerName;

    public TaoTaiKhoanFrame(NewOrOldAccFrame acc) {

        initComponents();
        this.jText_ten_tk.setText("");
        this.jText_sd.setText("");

        this.noAcc = acc;
        this.mainCustomerName = null;
        this.setVisible(false);

        jBt_ht.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (NumberUtils.isNumber(jText_sd.getText()) && (Long.parseLong(jText_sd.getText()) > 0)) {
                    try {
                        Socket client = new Socket("113.22.46.207", 6013);
                        DataOutputStream dout = new DataOutputStream(client.getOutputStream());
                        dout.writeByte(3);
                        dout.writeUTF(jText_ten_tk.getText() + "\n" + mainCustomerName + "\n" + jText_sd.getText());
                        dout.flush();
                        DataInputStream din = new DataInputStream(client.getInputStream());
                        byte check = din.readByte();
                        if (check == 1) {
                            JOptionPane.showMessageDialog(rootPane, "da tao tai khoan thanh cong");
                        } else {
                            JOptionPane.showMessageDialog(rootPane, "tao tai khoan khong thanh cong");
                        }
                        client.close();
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                    noAcc.setVisible(true);
                    TaoTaiKhoanFrame.this.setVisible(false);
                } else {
                    JOptionPane.showMessageDialog(rootPane, "Can nhap lai so tien gui");
                }

            }
        });
        jBt_ql.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                noAcc.setVisible(true);
                TaoTaiKhoanFrame.this.setVisible(false);

            }
        });
    }

    public void setMainCustomer(String main) {
        this.mainCustomerName = main;
    }

    public void resetUI() {
        this.jText_ten_tk.setText("");
        this.jText_sd.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();
        jText_ten_tk = new javax.swing.JTextField();
        jBt_ht = new javax.swing.JButton();
        jBt_ql = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jText_sd = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Tn Ti Khon");

        jBt_ht.setText("Hon Tt");

        jBt_ql.setText("Quay Li");

        jLabel2.setText("S Ti?n Gi");

        jLabel3.setText("(VND)");

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(51, 153, 0));
        jLabel4.setText("To Ti Khon Ngn Hng");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addGap(32, 32, 32)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel1).addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        68, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(43, 43, 43)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel4)
                                .addComponent(jText_ten_tk, javax.swing.GroupLayout.PREFERRED_SIZE, 191,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(layout.createSequentialGroup().addGroup(layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addGroup(layout.createSequentialGroup().addComponent(jBt_ql)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(jBt_ht))
                                        .addComponent(jText_sd, javax.swing.GroupLayout.PREFERRED_SIZE, 191,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(28, 28, 28).addComponent(jLabel3)))
                        .addContainerGap(72, Short.MAX_VALUE)));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addGap(37, 37, 37).addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 49, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 17,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jText_ten_tk, 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.LEADING)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel3).addComponent(jText_sd,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup().addComponent(jLabel2).addGap(34, 34, 34)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jBt_ql).addComponent(jBt_ht))))
                        .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 jBt_ht;
    private javax.swing.JButton jBt_ql;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JTextField jText_sd;
    private javax.swing.JTextField jText_ten_tk;
    // End of variables declaration//GEN-END:variables
}