โปรแกรมโรงพยาบาล HosJava บนฐานข้อมูล MariaDB (โปรแกรมฟอร์มยักษ์) มากมายหลายห้องตรวจ

ในห้อง 'คอมพิวเตอร์ & อินเตอร์เน็ต' ตั้งกระทู้โดย ledphong, 7 กันยายน 2014.

  1. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    เป็นแท้แน่นอน รอโปรแกรมมาพัฒนาโปรแกรมค่ายนี้แน่นอนคงหลาย แสน หรือ หลายล้านบาทแน่นอน

    ขณะนี้โปรแกรมโรงพยาบาล ยังคงใช้ HosXP for windows อยู่
     
    แก้ไขครั้งล่าสุดโดยผู้ดูแล: 11 กรกฎาคม 2015
  2. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    ใช้ Java Open Source เขียนแบบ Style Sun Microsystems
    =================================
    เขียน Text Mode วัดความเข้าใจ Java เชิงลึกสไตล์ฝรั่ง
     
  3. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    ตัวอย่างบางตอนที่เขียน Java ไม่อาศัย Tool Box เข้ามาเลยสักตัว
     

    ไฟล์ที่แนบมา:

    • MyOlder_2.png
      MyOlder_2.png
      ขนาดไฟล์:
      151.9 KB
      เปิดดู:
      208
  4. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    เขียน Java NetBeans ไม่ใช้ ToolBox คุ้มค่าสุดๆ และอีกอย่างแข็งแรงสุด ๆ
    สรุปเขียนแบบดังเดิมสไตล์ Sun Microsystems
     
  5. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    เท่าที่เขียนโปรแกรม Java NetBeans มาหากเขียนแบบสมัยใหม่คงอืดน่าดู หากเขียนแบบเดิม ๆ (เขียนแบบไม่ใช้ ToolBox) โอเค ดีครับ
     
  6. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    รูปแบบการเขียน Java NetBeans แบบดังเดิมวัดความเข้าใจ Java เชิงลึก
    =====================================
    ==========มาตรฐาน=========================
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;

    // A Swing GUI application inherits from top-level container javax.swing.JFrame
    public class ...... extends JFrame {

    // private variables
    // ......

    /** Constructor to setup the GUI components */
    public ......() {
    Container cp = this.getContentPane();

    // Content-pane sets layout
    cp.setLayout(new ....Layout());

    // Allocate the GUI components
    // .....

    // Content-pane adds components
    cp.add(....);

    // Source object adds listener
    // .....

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // Exit the program when the close-window button clicked
    setTitle("......"); // "this" JFrame sets title
    setSize(300, 150); // "this" JFrame sets initial size (or pack())
    setVisible(true); // show it
    }

    /** The entry main() method */
    public static void main(String[] args) {
    // Run GUI codes in Event-Dispatching thread for thread-safety
    SwingUtilities.invokeLater(new Runnable() {
    @Override
    public void run() {
    new ......(); // Let the constructor do the job
    }
    });
    }
    }
    ==========================================
     
  7. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    ดีไซน์หน้าจอก่อนครับ
     
  8. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    HosJava.java

    ===================
    package main;

    import java.awt.event.ActionEvent;
    import java.text.ParseException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.*;

    public class HosJava extends javax.swing.JFrame {

    JDesktopPane jDesktopPane1;
    JMenuItem FormAdd;
    JMenuBar MenuBar;
    JMenu MenuFile;

    public HosJava() {
    initComponents();
    //this.setLocationRelativeTo(null);//center
    this.setExtendedState(HosJava.MAXIMIZED_BOTH);//Maximized
    setTitle("โปรแกรม Hos Java V.2015 ( Java Open Source 7.3.1 ::Database MariaDB )");
    }

    @SuppressWarnings("unchecked")

    private void initComponents() {

    jDesktopPane1 = new javax.swing.JDesktopPane();
    MenuBar = new javax.swing.JMenuBar();
    MenuFile = new javax.swing.JMenu();
    FormAdd = new javax.swing.JMenuItem();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    MenuFile.setText("แฟ้ม");

    FormAdd.setText("เพิ่มรายการหลัก");
    FormAdd.addActionListener(new java.awt.event.ActionListener() {
    @Override
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    try {
    FormAddActionPerformed(evt);
    } catch (ParseException ex) {
    Logger.getLogger(HosJava.class.getName()).log(Level.SEVERE, null, ex);
    }
    }
    });
    MenuFile.add(FormAdd);

    MenuBar.add(MenuFile);

    setJMenuBar(MenuBar);

    pack();
    }

    private void FormAddActionPerformed(ActionEvent evt) throws ParseException {
    FormAdd f1 = new FormAdd("เพิ่มรายการหลัก");
    jDesktopPane1.add(f1);
    f1.show();
    }

    public static void main(String args[]) {

    java.awt.EventQueue.invokeLater(new Runnable() {
    @Override
    public void run() {
    new HosJava().setVisible(true);
    }
    });
    }
    }
     
  9. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    FormAdd.java

    ==================
    package main;

    import java.awt.Container;
    import java.text.ParseException;
    import javax.swing.JFrame;
    import javax.swing.SpringLayout;

    public class FormAdd extends javax.swing.JInternalFrame{

    FormAdd(String เพิ่มรายการหลัก) throws ParseException{
    JFrame.setDefaultLookAndFeelDecorated(true);

    JFrame frame = new JFrame("เพิ่มข้อมูล / แแก้ไขข้อมูล / ลบข้อมูล / ค้นหาข้อมูล");

    Container contentPane = frame.getContentPane();
    SpringLayout layout = new SpringLayout();
    contentPane.setLayout(layout);

    //Display the window.

    frame.pack();
    frame.setVisible(true);
    frame.setSize(690,450);//800,645
    frame.setResizable(false);//ไม่ให้ Resize
    frame.setLocationRelativeTo(null);
    }
    }
     

    ไฟล์ที่แนบมา:

    • 1.png
      1.png
      ขนาดไฟล์:
      82.4 KB
      เปิดดู:
      91
  10. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    กำหนดเลข HN ให้กับคนไข้
     
  11. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    ใช้ SpringLayout ใช้งานง่ายกว่า GridBagLayout ใน Java NetBeans
     
  12. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    ตัวอย่าง การวาง GridBagLayout ของเดิม
    ======================
    เขียนแบบดั้งเดิมของ Sun

    package main;

    import javax.swing.*;
    import java.awt.*;

    public class MyOlderGridBagLayout {

    public static void addItem(JPanel p,JComponent c,int x,int y,int width,int height,int align){
    GridBagConstraints gc = new GridBagConstraints();
    gc.gridx = x;
    gc.gridy = y;
    gc.gridwidth = width;
    gc.gridheight = height;
    gc.insets = new Insets(5,5,5,5);
    gc.anchor = align;
    gc.fill = GridBagConstraints.NONE;
    p.add(c,gc);
    }//addItem

    public static void main(String[] args) {
    JFrame f = new JFrame("โปรแกรมจ่ายเบี้ยยังชีพ My Older V.2015 R.1 ( Java Open Source::Database MariaDB )");
    JPanel p = new JPanel();
    p.setLayout(new GridBagLayout());

    JLabel lblCodePK,lblSexFK,lblTitleFK,lblFirstName,lblLastName,lblIDCard;
    JLabel lblBirthDate,lblBanID,lblMoo,lblTypeNameFK,lblAccessFK;
    JLabel lblLevelAccess,lblExpireDate,lblMoneyAccess,lblMoneyAids;
    JLabel lblGetMoneyFK,lblMethodMoneyFK,lblBankFK,lblBancee,lblSearch;
    JLabel lblCaretakerF,lblCaretakerL,lblBox1,lblBox2,lblBox3,lblMooFullName;
    JLabel lblFirstNameAcc,lblLastNameAcc,lblMooAcc;
    JTextField txtCodePK,txtCodeID,txtFirstName,txtLastName,txtIDCard;
    JTextField txtBirthDate,txtBanID,txtMoo,txtLevelAccess,txtExpireDate;
    JTextField txtMoneyAccess,txtMoneyAids,txtBancee;
    JTextField txtCaretakerF,txtCaretakerL,txtBox1,txtBox2,txtBox3,txtMooFullName;
    JTextField txtSearch,txtFirstNameAcc,txtLastNameAcc,txtMooAcc;

    lblCodePK = new JLabel("ลำดับที่ :");
    lblSexFK = new JLabel("เพศ :");
    lblTitleFK = new JLabel("คำนำหน้า :");
    lblFirstName = new JLabel("ชื่อ :");
    lblLastName = new JLabel("สกุล :");
    lblIDCard = new JLabel("เลขบัตรประชาชน :");
    lblBirthDate = new JLabel("ปี-เดือน-วัน เกิด(คศ.) :");
    lblBanID = new JLabel("บ้านเลขที่ :");
    lblMoo = new JLabel("หมู่ที่ :");
    lblTypeNameFK = new JLabel("ประเภทของผู้มีสิทธิ์ :");
    lblAccessFK = new JLabel("คุณสมบัติของคนพิการ :");
    lblExpireDate = new JLabel("บัตรคนพิการหมดอายุ:");
    lblLevelAccess = new JLabel("ระดับความพิการ :");
    lblMoneyAccess = new JLabel("เงินคนพิการ(บาท) :");
    lblMoneyAids = new JLabel("เงินผู้ติดเชื้อเอดส์(บาท) :");
    lblGetMoneyFK = new JLabel("ประเภทงบประมาณ :");
    lblMethodMoneyFK = new JLabel("วิธีขอรับเงิน :");
    lblBankFK = new JLabel("ชื่อธนาคาร :");
    lblBancee = new JLabel("เลขที่บัญชีธนาคาร :");
    lblCaretakerF = new JLabel("ชื่อ อผส. :");
    lblCaretakerL = new JLabel("สกุล อผส. :");
    lblBox1 = new JLabel("ปีงบประมาณรับเบี้ย ผส.");
    lblBox2 = new JLabel("ปีงบประมาณรับเบี้ย พก.");
    lblBox3 = new JLabel("ปีงบรับเบี้ยAids");
    lblMooFullName = new JLabel("หมู่ที่ อผส.");
    lblSearch = new JLabel("ค้นหาลำดับที่ :");
    lblFirstNameAcc = new JLabel("ชื่อ พก. :");
    lblLastNameAcc = new JLabel("สกุล พก. :");
    lblMooAcc = new JLabel("หมู่ที่ พก. :");



    txtCodePK = new JTextField(11);txtCodePK.setBackground(Color.pink);
    txtCodeID = new JTextField(11);txtCodeID.setBackground(Color.pink);
    txtFirstName = new JTextField(24);
    txtLastName = new JTextField(24);
    txtIDCard = new JTextField(24);
    txtBirthDate = new JTextField(11);txtBirthDate.setBackground(Color.pink);
    txtBanID = new JTextField(11);
    txtMoo = new JTextField(11);
    txtLevelAccess = new JTextField(11);
    txtExpireDate = new JTextField(11);txtExpireDate.setBackground(Color.pink);
    txtMoneyAccess = new JTextField(8);
    txtMoneyAids = new JTextField(8);
    txtBancee = new JTextField(24);
    txtCaretakerF = new JTextField(24);
    txtCaretakerL = new JTextField(24);
    txtBox1 = new JTextField(8);
    txtBox2 = new JTextField(8);
    txtBox3 = new JTextField(8);
    txtMooFullName = new JTextField(8);
    txtSearch = new JTextField(8);
    txtSearch.setBackground(Color.yellow);//Tab txtSearch Color YELLOW
    txtFirstNameAcc = new JTextField(11);
    txtLastNameAcc = new JTextField(8);
    txtMooAcc = new JTextField(11);
    //========ดูเดือน ก.พ.มี 28 หรือ 29 วัน==========
    //เอา คศ % 4 = 0 คือ มี 29 วัน
    //return ((($year % 4) == 0) && ((($year % 100) != 0) || (($year %400) == 0)));

    //=======ComboBox Sex=======================
    String SexFK[] = {"ชาย","หญิง"};
    JComboBox cmbSexFK = new JComboBox(SexFK);
    //==========================================

    //=======ComboBox Title=====================
    String TitleFK[] = {"นาย","นาง","นางสาว","เด็กชาย","เด็กหญิง","พระ","แม่ชี"};
    JComboBox cmbTitleFK = new JComboBox(TitleFK);
    //==========================================

    //=======ComboBox TypeNameFK================
    String TypeNameFK[] = {"ผู้สูงอายุ","ความพิการ","ผู้ติดเชื้อเอดส์","ผู้สูงอายุและความพิการ",
    "ผู้สูงอายุและผู้ติดเชื้อเอดส์","ความพิการและผู้ติดเชื้อเอดส์","ผู้สูงอายุความพิการผู้ติดเชื้อเอดส์",
    "มีเงินเดือน","พระมีเงินเดือนและความพิการ"};
    JComboBox cmbTypeNameFK = new JComboBox(TypeNameFK);
    //==========================================

    //=======ComboBox AccessFK==================
    String AccessFK[] = {"ไม่ระบุ","ความพิการทางการมองเห็น","ความพิการทางการได้ยิน","ความพิการทางการเคลื่อนไหว",
    "ความพิการทางการจิตใจหรือพฤติกรรม","ความพิการทางสติปัญญา","ความพิการทางการเรียนรู้",
    "ความพิการทางออทิสติก","ความพิการทางซ้ำซ้อน"};
    JComboBox cmbAccessFK = new JComboBox(AccessFK);
    //=======ComboBox GetMoneyFK================
    String GetMoneyFK[] = {"ไม่ระบุ","งบทั่วไป","งบอุดหนุนทั่วไปกำหนดวัตถุประสงค์","งบ อปท.จ่ายเอง"};
    JComboBox cmbGetMoneyFK = new JComboBox(GetMoneyFK);
    //=======ComboBox MethodMoney===============
    String MethodMoneyFK[] = {"ไม่ระบุ","รับเงินสด","โอนเข้าบัญชี"};
    JComboBox cmbMethodMoneyFK = new JComboBox(MethodMoneyFK);
    //=======ComboBox Bank======================
    String BankFK[] = {"ไม่ระบุ","กรุงไทย","กรุงศรีอยุธยา","กสิกรไทย","เกียรตินาคิน",
    "ทหารไทย","ไทยพาณิชย์","ธกส.","ธนชาติ","ออมสิน"};
    JComboBox cmbBankFK = new JComboBox(BankFK);
    //==========================================

    //==========Button==========================
    JButton btnGenID = new JButton("GenID");
    JButton btnAdd = new JButton("เพิ่มข้อมูล");
    JButton btnEdit = new JButton("แก้ไขข้อมูล");
    JButton btnDelete = new JButton("ลบข้อมูล");
    JButton btnRefresh = new JButton("รีเฟรซข้อมูล");
    JButton btnSearch = new JButton("ค้นหา");
    //=========GenID===========================
    addItem(p,btnGenID,3,0,1,1,GridBagConstraints.CENTER);
    btnGenID.setPreferredSize(new Dimension(90,25));
    //=========Add=============================
    addItem(p,btnAdd,4,0,1,1,GridBagConstraints.CENTER);
    btnAdd.setPreferredSize(new Dimension(120,25));
    //=========Edit============================
    addItem(p,btnEdit,4,1,2,1,GridBagConstraints.CENTER);
    btnEdit.setPreferredSize(new Dimension(120,25));
    //=========Delete==========================
    addItem(p,btnDelete,4,2,2,1,GridBagConstraints.CENTER);
    btnDelete.setPreferredSize(new Dimension(120,25));
    //=========Refresh=========================
    addItem(p,btnRefresh,4,3,2,1,GridBagConstraints.CENTER);
    btnRefresh.setPreferredSize(new Dimension(120,25));
    //=========btnSearch=======================
    addItem(p,btnSearch,4,10,2,1,GridBagConstraints.CENTER);
    btnSearch.setPreferredSize(new Dimension(120,25));
    //=========================================
    //คอลัมท์ แถว กว้าง สูง
    //==========CodePK=====================================
    addItem(p,lblCodePK,0,0,1,1,GridBagConstraints.WEST);
    addItem(p,txtCodePK,1,0,1,1,GridBagConstraints.CENTER);
    txtCodePK.setPreferredSize(new Dimension(20,25));
    //=====================================================

    //=========CodeID======================================
    addItem(p,txtCodeID,2,0,1,1,GridBagConstraints.CENTER);
    txtCodeID.setPreferredSize(new Dimension(20,25));
    //=====================================================

    //=========cmbSex======================================
    addItem(p,lblSexFK,0,1,1,1,GridBagConstraints.WEST);
    addItem(p,cmbSexFK,1,1,1,1,GridBagConstraints.WEST);
    cmbSexFK.setPreferredSize(new Dimension(120,25));
    //=====================================================

    //=========cmbTitle====================================
    addItem(p,lblTitleFK,0,2,1,1,GridBagConstraints.WEST);
    addItem(p,cmbTitleFK,1,2,1,1,GridBagConstraints.WEST);
    cmbTitleFK.setPreferredSize(new Dimension(120,25));
    //=====================================================

    //=========FirstName===================================
    addItem(p,lblFirstName,0,3,1,1,GridBagConstraints.WEST);
    addItem(p,txtFirstName,1,3,2,1,GridBagConstraints.CENTER);
    txtFirstName.setPreferredSize(new Dimension(30,25));
    //=====================================================

    //========LastName=====================================
    addItem(p,lblLastName,0,4,1,1,GridBagConstraints.WEST);
    addItem(p,txtLastName,1,4,2,1,GridBagConstraints.CENTER);
    txtLastName.setPreferredSize(new Dimension(30,25));
    //=====================================================

    //========IDCard=======================================
    addItem(p,lblIDCard,0,5,1,1,GridBagConstraints.WEST);
    addItem(p,txtIDCard,1,5,2,1,GridBagConstraints.CENTER);
    txtIDCard.setPreferredSize(new Dimension(20,25));
    //=====================================================

    //==========BirthDate===================================
    addItem(p,lblBirthDate,0,6,1,1,GridBagConstraints.WEST);
    addItem(p,txtBirthDate,1,6,1,1,GridBagConstraints.CENTER);
    txtBirthDate.setPreferredSize(new Dimension(20,25));
    //======================================================

    //==========BanID=======================================
    addItem(p,lblBanID,0,7,1,1,GridBagConstraints.WEST);
    addItem(p,txtBanID,1,7,1,1,GridBagConstraints.CENTER);
    txtBanID.setPreferredSize(new Dimension(20,25));
    //======================================================

    //==========Moo=========================================
    addItem(p,lblMoo,0,8,1,1,GridBagConstraints.WEST);
    addItem(p,txtMoo,1,8,1,1,GridBagConstraints.CENTER);
    txtMoo.setPreferredSize(new Dimension(20,25));
    //======================================================

    //==========cmdTypeNameFK===============================
    addItem(p,lblTypeNameFK,0,9,1,1,GridBagConstraints.WEST);
    addItem(p,cmbTypeNameFK,1,9,2,1,GridBagConstraints.CENTER);
    cmbTypeNameFK.setPreferredSize(new Dimension(270,25));
    //======================================================

    //==========cmdAccessFK=================================
    addItem(p,lblAccessFK,0,10,1,1,GridBagConstraints.WEST);
    addItem(p,cmbAccessFK,1,10,2,1,GridBagConstraints.CENTER);
    cmbAccessFK.setPreferredSize(new Dimension(270,25));
    //======================================================

    //==========LevelAccess=================================
    addItem(p,lblLevelAccess,0,11,1,1,GridBagConstraints.WEST);
    addItem(p,txtLevelAccess,1,11,1,1,GridBagConstraints.CENTER);
    txtLevelAccess.setPreferredSize(new Dimension(20,25));
    //======================================================

    //==========ExpireDate Access===========================
    addItem(p,lblExpireDate,0,12,1,1,GridBagConstraints.WEST);
    addItem(p,txtExpireDate,1,12,1,1,GridBagConstraints.CENTER);
    txtExpireDate.setPreferredSize(new Dimension(20,25));
    //======================================================

    //==========cmbGetMoneyFK================================
    addItem(p,lblGetMoneyFK,0,13,1,1,GridBagConstraints.WEST);
    addItem(p,cmbGetMoneyFK,1,13,2,1,GridBagConstraints.CENTER);
    cmbGetMoneyFK.setPreferredSize(new Dimension(270,25));
    //======================================================

    //==========cmbMethodMoneyFK============================
    addItem(p,lblMethodMoneyFK,0,14,1,1,GridBagConstraints.WEST);
    addItem(p,cmbMethodMoneyFK,1,14,1,1,GridBagConstraints.CENTER);
    cmbMethodMoneyFK.setPreferredSize(new Dimension(120,25));
    //======================================================

    //==========txtFirstNameAcc============================
    addItem(p,lblFirstNameAcc,2,14,1,1,GridBagConstraints.WEST);
    addItem(p,txtFirstNameAcc,2,15,1,1,GridBagConstraints.CENTER);
    txtFirstNameAcc.setPreferredSize(new Dimension(20,25));
    //======================================================

    //==========txtLastNameAcc============================
    addItem(p,lblLastNameAcc,3,14,1,1,GridBagConstraints.WEST);
    addItem(p,txtLastNameAcc,3,15,1,1,GridBagConstraints.CENTER);
    txtLastNameAcc.setPreferredSize(new Dimension(80,25));
    //======================================================

    //==========txtMooAcc============================
    addItem(p,lblMooAcc,4,14,1,1,GridBagConstraints.WEST);
    addItem(p,txtMooAcc,4,15,1,1,GridBagConstraints.CENTER);
    txtMooAcc.setPreferredSize(new Dimension(120,25));
    //======================================================

    //==========cmbBankFK================================
    addItem(p,lblBankFK,0,15,1,1,GridBagConstraints.WEST);
    addItem(p,cmbBankFK,1,15,1,1,GridBagConstraints.CENTER);
    cmbBankFK.setPreferredSize(new Dimension(120,25));
    //======================================================

    //==========Bancee======================================
    addItem(p,lblBancee,0,16,1,1,GridBagConstraints.WEST);
    addItem(p,txtBancee,1,16,2,1,GridBagConstraints.CENTER);
    txtBancee.setPreferredSize(new Dimension(120,25));
    //======================================================

    //==========CaretakerF==================================
    addItem(p,lblCaretakerF,0,17,1,1,GridBagConstraints.WEST);
    addItem(p,txtCaretakerF,1,17,2,1,GridBagConstraints.CENTER);
    txtCaretakerF.setPreferredSize(new Dimension(120,25));
    //======================================================

    //==========CaretakerL==================================
    addItem(p,lblCaretakerL,0,18,1,1,GridBagConstraints.WEST);
    addItem(p,txtCaretakerL,1,18,2,1,GridBagConstraints.CENTER);
    txtCaretakerL.setPreferredSize(new Dimension(120,25));
    //======================================================

    //==========Comment==================================
    //addItem(p,lblComment,0,19,1,1,GridBagConstraints.WEST);
    //addItem(p,txtComment,1,19,2,1,GridBagConstraints.CENTER);
    //txtComment.setPreferredSize(new Dimension(120,25));
    //===================================================

    //==========txtSearch==================================
    addItem(p,lblSearch,3,9,1,1,GridBagConstraints.WEST);
    addItem(p,txtSearch,3,10,1,1,GridBagConstraints.CENTER);
    txtSearch.setPreferredSize(new Dimension(80,25));
    //=======================================================

    //==========Box1========================================
    addItem(p,lblBox1,2,1,1,1,GridBagConstraints.WEST);
    addItem(p,txtBox1,3,1,1,1,GridBagConstraints.CENTER);
    txtBox1.setPreferredSize(new Dimension(80,25));
    //==========Box2========================================
    addItem(p,lblBox2,2,2,1,1,GridBagConstraints.WEST);
    addItem(p,txtBox2,3,2,1,1,GridBagConstraints.CENTER);
    txtBox2.setPreferredSize(new Dimension(80,25));
    //==========Box3========================================
    addItem(p,lblBox3,3,3,1,1,GridBagConstraints.WEST);
    addItem(p,txtBox3,3,4,1,1,GridBagConstraints.CENTER);
    txtBox3.setPreferredSize(new Dimension(80,25));
    //=======================================================

    //==========MooFullName==================================
    addItem(p,lblMooFullName,3,16,1,1,GridBagConstraints.WEST);
    addItem(p,txtMooFullName,3,17,1,1,GridBagConstraints.CENTER);
    txtMooFullName.setPreferredSize(new Dimension(80,25));
    //=======================================================

    //==========MoneyAccess=================================
    addItem(p,lblMoneyAccess,2,11,1,1,GridBagConstraints.WEST);
    addItem(p,txtMoneyAccess,3,11,1,1,GridBagConstraints.CENTER);
    txtMoneyAccess.setPreferredSize(new Dimension(80,25));
    //======================================================

    //==========MoneyAids===================================
    addItem(p,lblMoneyAids,2,12,1,1,GridBagConstraints.WEST);
    addItem(p,txtMoneyAids,3,12,1,1,GridBagConstraints.CENTER);
    txtMoneyAids.setPreferredSize(new Dimension(80,25));
    //======================================================

    f.add(p);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(690, 700);
    f.setResizable(false);//ไม่ให้ Resize
    f.setVisible(true);
    f.setLocationRelativeTo(null);//center
    }
    }
     

    ไฟล์ที่แนบมา:

    • 2.png
      2.png
      ขนาดไฟล์:
      171.8 KB
      เปิดดู:
      81
    แก้ไขครั้งล่าสุดโดยผู้ดูแล: 14 มิถุนายน 2015
  13. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    เวลานำไปใช้กับเครื่องอื่น Box ต่าง ๆ ไม่ต้องมาจัดใหม่
     
  14. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    อีกแบบ GridBagLayout
    ==================
    MyOlderGridBagLayout.java

    ==================
    package main;

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;

    public class MyOlderGridBagLayout extends JFrame{

    Connection connect;
    PreparedStatement pstmt;
    ResultSet rs;
    JPanel p;

    JButton btnGenID,btnAdd,btnEdit,btnDelete,btnRefresh,btnSearch;
    JTextField txtCodePK,txtCodeID,txtSearch;

    public MyOlderGridBagLayout(String title){
    super(title);
    p = new JPanel();
    p.setLayout(new GridBagLayout());

    JLabel lblCodePK,lblSexFK,lblTitleFK,lblFirstName,lblLastName,lblIDCard;
    JLabel lblBirthDate,lblBanID,lblMoo,lblTypeNameFK,lblAccessFK;
    JLabel lblLevelAccess,lblExpireDate,lblMoneyAccess,lblMoneyAids;
    JLabel lblGetMoneyFK,lblMethodMoneyFK,lblBankFK,lblBancee,lblSearch;
    JLabel lblCaretakerF,lblCaretakerL,lblBox1,lblBox2,lblBox3,lblMooFullName;
    JLabel lblFirstNameAcc,lblLastNameAcc,lblMooAcc;
    JTextField txtFirstName,txtLastName,txtIDCard;
    JTextField txtBirthDate,txtBanID,txtMoo,txtLevelAccess,txtExpireDate;
    JTextField txtMoneyAccess,txtMoneyAids,txtBancee;
    JTextField txtCaretakerF,txtCaretakerL,txtBox1,txtBox2,txtBox3,txtMooFullName;
    JTextField txtFirstNameAcc,txtLastNameAcc,txtMooAcc;

    lblCodePK = new JLabel("ลำดับที่ :");
    lblSexFK = new JLabel("เพศ :");
    lblTitleFK = new JLabel("คำนำหน้า :");
    lblFirstName = new JLabel("ชื่อ :");
    lblLastName = new JLabel("สกุล :");
    lblIDCard = new JLabel("เลขบัตรประชาชน :");
    lblBirthDate = new JLabel("ปี-เดือน-วัน เกิด(คศ.) :");
    lblBanID = new JLabel("บ้านเลขที่ :");
    lblMoo = new JLabel("หมู่ที่ :");
    lblTypeNameFK = new JLabel("ประเภทของผู้มีสิทธิ์ :");
    lblAccessFK = new JLabel("คุณสมบัติของคนพิการ :");
    lblExpireDate = new JLabel("บัตรคนพิการหมดอายุ:");
    lblLevelAccess = new JLabel("ระดับความพิการ :");
    lblMoneyAccess = new JLabel("เงินคนพิการ(บาท) :");
    lblMoneyAids = new JLabel("เงินผู้ติดเชื้อเอดส์(บาท) :");
    lblGetMoneyFK = new JLabel("ประเภทงบประมาณ :");
    lblMethodMoneyFK = new JLabel("วิธีขอรับเงิน :");
    lblBankFK = new JLabel("ชื่อธนาคาร :");
    lblBancee = new JLabel("เลขที่บัญชีธนาคาร :");
    lblCaretakerF = new JLabel("ชื่อ อผส. :");
    lblCaretakerL = new JLabel("สกุล อผส. :");
    lblBox1 = new JLabel("ปีงบประมาณรับเบี้ย ผส.");
    lblBox2 = new JLabel("ปีงบประมาณรับเบี้ย พก.");
    lblBox3 = new JLabel("ปีงบรับเบี้ยAids");
    lblMooFullName = new JLabel("หมู่ที่ อผส.");
    lblSearch = new JLabel("ค้นหาลำดับที่ :");
    lblFirstNameAcc = new JLabel("ชื่อ พก. :");
    lblLastNameAcc = new JLabel("สกุล พก. :");
    lblMooAcc = new JLabel("หมู่ที่ พก. :");

    txtCodePK = new JTextField(11);txtCodePK.setBackground(Color.white);
    txtCodeID = new JTextField(11);txtCodeID.setBackground(Color.white);
    txtFirstName = new JTextField(24);
    txtLastName = new JTextField(24);
    txtIDCard = new JTextField(24);
    txtBirthDate = new JTextField(11);txtBirthDate.setBackground(Color.pink);
    txtBanID = new JTextField(11);
    txtMoo = new JTextField(11);
    txtLevelAccess = new JTextField(11);
    txtExpireDate = new JTextField(11);txtExpireDate.setBackground(Color.pink);
    txtMoneyAccess = new JTextField(8);
    txtMoneyAids = new JTextField(8);
    txtBancee = new JTextField(24);
    txtCaretakerF = new JTextField(24);
    txtCaretakerL = new JTextField(24);
    txtBox1 = new JTextField(8);
    txtBox2 = new JTextField(8);
    txtBox3 = new JTextField(8);
    txtMooFullName = new JTextField(8);
    txtSearch = new JTextField(8);
    txtSearch.setBackground(Color.yellow);//Tab txtSearch Color YELLOW
    txtFirstNameAcc = new JTextField(11);
    txtLastNameAcc = new JTextField(8);
    txtMooAcc = new JTextField(11);
    //========ดูเดือน ก.พ.มี 28 หรือ 29 วัน==========
    //เอา คศ % 4 = 0 คือ มี 29 วัน
    //return ((($year % 4) == 0) && ((($year % 100) != 0) || (($year %400) == 0)));

    //=======ComboBox Sex=======================
    String SexFK[] = {"ชาย","หญิง"};
    JComboBox cmbSexFK = new JComboBox(SexFK);
    //==========================================

    //=======ComboBox Title=====================
    String TitleFK[] = {"นาย","นาง","นางสาว","เด็กชาย","เด็กหญิง","พระ","แม่ชี"};
    JComboBox cmbTitleFK = new JComboBox(TitleFK);
    //==========================================

    //=======ComboBox TypeNameFK================
    String TypeNameFK[] = {"ผู้สูงอายุ","ความพิการ","ผู้ติดเชื้อเอดส์","ผู้สูงอายุและความพิการ",
    "ผู้สูงอายุและผู้ติดเชื้อเอดส์","ความพิการและผู้ติดเชื้อเอดส์","ผู้สูงอายุความพิการผู้ติดเชื้อเอดส์",
    "มีเงินเดือน","พระมีเงินเดือนและความพิการ"};
    JComboBox cmbTypeNameFK = new JComboBox(TypeNameFK);
    //==========================================

    //=======ComboBox AccessFK==================
    String AccessFK[] = {"ไม่ระบุ","ความพิการทางการมองเห็น","ความพิการทางการได้ยิน","ความพิการทางการเคลื่อนไหว",
    "ความพิการทางการจิตใจหรือพฤติกรรม","ความพิการทางสติปัญญา","ความพิการทางการเรียนรู้",
    "ความพิการทางออทิสติก","ความพิการทางซ้ำซ้อน"};
    JComboBox cmbAccessFK = new JComboBox(AccessFK);
    //=======ComboBox GetMoneyFK================
    String GetMoneyFK[] = {"ไม่ระบุ","งบทั่วไป","งบอุดหนุนทั่วไปกำหนดวัตถุประสงค์","งบ อปท.จ่ายเอง"};
    JComboBox cmbGetMoneyFK = new JComboBox(GetMoneyFK);
    //=======ComboBox MethodMoney===============
    String MethodMoneyFK[] = {"ไม่ระบุ","รับเงินสด","โอนเข้าบัญชี"};
    JComboBox cmbMethodMoneyFK = new JComboBox(MethodMoneyFK);
    //=======ComboBox Bank======================
    String BankFK[] = {"ไม่ระบุ","กรุงไทย","กรุงศรีอยุธยา","กสิกรไทย","เกียรตินาคิน",
    "ทหารไทย","ไทยพาณิชย์","ธกส.","ธนชาติ","ออมสิน"};
    JComboBox cmbBankFK = new JComboBox(BankFK);
    //==========================================

    //==========Button==========================
    btnGenID = new JButton("GenID");
    btnAdd = new JButton("เพิ่มข้อมูล");
    btnEdit = new JButton("แก้ไขข้อมูล");
    btnDelete = new JButton("ลบข้อมูล");
    btnRefresh = new JButton("รีเฟรซข้อมูล");
    btnSearch = new JButton("ค้นหา");

    AddPanel x = new AddPanel();
    //=========GenID===========================
    x.addItem(p,btnGenID,3,0,1,1,GridBagConstraints.CENTER);
    btnGenID.setPreferredSize(new Dimension(90,25));
    //=========Add=============================
    x.addItem(p,btnAdd,4,0,1,1,GridBagConstraints.CENTER);
    btnAdd.setPreferredSize(new Dimension(120,25));
    //=========Edit============================
    x.addItem(p,btnEdit,4,1,2,1,GridBagConstraints.CENTER);
    btnEdit.setPreferredSize(new Dimension(120,25));
    //=========Delete==========================
    x.addItem(p,btnDelete,4,2,2,1,GridBagConstraints.CENTER);
    btnDelete.setPreferredSize(new Dimension(120,25));
    //=========Refresh=========================
    x.addItem(p,btnRefresh,4,3,2,1,GridBagConstraints.CENTER);
    btnRefresh.setPreferredSize(new Dimension(120,25));
    //=========btnSearch=======================
    x.addItem(p,btnSearch,4,10,2,1,GridBagConstraints.CENTER);
    btnSearch.setPreferredSize(new Dimension(120,25));
    //=========================================
    //คอลัมท์ แถว กว้าง สูง
    //==========CodePK=====================================
    x.addItem(p,lblCodePK,0,0,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtCodePK,1,0,1,1,GridBagConstraints.CENTER);
    txtCodePK.setPreferredSize(new Dimension(20,25));
    //=====================================================

    //=========CodeID======================================
    x.addItem(p,txtCodeID,2,0,1,1,GridBagConstraints.CENTER);
    txtCodeID.setPreferredSize(new Dimension(20,25));
    //=====================================================

    //=========cmbSex======================================
    x.addItem(p,lblSexFK,0,1,1,1,GridBagConstraints.WEST);
    x.addItem(p,cmbSexFK,1,1,1,1,GridBagConstraints.WEST);
    cmbSexFK.setPreferredSize(new Dimension(120,25));
    //=====================================================

    //=========cmbTitle====================================
    x.addItem(p,lblTitleFK,0,2,1,1,GridBagConstraints.WEST);
    x.addItem(p,cmbTitleFK,1,2,1,1,GridBagConstraints.WEST);
    cmbTitleFK.setPreferredSize(new Dimension(120,25));
    //=====================================================

    //=========FirstName===================================
    x.addItem(p,lblFirstName,0,3,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtFirstName,1,3,2,1,GridBagConstraints.CENTER);
    txtFirstName.setPreferredSize(new Dimension(30,25));
    //=====================================================

    //========LastName=====================================
    x.addItem(p,lblLastName,0,4,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtLastName,1,4,2,1,GridBagConstraints.CENTER);
    txtLastName.setPreferredSize(new Dimension(30,25));
    //=====================================================

    //========IDCard=======================================
    x.addItem(p,lblIDCard,0,5,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtIDCard,1,5,2,1,GridBagConstraints.CENTER);
    txtIDCard.setPreferredSize(new Dimension(20,25));
    //=====================================================

    //==========BirthDate===================================
    x.addItem(p,lblBirthDate,0,6,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtBirthDate,1,6,1,1,GridBagConstraints.CENTER);
    txtBirthDate.setPreferredSize(new Dimension(20,25));
    //======================================================

    //==========BanID=======================================
    x.addItem(p,lblBanID,0,7,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtBanID,1,7,1,1,GridBagConstraints.CENTER);
    txtBanID.setPreferredSize(new Dimension(20,25));
    //======================================================

    //==========Moo=========================================
    x.addItem(p,lblMoo,0,8,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtMoo,1,8,1,1,GridBagConstraints.CENTER);
    txtMoo.setPreferredSize(new Dimension(20,25));
    //======================================================

    //==========cmdTypeNameFK===============================
    x.addItem(p,lblTypeNameFK,0,9,1,1,GridBagConstraints.WEST);
    x.addItem(p,cmbTypeNameFK,1,9,2,1,GridBagConstraints.CENTER);
    cmbTypeNameFK.setPreferredSize(new Dimension(270,25));
    //======================================================

    //==========cmdAccessFK=================================
    x.addItem(p,lblAccessFK,0,10,1,1,GridBagConstraints.WEST);
    x.addItem(p,cmbAccessFK,1,10,2,1,GridBagConstraints.CENTER);
    cmbAccessFK.setPreferredSize(new Dimension(270,25));
    //======================================================

    //==========LevelAccess=================================
    x.addItem(p,lblLevelAccess,0,11,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtLevelAccess,1,11,1,1,GridBagConstraints.CENTER);
    txtLevelAccess.setPreferredSize(new Dimension(20,25));
    //======================================================

    //==========ExpireDate Access===========================
    x.addItem(p,lblExpireDate,0,12,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtExpireDate,1,12,1,1,GridBagConstraints.CENTER);
    txtExpireDate.setPreferredSize(new Dimension(20,25));
    //======================================================

    //==========cmbGetMoneyFK================================
    x.addItem(p,lblGetMoneyFK,0,13,1,1,GridBagConstraints.WEST);
    x.addItem(p,cmbGetMoneyFK,1,13,2,1,GridBagConstraints.CENTER);
    cmbGetMoneyFK.setPreferredSize(new Dimension(270,25));
    //======================================================

    //==========cmbMethodMoneyFK============================
    x.addItem(p,lblMethodMoneyFK,0,14,1,1,GridBagConstraints.WEST);
    x.addItem(p,cmbMethodMoneyFK,1,14,1,1,GridBagConstraints.CENTER);
    cmbMethodMoneyFK.setPreferredSize(new Dimension(120,25));
    //======================================================

    //==========txtFirstNameAcc============================
    x.addItem(p,lblFirstNameAcc,2,14,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtFirstNameAcc,2,15,1,1,GridBagConstraints.CENTER);
    txtFirstNameAcc.setPreferredSize(new Dimension(20,25));
    //======================================================

    //==========txtLastNameAcc============================
    x.addItem(p,lblLastNameAcc,3,14,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtLastNameAcc,3,15,1,1,GridBagConstraints.CENTER);
    txtLastNameAcc.setPreferredSize(new Dimension(80,25));
    //======================================================

    //==========txtMooAcc============================
    x.addItem(p,lblMooAcc,4,14,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtMooAcc,4,15,1,1,GridBagConstraints.CENTER);
    txtMooAcc.setPreferredSize(new Dimension(120,25));
    //======================================================

    //==========cmbBankFK================================
    x.addItem(p,lblBankFK,0,15,1,1,GridBagConstraints.WEST);
    x.addItem(p,cmbBankFK,1,15,1,1,GridBagConstraints.CENTER);
    cmbBankFK.setPreferredSize(new Dimension(120,25));
    //======================================================

    //==========Bancee======================================
    x.addItem(p,lblBancee,0,16,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtBancee,1,16,2,1,GridBagConstraints.CENTER);
    txtBancee.setPreferredSize(new Dimension(120,25));
    //======================================================

    //==========CaretakerF==================================
    x.addItem(p,lblCaretakerF,0,17,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtCaretakerF,1,17,2,1,GridBagConstraints.CENTER);
    txtCaretakerF.setPreferredSize(new Dimension(120,25));
    //======================================================

    //==========CaretakerL==================================
    x.addItem(p,lblCaretakerL,0,18,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtCaretakerL,1,18,2,1,GridBagConstraints.CENTER);
    txtCaretakerL.setPreferredSize(new Dimension(120,25));
    //======================================================

    //==========Comment==================================
    //addItem(p,lblComment,0,19,1,1,GridBagConstraints.WEST);
    //addItem(p,txtComment,1,19,2,1,GridBagConstraints.CENTER);
    //txtComment.setPreferredSize(new Dimension(120,25));
    //===================================================

    //==========txtSearch==================================
    x.addItem(p,lblSearch,3,9,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtSearch,3,10,1,1,GridBagConstraints.CENTER);
    txtSearch.setPreferredSize(new Dimension(80,25));
    //=======================================================

    //==========Box1========================================
    x.addItem(p,lblBox1,2,1,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtBox1,3,1,1,1,GridBagConstraints.CENTER);
    txtBox1.setPreferredSize(new Dimension(80,25));
    //==========Box2========================================
    x.addItem(p,lblBox2,2,2,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtBox2,3,2,1,1,GridBagConstraints.CENTER);
    txtBox2.setPreferredSize(new Dimension(80,25));
    //==========Box3========================================
    x.addItem(p,lblBox3,3,3,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtBox3,3,4,1,1,GridBagConstraints.CENTER);
    txtBox3.setPreferredSize(new Dimension(80,25));
    //=======================================================

    //==========MooFullName==================================
    x.addItem(p,lblMooFullName,3,16,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtMooFullName,3,17,1,1,GridBagConstraints.CENTER);
    txtMooFullName.setPreferredSize(new Dimension(80,25));
    //=======================================================

    //==========MoneyAccess=================================
    x.addItem(p,lblMoneyAccess,2,11,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtMoneyAccess,3,11,1,1,GridBagConstraints.CENTER);
    txtMoneyAccess.setPreferredSize(new Dimension(80,25));
    //======================================================

    //==========MoneyAids===================================
    x.addItem(p,lblMoneyAids,2,12,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtMoneyAids,3,12,1,1,GridBagConstraints.CENTER);
    txtMoneyAids.setPreferredSize(new Dimension(80,25));
    //======================================================

    //=========Command Button===============================
    btnGenID.addActionListener(new ButtonListener());//เมื่อ Click ปุ่ม btnGenID

    //======================================================

    add(p);
    }

    public static void main(String[] args) {
    MyOlderGridBagLayout f = new MyOlderGridBagLayout("โปรแกรมจ่ายเบี้ยยังชีพ My Older V.2015 R.1 ( Java Open Source::Database MariaDB )");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(690, 700);
    f.setResizable(false);//ไม่ให้ Resize
    f.setVisible(true);
    f.setLocationRelativeTo(null);//center
    }

    private class ButtonListener implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent ae) {
    Object source = ae.getSource();
    if(source == btnGenID){
    try{
    Class.forName("org.mariadb.jdbc.Driver");//เปลี่ยนแค่ com ==> org
    connect = DriverManager.getConnection("jdbc:mariadb://localhost/dbolder" +
    "?user=root&password=gomplayer");
    String sql = "SELECT max(CodePK) FROM tblolder";
    pstmt = connect.prepareStatement(sql);
    rs = pstmt.executeQuery();

    if (rs.next()) {
    int maxID = rs.getInt(1)+1;

    txtCodePK.setText(String.valueOf(maxID));
    String paded = String.format("%7s",String.valueOf(maxID)).replace(' ', '0');
    txtCodeID.setText(paded);
    //==========ปิดปุ่มและ textBox====================
    btnGenID.setEnabled(false);
    btnAdd.setEnabled(true);
    btnEdit.setEnabled(false);
    btnDelete.setEnabled(false);
    btnSearch.setEnabled(false);
    txtSearch.setEnabled(false);
    txtCodePK.setEnabled(false);
    txtCodeID.setEnabled(false);
    //=============================================
    }
    }catch(ClassNotFoundException | SQLException ex){
    JOptionPane.showMessageDialog(null,"Error GenID Auto !\n"+ex.getMessage());
    }
    }
    }
    }
    }
     
  15. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    AddPanel.java
    =====================
    package main;

    import java.awt.GridBagConstraints;
    import java.awt.Insets;
    import javax.swing.JComponent;
    import javax.swing.JPanel;

    public class AddPanel {
    void addItem(JPanel p,JComponent c,int x,int y,int width,int height,int align){
    GridBagConstraints gc = new GridBagConstraints();
    gc.gridx = x;
    gc.gridy = y;
    gc.gridwidth = width;
    gc.gridheight = height;
    gc.insets = new Insets(5,5,5,5);
    gc.anchor = align;
    gc.fill = GridBagConstraints.NONE;
    p.add(c,gc);
    }//addItem
    }
     

    ไฟล์ที่แนบมา:

    • 3.png
      3.png
      ขนาดไฟล์:
      145.9 KB
      เปิดดู:
      62
    • 4.png
      4.png
      ขนาดไฟล์:
      170.3 KB
      เปิดดู:
      63
  16. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    เมื่อได้คำสั่ง btnGenID แล้วมาเพิ่ม btnRefresh
    =========================
     
  17. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    package main;

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;

    public class MyOlderGridBagLayout extends JFrame{

    Connection connect;
    PreparedStatement pstmt;
    ResultSet rs;
    JPanel p;

    JButton btnGenID,btnAdd,btnEdit,btnDelete,btnRefresh,btnSearch;
    JTextField txtCodePK,txtCodeID,txtSearch;
    JComboBox cmbSexFK,cmbTitleFK;

    public MyOlderGridBagLayout(String title){
    super(title);
    p = new JPanel();
    p.setLayout(new GridBagLayout());

    JLabel lblCodePK,lblSexFK,lblTitleFK,lblFirstName,lblLastName,lblIDCard;
    JLabel lblBirthDate,lblBanID,lblMoo,lblTypeNameFK,lblAccessFK;
    JLabel lblLevelAccess,lblExpireDate,lblMoneyAccess,lblMoneyAids;
    JLabel lblGetMoneyFK,lblMethodMoneyFK,lblBankFK,lblBancee,lblSearch;
    JLabel lblCaretakerF,lblCaretakerL,lblBox1,lblBox2,lblBox3,lblMooFullName;
    JLabel lblFirstNameAcc,lblLastNameAcc,lblMooAcc;
    JTextField txtFirstName,txtLastName,txtIDCard;
    JTextField txtBirthDate,txtBanID,txtMoo,txtLevelAccess,txtExpireDate;
    JTextField txtMoneyAccess,txtMoneyAids,txtBancee;
    JTextField txtCaretakerF,txtCaretakerL,txtBox1,txtBox2,txtBox3,txtMooFullName;
    JTextField txtFirstNameAcc,txtLastNameAcc,txtMooAcc;

    lblCodePK = new JLabel("ลำดับที่ :");
    lblSexFK = new JLabel("เพศ :");
    lblTitleFK = new JLabel("คำนำหน้า :");
    lblFirstName = new JLabel("ชื่อ :");
    lblLastName = new JLabel("สกุล :");
    lblIDCard = new JLabel("เลขบัตรประชาชน :");
    lblBirthDate = new JLabel("ปี-เดือน-วัน เกิด(คศ.) :");
    lblBanID = new JLabel("บ้านเลขที่ :");
    lblMoo = new JLabel("หมู่ที่ :");
    lblTypeNameFK = new JLabel("ประเภทของผู้มีสิทธิ์ :");
    lblAccessFK = new JLabel("คุณสมบัติของคนพิการ :");
    lblExpireDate = new JLabel("บัตรคนพิการหมดอายุ:");
    lblLevelAccess = new JLabel("ระดับความพิการ :");
    lblMoneyAccess = new JLabel("เงินคนพิการ(บาท) :");
    lblMoneyAids = new JLabel("เงินผู้ติดเชื้อเอดส์(บาท) :");
    lblGetMoneyFK = new JLabel("ประเภทงบประมาณ :");
    lblMethodMoneyFK = new JLabel("วิธีขอรับเงิน :");
    lblBankFK = new JLabel("ชื่อธนาคาร :");
    lblBancee = new JLabel("เลขที่บัญชีธนาคาร :");
    lblCaretakerF = new JLabel("ชื่อ อผส. :");
    lblCaretakerL = new JLabel("สกุล อผส. :");
    lblBox1 = new JLabel("ปีงบประมาณรับเบี้ย ผส.");
    lblBox2 = new JLabel("ปีงบประมาณรับเบี้ย พก.");
    lblBox3 = new JLabel("ปีงบรับเบี้ยAids");
    lblMooFullName = new JLabel("หมู่ที่ อผส.");
    lblSearch = new JLabel("ค้นหาลำดับที่ :");
    lblFirstNameAcc = new JLabel("ชื่อ พก. :");
    lblLastNameAcc = new JLabel("สกุล พก. :");
    lblMooAcc = new JLabel("หมู่ที่ พก. :");

    txtCodePK = new JTextField(11);txtCodePK.setBackground(Color.white);
    txtCodeID = new JTextField(11);txtCodeID.setBackground(Color.white);
    txtFirstName = new JTextField(24);
    txtLastName = new JTextField(24);
    txtIDCard = new JTextField(24);
    txtBirthDate = new JTextField(11);txtBirthDate.setBackground(Color.pink);
    txtBanID = new JTextField(11);
    txtMoo = new JTextField(11);
    txtLevelAccess = new JTextField(11);
    txtExpireDate = new JTextField(11);txtExpireDate.setBackground(Color.pink);
    txtMoneyAccess = new JTextField(8);
    txtMoneyAids = new JTextField(8);
    txtBancee = new JTextField(24);
    txtCaretakerF = new JTextField(24);
    txtCaretakerL = new JTextField(24);
    txtBox1 = new JTextField(8);
    txtBox2 = new JTextField(8);
    txtBox3 = new JTextField(8);
    txtMooFullName = new JTextField(8);
    txtSearch = new JTextField(8);
    txtSearch.setBackground(Color.yellow);//Tab txtSearch Color YELLOW
    txtFirstNameAcc = new JTextField(11);
    txtLastNameAcc = new JTextField(8);
    txtMooAcc = new JTextField(11);
    //========ดูเดือน ก.พ.มี 28 หรือ 29 วัน==========
    //เอา คศ % 4 = 0 คือ มี 29 วัน
    //return ((($year % 4) == 0) && ((($year % 100) != 0) || (($year %400) == 0)));

    //=======ComboBox Sex=======================
    String SexFK[] = {"ชาย","หญิง"};
    cmbSexFK = new JComboBox(SexFK);
    //==========================================

    //=======ComboBox Title=====================
    String TitleFK[] = {"นาย","นาง","นางสาว","เด็กชาย","เด็กหญิง","พระ","แม่ชี"};
    cmbTitleFK = new JComboBox(TitleFK);
    //==========================================

    //=======ComboBox TypeNameFK================
    String TypeNameFK[] = {"ผู้สูงอายุ","ความพิการ","ผู้ติดเชื้อเอดส์","ผู้สูงอายุและความพิการ",
    "ผู้สูงอายุและผู้ติดเชื้อเอดส์","ความพิการและผู้ติดเชื้อเอดส์","ผู้สูงอายุความพิการผู้ติดเชื้อเอดส์",
    "มีเงินเดือน","พระมีเงินเดือนและความพิการ"};
    JComboBox cmbTypeNameFK = new JComboBox(TypeNameFK);
    //==========================================

    //=======ComboBox AccessFK==================
    String AccessFK[] = {"ไม่ระบุ","ความพิการทางการมองเห็น","ความพิการทางการได้ยิน","ความพิการทางการเคลื่อนไหว",
    "ความพิการทางการจิตใจหรือพฤติกรรม","ความพิการทางสติปัญญา","ความพิการทางการเรียนรู้",
    "ความพิการทางออทิสติก","ความพิการทางซ้ำซ้อน"};
    JComboBox cmbAccessFK = new JComboBox(AccessFK);
    //=======ComboBox GetMoneyFK================
    String GetMoneyFK[] = {"ไม่ระบุ","งบทั่วไป","งบอุดหนุนทั่วไปกำหนดวัตถุประสงค์","งบ อปท.จ่ายเอง"};
    JComboBox cmbGetMoneyFK = new JComboBox(GetMoneyFK);
    //=======ComboBox MethodMoney===============
    String MethodMoneyFK[] = {"ไม่ระบุ","รับเงินสด","โอนเข้าบัญชี"};
    JComboBox cmbMethodMoneyFK = new JComboBox(MethodMoneyFK);
    //=======ComboBox Bank======================
    String BankFK[] = {"ไม่ระบุ","กรุงไทย","กรุงศรีอยุธยา","กสิกรไทย","เกียรตินาคิน",
    "ทหารไทย","ไทยพาณิชย์","ธกส.","ธนชาติ","ออมสิน"};
    JComboBox cmbBankFK = new JComboBox(BankFK);
    //==========================================

    //==========Button==========================
    btnGenID = new JButton("GenID");
    btnAdd = new JButton("เพิ่มข้อมูล");
    btnEdit = new JButton("แก้ไขข้อมูล");
    btnDelete = new JButton("ลบข้อมูล");
    btnRefresh = new JButton("รีเฟรซข้อมูล");
    btnSearch = new JButton("ค้นหา");

    AddPanel x = new AddPanel();
    //=========GenID===========================
    x.addItem(p,btnGenID,3,0,1,1,GridBagConstraints.CENTER);
    btnGenID.setPreferredSize(new Dimension(90,25));
    //=========Add=============================
    x.addItem(p,btnAdd,4,0,1,1,GridBagConstraints.CENTER);
    btnAdd.setPreferredSize(new Dimension(120,25));
    //=========Edit============================
    x.addItem(p,btnEdit,4,1,2,1,GridBagConstraints.CENTER);
    btnEdit.setPreferredSize(new Dimension(120,25));
    //=========Delete==========================
    x.addItem(p,btnDelete,4,2,2,1,GridBagConstraints.CENTER);
    btnDelete.setPreferredSize(new Dimension(120,25));
    //=========Refresh=========================
    x.addItem(p,btnRefresh,4,3,2,1,GridBagConstraints.CENTER);
    btnRefresh.setPreferredSize(new Dimension(120,25));
    //=========btnSearch=======================
    x.addItem(p,btnSearch,4,10,2,1,GridBagConstraints.CENTER);
    btnSearch.setPreferredSize(new Dimension(120,25));
    //=========================================
    //คอลัมท์ แถว กว้าง สูง
    //==========CodePK=====================================
    x.addItem(p,lblCodePK,0,0,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtCodePK,1,0,1,1,GridBagConstraints.CENTER);
    txtCodePK.setPreferredSize(new Dimension(20,25));
    //=====================================================

    //=========CodeID======================================
    x.addItem(p,txtCodeID,2,0,1,1,GridBagConstraints.CENTER);
    txtCodeID.setPreferredSize(new Dimension(20,25));
    //=====================================================

    //=========cmbSex======================================
    x.addItem(p,lblSexFK,0,1,1,1,GridBagConstraints.WEST);
    x.addItem(p,cmbSexFK,1,1,1,1,GridBagConstraints.WEST);
    cmbSexFK.setPreferredSize(new Dimension(120,25));
    //=====================================================

    //=========cmbTitle====================================
    x.addItem(p,lblTitleFK,0,2,1,1,GridBagConstraints.WEST);
    x.addItem(p,cmbTitleFK,1,2,1,1,GridBagConstraints.WEST);
    cmbTitleFK.setPreferredSize(new Dimension(120,25));
    //=====================================================

    //=========FirstName===================================
    x.addItem(p,lblFirstName,0,3,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtFirstName,1,3,2,1,GridBagConstraints.CENTER);
    txtFirstName.setPreferredSize(new Dimension(30,25));
    //=====================================================

    //========LastName=====================================
    x.addItem(p,lblLastName,0,4,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtLastName,1,4,2,1,GridBagConstraints.CENTER);
    txtLastName.setPreferredSize(new Dimension(30,25));
    //=====================================================

    //========IDCard=======================================
    x.addItem(p,lblIDCard,0,5,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtIDCard,1,5,2,1,GridBagConstraints.CENTER);
    txtIDCard.setPreferredSize(new Dimension(20,25));
    //=====================================================

    //==========BirthDate===================================
    x.addItem(p,lblBirthDate,0,6,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtBirthDate,1,6,1,1,GridBagConstraints.CENTER);
    txtBirthDate.setPreferredSize(new Dimension(20,25));
    //======================================================

    //==========BanID=======================================
    x.addItem(p,lblBanID,0,7,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtBanID,1,7,1,1,GridBagConstraints.CENTER);
    txtBanID.setPreferredSize(new Dimension(20,25));
    //======================================================

    //==========Moo=========================================
    x.addItem(p,lblMoo,0,8,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtMoo,1,8,1,1,GridBagConstraints.CENTER);
    txtMoo.setPreferredSize(new Dimension(20,25));
    //======================================================

    //==========cmdTypeNameFK===============================
    x.addItem(p,lblTypeNameFK,0,9,1,1,GridBagConstraints.WEST);
    x.addItem(p,cmbTypeNameFK,1,9,2,1,GridBagConstraints.CENTER);
    cmbTypeNameFK.setPreferredSize(new Dimension(270,25));
    //======================================================

    //==========cmdAccessFK=================================
    x.addItem(p,lblAccessFK,0,10,1,1,GridBagConstraints.WEST);
    x.addItem(p,cmbAccessFK,1,10,2,1,GridBagConstraints.CENTER);
    cmbAccessFK.setPreferredSize(new Dimension(270,25));
    //======================================================

    //==========LevelAccess=================================
    x.addItem(p,lblLevelAccess,0,11,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtLevelAccess,1,11,1,1,GridBagConstraints.CENTER);
    txtLevelAccess.setPreferredSize(new Dimension(20,25));
    //======================================================

    //==========ExpireDate Access===========================
    x.addItem(p,lblExpireDate,0,12,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtExpireDate,1,12,1,1,GridBagConstraints.CENTER);
    txtExpireDate.setPreferredSize(new Dimension(20,25));
    //======================================================

    //==========cmbGetMoneyFK================================
    x.addItem(p,lblGetMoneyFK,0,13,1,1,GridBagConstraints.WEST);
    x.addItem(p,cmbGetMoneyFK,1,13,2,1,GridBagConstraints.CENTER);
    cmbGetMoneyFK.setPreferredSize(new Dimension(270,25));
    //======================================================

    //==========cmbMethodMoneyFK============================
    x.addItem(p,lblMethodMoneyFK,0,14,1,1,GridBagConstraints.WEST);
    x.addItem(p,cmbMethodMoneyFK,1,14,1,1,GridBagConstraints.CENTER);
    cmbMethodMoneyFK.setPreferredSize(new Dimension(120,25));
    //======================================================

    //==========txtFirstNameAcc============================
    x.addItem(p,lblFirstNameAcc,2,14,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtFirstNameAcc,2,15,1,1,GridBagConstraints.CENTER);
    txtFirstNameAcc.setPreferredSize(new Dimension(20,25));
    //======================================================

    //==========txtLastNameAcc============================
    x.addItem(p,lblLastNameAcc,3,14,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtLastNameAcc,3,15,1,1,GridBagConstraints.CENTER);
    txtLastNameAcc.setPreferredSize(new Dimension(80,25));
    //======================================================

    //==========txtMooAcc============================
    x.addItem(p,lblMooAcc,4,14,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtMooAcc,4,15,1,1,GridBagConstraints.CENTER);
    txtMooAcc.setPreferredSize(new Dimension(120,25));
    //======================================================

    //==========cmbBankFK================================
    x.addItem(p,lblBankFK,0,15,1,1,GridBagConstraints.WEST);
    x.addItem(p,cmbBankFK,1,15,1,1,GridBagConstraints.CENTER);
    cmbBankFK.setPreferredSize(new Dimension(120,25));
    //======================================================

    //==========Bancee======================================
    x.addItem(p,lblBancee,0,16,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtBancee,1,16,2,1,GridBagConstraints.CENTER);
    txtBancee.setPreferredSize(new Dimension(120,25));
    //======================================================

    //==========CaretakerF==================================
    x.addItem(p,lblCaretakerF,0,17,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtCaretakerF,1,17,2,1,GridBagConstraints.CENTER);
    txtCaretakerF.setPreferredSize(new Dimension(120,25));
    //======================================================

    //==========CaretakerL==================================
    x.addItem(p,lblCaretakerL,0,18,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtCaretakerL,1,18,2,1,GridBagConstraints.CENTER);
    txtCaretakerL.setPreferredSize(new Dimension(120,25));
    //======================================================

    //==========Comment==================================
    //addItem(p,lblComment,0,19,1,1,GridBagConstraints.WEST);
    //addItem(p,txtComment,1,19,2,1,GridBagConstraints.CENTER);
    //txtComment.setPreferredSize(new Dimension(120,25));
    //===================================================

    //==========txtSearch==================================
    x.addItem(p,lblSearch,3,9,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtSearch,3,10,1,1,GridBagConstraints.CENTER);
    txtSearch.setPreferredSize(new Dimension(80,25));
    //=======================================================

    //==========Box1========================================
    x.addItem(p,lblBox1,2,1,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtBox1,3,1,1,1,GridBagConstraints.CENTER);
    txtBox1.setPreferredSize(new Dimension(80,25));
    //==========Box2========================================
    x.addItem(p,lblBox2,2,2,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtBox2,3,2,1,1,GridBagConstraints.CENTER);
    txtBox2.setPreferredSize(new Dimension(80,25));
    //==========Box3========================================
    x.addItem(p,lblBox3,3,3,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtBox3,3,4,1,1,GridBagConstraints.CENTER);
    txtBox3.setPreferredSize(new Dimension(80,25));
    //=======================================================

    //==========MooFullName==================================
    x.addItem(p,lblMooFullName,3,16,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtMooFullName,3,17,1,1,GridBagConstraints.CENTER);
    txtMooFullName.setPreferredSize(new Dimension(80,25));
    //=======================================================

    //==========MoneyAccess=================================
    x.addItem(p,lblMoneyAccess,2,11,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtMoneyAccess,3,11,1,1,GridBagConstraints.CENTER);
    txtMoneyAccess.setPreferredSize(new Dimension(80,25));
    //======================================================

    //==========MoneyAids===================================
    x.addItem(p,lblMoneyAids,2,12,1,1,GridBagConstraints.WEST);
    x.addItem(p,txtMoneyAids,3,12,1,1,GridBagConstraints.CENTER);
    txtMoneyAids.setPreferredSize(new Dimension(80,25));
    //======================================================

    //=========Command Button===============================
    btnGenID.addActionListener(new ButtonListener());//เมื่อ Click ปุ่ม btnGenID
    btnRefresh.addActionListener(new ButtonListener());//เมื่อ Click ปุ่ม btnRefresh
    //======================================================

    add(p);
    }

    public static void main(String[] args) {
    MyOlderGridBagLayout f = new MyOlderGridBagLayout("โปรแกรมจ่ายเบี้ยยังชีพ My Older V.2015 R.1 ( Java Open Source::Database MariaDB )");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(690, 700);
    f.setResizable(false);//ไม่ให้ Resize
    f.setVisible(true);
    f.setLocationRelativeTo(null);//center
    }

    private class ButtonListener implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent ae) {
    Object source = ae.getSource();
    if(source == btnGenID){
    try{
    Class.forName("org.mariadb.jdbc.Driver");//เปลี่ยนแค่ com ==> org
    connect = DriverManager.getConnection("jdbc:mariadb://localhost/dbolder" +
    "?user=root&password=gomplayer");
    String sql = "SELECT max(CodePK) FROM tblolder";
    pstmt = connect.prepareStatement(sql);
    rs = pstmt.executeQuery();

    if (rs.next()) {
    int maxID = rs.getInt(1)+1;

    txtCodePK.setText(String.valueOf(maxID));
    String paded = String.format("%7s",String.valueOf(maxID)).replace(' ', '0');
    txtCodeID.setText(paded);
    //==========ปิดปุ่มและ textBox====================
    btnGenID.setEnabled(false);
    btnAdd.setEnabled(true);
    btnEdit.setEnabled(false);
    btnDelete.setEnabled(false);
    btnSearch.setEnabled(false);
    txtSearch.setEnabled(false);
    txtCodePK.setEnabled(false);
    txtCodeID.setEnabled(false);
    //=============================================
    }
    }catch(ClassNotFoundException | SQLException ex){
    JOptionPane.showMessageDialog(null,"Error GenID Auto !\n"+ex.getMessage());
    }
    }
    if(source == btnRefresh){
    try{
    txtCodePK.setText("");
    txtCodeID.setText("");
    cmbSexFK.setSelectedItem(null);
    cmbTitleFK.setSelectedItem(null);

    txtSearch.setText("");

    //==========เปิดปุ่มและ textBox================
    btnGenID.setEnabled(true);
    btnAdd.setEnabled(true);
    btnEdit.setEnabled(true);
    btnDelete.setEnabled(true);
    btnSearch.setEnabled(true);
    txtSearch.setEnabled(true);
    txtCodePK.setEnabled(true);
    txtCodeID.setEnabled(true);
    //=========================================
    }catch(Exception e){
    JOptionPane.showMessageDialog(null, "Error Refresh Database !\n"+e.getMessage());
    }
    }
    }
    }
    }
     
  18. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    ต่อไปมาดูทาง SpringLayout แบบที่นิยมและง่ายต่อการออกแบบ
    =================================
    ใช้
    1.JDK 1.7 (NetBeans 7.3.1 Text Mode)
    2.jcalendar-1.4.jar
    3.mariadb-java-client-1.1.8.jar
     
    แก้ไขครั้งล่าสุดโดยผู้ดูแล: 15 มิถุนายน 2015
  19. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    FormAdd.java
    ============================
    เปลี่ยนวันที่ เป็น United States ครับ จึงจะใช้ปฏิทินแบบไม่มีปัญหา

    package main;

    import com.toedter.calendar.JDateChooser;
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.text.ParseException;
    import java.util.Date;
    import java.util.Locale;
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JTextField;
    import javax.swing.SpringLayout;

    public class FormAdd extends javax.swing.JInternalFrame{

    final JTextField txtCodePK,txtCodeID,txtFirstName,txtLastName,txtIDCard;
    final JTextField txtBanID,txtMoo,txtDiag,txtSearch,txtTambol,txtDistrict;
    final JTextField txtIntolerance;
    final JComboBox cmbSexFK,cmbTitleFK,cmbReport,cmbProvince;
    final JButton btnGenID,btnAdd,btnEdit,btnDelete,btnRefresh,btnSearch;
    final JDateChooser txtBirthDate,txtInspectionDate,txtDoctorDate;

    FormAdd(String เพิ่มรายการหลัก) throws ParseException{
    JFrame.setDefaultLookAndFeelDecorated(true);

    JFrame frame = new JFrame("เพิ่มข้อมูล / แแก้ไขข้อมูล / ลบข้อมูล / ค้นหาข้อมูล");

    Container contentPane = frame.getContentPane();
    SpringLayout layout = new SpringLayout();
    contentPane.setLayout(layout);

    //==========JLabel=========================
    JLabel lblCodePK = new JLabel("เลข HN : ");
    JLabel lblSexFK = new JLabel("เพศ : ");
    JLabel lblFirstName = new JLabel("ชื่อ : ");
    JLabel lblLastName = new JLabel("สกุล : ");
    JLabel lblIDCard = new JLabel("เลขบัตรประชาชน : ");
    JLabel lblBirthDate = new JLabel("เดือน วัน,ปี เกิด(คศ.) : ");
    JLabel lblBanID = new JLabel("บ้านเลขที่ :");
    JLabel lblMoo = new JLabel("หมู่ที่ :");
    JLabel lblTambol = new JLabel("ตำบล :");
    JLabel lblDistrict = new JLabel("อำเภอ :");
    JLabel lblProvince = new JLabel("จังหวัด :");
    JLabel lblDiag = new JLabel("อาการของโรค :");
    JLabel lblIntolerance = new JLabel("แพ้ยา :");
    JLabel lblInspectionDate = new JLabel("เดือน วัน,ปี(คศ.)ที่มาตรวจ :");
    JLabel lblReport = new JLabel("รายงาน :");
    JLabel lblDoctorDate = new JLabel("วันที่แพทย์นัด :");
    JLabel lblSearch = new JLabel("ค้นหาลำดับที่ :");

    //==========JTextField=====================
    txtCodePK = new JTextField("txtCodePK", 10);//txtCodePK.setBackground(Color.pink);
    txtCodeID = new JTextField("txtCodeID", 9);//txtCodeID.setBackground(Color.pink);
    txtFirstName = new JTextField("txtFirstName", 22);
    txtLastName = new JTextField("txtLastName", 22);
    txtIDCard = new JTextField("txtIDCard", 22);
    //================txtBirthDate======================
    Locale locale = new Locale ( "en", "US" );//new Locale ( "th", "TH" );
    txtBirthDate = new JDateChooser ( );
    txtBirthDate.setPreferredSize(new Dimension(216, 20));
    txtBirthDate.setLocale ( locale );
    Date date = new Date();
    txtBirthDate.setDate(date);
    contentPane.add ( txtBirthDate );
    //==================================================

    txtBanID = new JTextField("txtBanID",10);
    txtMoo = new JTextField("txtMoo",10);
    txtTambol = new JTextField("txtTambol",22);
    txtDistrict = new JTextField("txtDistrict",22);
    txtDiag = new JTextField("txtDiag",22);
    txtIntolerance = new JTextField("txtIntolerance",22);
    //================txtInspectionDate=================
    txtInspectionDate = new JDateChooser ( );
    txtInspectionDate.setPreferredSize(new Dimension(216, 20));
    txtInspectionDate.setLocale ( locale );
    txtInspectionDate.setDate(date);
    contentPane.add ( txtInspectionDate );
    //==================================================

    //================txtDoctorDate=====================
    txtDoctorDate = new JDateChooser ( );
    txtDoctorDate.setPreferredSize(new Dimension(216, 20));
    txtDoctorDate.setLocale ( locale );
    txtDoctorDate.setDate(date);
    contentPane.add ( txtDoctorDate );
    //==================================================
    txtSearch = new JTextField("txtSearch",10);txtSearch.setBackground(Color.yellow);


    //==========JButton=========================
    btnGenID = new JButton("GenID");
    btnGenID.setPreferredSize(new Dimension(90, 20));
    btnAdd = new JButton("เพิ่มข้อมูล");
    btnAdd.setPreferredSize(new Dimension(110, 20));
    btnEdit = new JButton("แก้ไขข้อมูล");
    btnEdit.setPreferredSize(new Dimension(110, 20));
    btnDelete = new JButton("ลบข้อมูล");
    btnDelete.setPreferredSize(new Dimension(110, 20));
    btnRefresh = new JButton("รีเฟรซข้อมูล");
    btnRefresh.setPreferredSize(new Dimension(110, 20));
    btnSearch = new JButton("ค้นหา");
    btnSearch.setPreferredSize(new Dimension(110, 20));

    //=======ComboBox ==================================================
    String SexFK[] = {"ชาย","หญิง"};
    cmbSexFK = new JComboBox(SexFK);
    cmbSexFK.setPreferredSize(new Dimension(115, 20));

    String TitleFK[] = {"นาย","นาง","นางสาว","เด็กชาย","เด็กหญิง","พระ","แม่ชี"};
    cmbTitleFK = new JComboBox(TitleFK);
    cmbTitleFK.setPreferredSize(new Dimension(95, 20));

    String Report[] = {"รับรักษา","กลับบ้าน"};
    cmbReport = new JComboBox(Report);
    cmbReport.setPreferredSize(new Dimension(95, 20));

    String Province[] = {"กรุงเทพมหานคร","กระบี่","กาญจนบุรี","กาฬสินธุ์",
    "กำแพงเพชร","ขอนแก่น","จันทบุรี","ฉะเชิงเทรา","ชลบุรี","ชัยนาท","ชัยภูมิ",
    "ชุมพร","เชียงราย","เชียงใหม่","ตรัง","ตราด","ตาก","นครนายก","นครปฐม",
    "นครพนม","นครราชสีมา","นครศรีธรรมราช","นครสวรรค์","นนทบุรี","นราธิวาส",
    "น่าน","บึงกาฬ","บุรีรัมย์","ปทุมธานี","ประจวบคีรีขันธ์","ปราจีนบุรี","ปัตตานี",
    "พระนครศรีอยุธยา","พะเยา","พังงา","พัทลุง","พิจิตร","พิษณุโลก","เพชรบุรี",
    "เพชรบูรณ์","แพร่","ภูเก็ต","มหาสารคาม","มุกดาหาร","แม่ฮ่องสอน","ยะลา",
    "ยโสธร","ระนอง","ระยอง","ราชบุรี","ร้อยเอ็ด","ลพบุรี","ลำปาง","ลำพูน",
    "เลย","ศรีสะเกษ","สกลนคร","สงขลา","สตูล","สมุทรปราการ","สมุทรสงคราม",
    "สมุทรสาคร","สระบุรี","สระแก้ว","สิงห์บุรี","สุพรรณบุรี","สุราษฎร์ธานี","สุรินทร์",
    "สุโขทัย","หนองคาย","หนองบัวลำภู","อำนาจเจริญ","อุดรธานี","อุตรดิตถ์",
    "อุทัยธานี","อ่างทอง","อุบลราชธานี"};
    cmbProvince = new JComboBox(Province);
    cmbProvince.setPreferredSize(new Dimension(140, 20));



    //=====add lbl==============================
    contentPane.add(lblCodePK);
    contentPane.add(lblSexFK);
    contentPane.add(lblFirstName);
    contentPane.add(lblLastName);
    contentPane.add(lblIDCard);
    contentPane.add(lblBirthDate);
    contentPane.add(lblBanID);
    contentPane.add(lblMoo);
    contentPane.add(lblTambol);
    contentPane.add(lblDistrict);
    contentPane.add(lblProvince);
    contentPane.add(lblDiag);
    contentPane.add(lblIntolerance);
    contentPane.add(lblInspectionDate);
    contentPane.add(lblReport);
    contentPane.add(lblDoctorDate);
    contentPane.add(lblSearch);



    //=====add txt==============================
    contentPane.add(txtCodePK);
    contentPane.add(txtCodeID);
    contentPane.add(txtFirstName);
    contentPane.add(txtLastName);
    contentPane.add(txtIDCard);
    contentPane.add(txtBanID);
    contentPane.add(txtMoo);
    contentPane.add(txtTambol);
    contentPane.add(txtDistrict);
    contentPane.add(txtDiag);
    contentPane.add(txtIntolerance);
    contentPane.add(txtInspectionDate);
    contentPane.add(txtDoctorDate);
    contentPane.add(txtSearch);


    //======add button==========================
    contentPane.add(btnGenID);
    contentPane.add(btnAdd);
    contentPane.add(btnEdit);
    contentPane.add(btnDelete);
    contentPane.add(btnRefresh);
    contentPane.add(btnSearch);

    //======add combobox========================
    contentPane.add(cmbSexFK);
    contentPane.add(cmbTitleFK);
    contentPane.add(cmbReport);
    contentPane.add(cmbProvince);

    //===================lblCodePK===========================================
    layout.putConstraint(SpringLayout.WEST, lblCodePK, 10, SpringLayout.WEST, contentPane);
    layout.putConstraint(SpringLayout.NORTH, lblCodePK, 5, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //===================lblSex==============================================
    layout.putConstraint(SpringLayout.WEST, lblSexFK, 10, SpringLayout.WEST, contentPane);
    layout.putConstraint(SpringLayout.NORTH, lblSexFK, 30, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //===================lblFirstName=========================================
    layout.putConstraint(SpringLayout.WEST, lblFirstName, 10, SpringLayout.WEST, contentPane);
    layout.putConstraint(SpringLayout.NORTH, lblFirstName, 55, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //===================lblLastName=========================================
    layout.putConstraint(SpringLayout.WEST, lblLastName, 10, SpringLayout.WEST, contentPane);
    layout.putConstraint(SpringLayout.NORTH, lblLastName, 80, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //===================lblIDCard===========================================
    layout.putConstraint(SpringLayout.WEST, lblIDCard, 10, SpringLayout.WEST, contentPane);
    layout.putConstraint(SpringLayout.NORTH, lblIDCard, 105, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //===================lblBirthDate=========================================
    layout.putConstraint(SpringLayout.WEST, lblBirthDate, 10, SpringLayout.WEST, contentPane);
    layout.putConstraint(SpringLayout.NORTH, lblBirthDate, 130, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //===================lblBanID============================================
    layout.putConstraint(SpringLayout.WEST, lblBanID, 10, SpringLayout.WEST, contentPane);
    layout.putConstraint(SpringLayout.NORTH, lblBanID, 155, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //===================lblMoo==============================================
    layout.putConstraint(SpringLayout.WEST, lblMoo, 10, SpringLayout.WEST, contentPane);
    layout.putConstraint(SpringLayout.NORTH, lblMoo, 180, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //===================lblTambol===========================================
    layout.putConstraint(SpringLayout.WEST, lblTambol, 10, SpringLayout.WEST, contentPane);
    layout.putConstraint(SpringLayout.NORTH, lblTambol, 205, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //===================lblDistrict=========================================
    layout.putConstraint(SpringLayout.WEST, lblDistrict, 10, SpringLayout.WEST, contentPane);
    layout.putConstraint(SpringLayout.NORTH, lblDistrict, 230, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //===================lblProvince=========================================
    layout.putConstraint(SpringLayout.WEST, lblProvince, 10, SpringLayout.WEST, contentPane);
    layout.putConstraint(SpringLayout.NORTH, lblProvince, 255, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //===================lblDiag=============================================
    layout.putConstraint(SpringLayout.WEST, lblDiag, 10, SpringLayout.WEST, contentPane);
    layout.putConstraint(SpringLayout.NORTH, lblDiag, 280, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //===================lblIntolerance======================================
    layout.putConstraint(SpringLayout.WEST, lblIntolerance, 10, SpringLayout.WEST, contentPane);
    layout.putConstraint(SpringLayout.NORTH, lblIntolerance, 305, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //===================lblInspectionDate===================================
    layout.putConstraint(SpringLayout.WEST, lblInspectionDate, 10, SpringLayout.WEST, contentPane);
    layout.putConstraint(SpringLayout.NORTH, lblInspectionDate, 330, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //===================lblReport==========================================
    layout.putConstraint(SpringLayout.WEST, lblReport, 10, SpringLayout.WEST, contentPane);
    layout.putConstraint(SpringLayout.NORTH, lblReport, 355, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //===================lblDoctorDate=======================================
    layout.putConstraint(SpringLayout.WEST, lblDoctorDate, 10, SpringLayout.WEST, contentPane);
    layout.putConstraint(SpringLayout.NORTH, lblDoctorDate, 380, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //===================lblSearch==========================================
    layout.putConstraint(SpringLayout.WEST, lblSearch, 10, SpringLayout.WEST, contentPane);
    layout.putConstraint(SpringLayout.NORTH, lblSearch, 405, SpringLayout.NORTH, contentPane);
    //=======================================================================





    //==================txtCodePK============================================
    layout.putConstraint(SpringLayout.WEST, txtCodePK, 110,SpringLayout.EAST, lblCodePK);
    layout.putConstraint(SpringLayout.NORTH, txtCodePK, 5, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //==================txtCodeID============================================
    layout.putConstraint(SpringLayout.WEST, txtCodeID, 260, SpringLayout.EAST, lblCodePK);
    layout.putConstraint(SpringLayout.NORTH, txtCodeID, 5, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //==================cmbSexFK=============================================
    layout.putConstraint(SpringLayout.WEST, cmbSexFK, 110,SpringLayout.EAST, lblCodePK);
    layout.putConstraint(SpringLayout.NORTH, cmbSexFK, 30,SpringLayout.NORTH, contentPane);
    //=======================================================================

    //==================cmbTitleFK=============================================
    layout.putConstraint(SpringLayout.WEST, cmbTitleFK, 260, SpringLayout.EAST, lblCodePK);
    layout.putConstraint(SpringLayout.NORTH, cmbTitleFK, 30, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //==================txtFirstName==========================================
    layout.putConstraint(SpringLayout.WEST, txtFirstName, 110, SpringLayout.EAST, lblCodePK);
    layout.putConstraint(SpringLayout.NORTH, txtFirstName, 55, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //==================txtLastName==========================================
    layout.putConstraint(SpringLayout.WEST, txtLastName, 110, SpringLayout.EAST, lblCodePK);
    layout.putConstraint(SpringLayout.NORTH, txtLastName, 80, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //==================txtIDCard============================================
    layout.putConstraint(SpringLayout.WEST, txtIDCard, 110, SpringLayout.EAST, lblCodePK);
    layout.putConstraint(SpringLayout.NORTH, txtIDCard, 105, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //==================txtBirthDate=========================================
    layout.putConstraint(SpringLayout.WEST, txtBirthDate, 110, SpringLayout.EAST, lblCodePK);
    layout.putConstraint(SpringLayout.NORTH, txtBirthDate, 130, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //==================txtBanID=============================================
    layout.putConstraint(SpringLayout.WEST, txtBanID, 110, SpringLayout.EAST, lblCodePK);
    layout.putConstraint(SpringLayout.NORTH, txtBanID, 155, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //==================txtMoo===============================================
    layout.putConstraint(SpringLayout.WEST, txtMoo, 110, SpringLayout.EAST, lblCodePK);
    layout.putConstraint(SpringLayout.NORTH, txtMoo, 180, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //==================txtTambol============================================
    layout.putConstraint(SpringLayout.WEST, txtTambol, 110, SpringLayout.EAST, lblCodePK);
    layout.putConstraint(SpringLayout.NORTH, txtTambol, 205, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //==================txtDistrict==========================================
    layout.putConstraint(SpringLayout.WEST, txtDistrict, 110, SpringLayout.EAST, lblCodePK);
    layout.putConstraint(SpringLayout.NORTH, txtDistrict, 230, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //==================cmbProvince==========================================
    layout.putConstraint(SpringLayout.WEST, cmbProvince, 110, SpringLayout.EAST, lblCodePK);
    layout.putConstraint(SpringLayout.NORTH, cmbProvince, 255, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //==================txtDiag=============================================
    layout.putConstraint(SpringLayout.WEST, txtDiag, 110, SpringLayout.EAST, lblCodePK);
    layout.putConstraint(SpringLayout.NORTH, txtDiag, 280, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //==================txtIntolerance=======================================
    layout.putConstraint(SpringLayout.WEST, txtIntolerance, 110, SpringLayout.EAST, lblCodePK);
    layout.putConstraint(SpringLayout.NORTH, txtIntolerance, 305, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //==================txtInspectionDate====================================
    layout.putConstraint(SpringLayout.WEST, txtInspectionDate, 110, SpringLayout.EAST, lblCodePK);
    layout.putConstraint(SpringLayout.NORTH, txtInspectionDate, 330, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //==================cmbReport===========================================
    layout.putConstraint(SpringLayout.WEST, cmbReport, 110,SpringLayout.EAST, lblCodePK);
    layout.putConstraint(SpringLayout.NORTH, cmbReport, 355,SpringLayout.NORTH, contentPane);
    //=======================================================================

    //==================txtDoctorDate========================================
    layout.putConstraint(SpringLayout.WEST, txtDoctorDate, 110, SpringLayout.EAST, lblCodePK);
    layout.putConstraint(SpringLayout.NORTH, txtDoctorDate, 380, SpringLayout.NORTH, contentPane);
    //=======================================================================

    //===================txtSearch==========================================
    layout.putConstraint(SpringLayout.WEST, txtSearch, 160, SpringLayout.WEST, lblCodePK);
    layout.putConstraint(SpringLayout.NORTH, txtSearch, 405, SpringLayout.NORTH, contentPane);
    //=======================================================================







    //===================btnGenID============================================
    layout.putConstraint(SpringLayout.WEST, btnGenID, 460, SpringLayout.WEST,contentPane);
    layout.putConstraint(SpringLayout.NORTH, btnGenID, 5, SpringLayout.NORTH,contentPane);
    //=======================================================================

    //===================btnAdd============================================
    layout.putConstraint(SpringLayout.WEST, btnAdd, 560, SpringLayout.WEST,contentPane);
    layout.putConstraint(SpringLayout.NORTH, btnAdd, 5, SpringLayout.NORTH,contentPane);
    //=======================================================================

    //===================btnEdit============================================
    layout.putConstraint(SpringLayout.WEST, btnEdit, 560, SpringLayout.WEST,contentPane);
    layout.putConstraint(SpringLayout.NORTH, btnEdit, 35, SpringLayout.NORTH,contentPane);
    //=======================================================================

    //===================btnDelte============================================
    layout.putConstraint(SpringLayout.WEST, btnDelete, 560, SpringLayout.WEST,contentPane);
    layout.putConstraint(SpringLayout.NORTH, btnDelete, 65, SpringLayout.NORTH,contentPane);
    //=======================================================================

    //===================btnRefresh============================================
    layout.putConstraint(SpringLayout.WEST, btnRefresh, 560, SpringLayout.WEST,contentPane);
    layout.putConstraint(SpringLayout.NORTH, btnRefresh, 95, SpringLayout.NORTH,contentPane);
    //=======================================================================

    //===================btnSeach============================================
    layout.putConstraint(SpringLayout.WEST, btnSearch, 305, SpringLayout.WEST, contentPane);
    layout.putConstraint(SpringLayout.NORTH, btnSearch, 405, SpringLayout.NORTH,contentPane);
    //=======================================================================



    //Display the window.

    frame.pack();
    frame.setVisible(true);
    frame.setSize(690,480);//800,645
    frame.setResizable(false);//ไม่ให้ Resize
    frame.setLocationRelativeTo(null);
    }
    }
     

    ไฟล์ที่แนบมา:

    • 5.png
      5.png
      ขนาดไฟล์:
      113 KB
      เปิดดู:
      91
    • 6.png
      6.png
      ขนาดไฟล์:
      226.3 KB
      เปิดดู:
      94
    • 7.png
      7.png
      ขนาดไฟล์:
      222.9 KB
      เปิดดู:
      79
    แก้ไขครั้งล่าสุดโดยผู้ดูแล: 15 มิถุนายน 2015
  20. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    นโยบาย ของผมจะเปลี่ยนแปลงและเป็นแรงผลักดันของการใช้ Java Open Source บน Ubuntu มาแทนที่ Windows OS และจะค้นหา Look ใหม่ ๆ มากับการใช้ Java Open Source ตลอดไปครับ (จะทำดีที่สุดในการเผยแผ่บทความ สำหรับโปรแกรมเมอร์ทุกคน) ....ขอบคุณทุกท่านที่คอยติดตามบทความทุกบทและทุกตอนครับ
     

แชร์หน้านี้

Loading...