Netbeans IDE

 

Thai netbeans -เรียนรู้เน็ตบีน - เรียน netbeans

Swing GUI with NetBeans IDE

JCheckBox

 

Thai netbeans - netbeans thai - สอน netbeans -เรียน netbeans - online netbeansThai netbeans - netbeans thai - สอน netbeans -เรียน netbeans - online netbeans
นำ Component ต่างๆ มาวางดังภาพแล้วทำการแก้ไข

คลิกขวาที่ปุ่ม เลือก  Events --> Action --> actionPerformed  เพื่อทำการเขียนโค้ด

       

        int Bath = 0;
        if (jCheckBox1.isSelected() == true) {
            Bath += 50;
        }
        if (jCheckBox2.isSelected() == true) {
            Bath += 30;
        }
        if (jCheckBox3.isSelected() == true) {
            Bath += 20;
        }
        jLabel1.setText("ราคารวม : " + Bath + " ฿");


กดปุ่ม Shift+F6 เพื่อรันโปรแกรม

ผลที่ได้

Thai netbeans - netbeans thai - สอน netbeans -เรียน netbeans - online netbeans    

อธิบาย
โปรแกรมจะทำการบวกค่าเพิ่มตามจำนวนที่กำหนดไว้
เช่น  if (jCheckBox1.isSelected() == true) {
            Bath += 50;
        }

เมื่อมีการ check ค่าที่ช่องแรกให้บวกค่าเพิ่มไปอีก 50 แล้วเก็บค่าไว้ในตัวแปร Bath เพื่อนำไปแสดงผลยัง JLabel

Download This Project Netbeans.