|
 |
|
Java GUI สอบถามการเช็คค่าในตารางว่ามีซ้ำกันไหมครับ และการดึงค่าของ table ครับ JAVAGUI |
|
 |
|
|
 |
 |
|
คุณใช้ DataSource แบบไหนครับ Array หรือว่าอะไรครับ
|
 |
 |
 |
 |
Date :
2015-03-27 10:45:43 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 1 เขียนโดย : mr.win เมื่อวันที่ 2015-03-27 10:45:43
รายละเอียดของการตอบ ::
ใช่เป็นการเพิ่มข้อมูลทีล้ะรายการครับ ไม่ได้เป็น Array ครับ ตัวอย่าง code ปุ่มเพิ่มลงตารางล่างอ้ะครับ รบกวนด้วยครับ Admin
Code (Java)
Object[] data = new Object[0];
DefaultTableModel std = new DefaultTableModel();
std = (DefaultTableModel) table2.getModel();
std.addRow(data);
int row = table.getSelectedRow();
int row1 = table2.getRowCount() - 1;
if (row == -1) {
JOptionPane.showMessageDialog(null, "กรูณาค้นสินค้าและเลือกสินค้าก่อน"); //ดึงหมายเลขแถวที่ผู้ใช้เลือก
std.removeRow(row1);
count();
return;
} else {
table.getSelectedRow();
String id = table.getValueAt(row, 0).toString();
String name = table.getValueAt(row, 1).toString();
String unit = table.getValueAt(row, 2).toString();
String price = table.getValueAt(row, 3).toString();
String amount = table.getValueAt(row, 4).toString();
table2.setValueAt(count++, row1, 0);
table2.setValueAt(id, row1, 1);
table2.setValueAt(name, row1, 2);
table2.setValueAt(unit, row1, 3);
String unitbuy2 = JOptionPane.showInputDialog("ใส่จำนวนที่ต้องการซื้อ");
if (unitbuy2.equalsIgnoreCase("")) {
JOptionPane.showMessageDialog(null, "กรุณากรอกจำนวน");
std.removeRow(row1);
count = 1;
return;
}
int unitbuy1 = Integer.parseInt(unitbuy2);
int amount1 = Integer.parseInt(amount);
if (unitbuy1 > amount1) {
JOptionPane.showMessageDialog(null, "สินค้าไม่พอขาย");
std.removeRow(row1);
count--;
return;
}
int pricebuy = Integer.parseInt(price);
int sum = unitbuy1 * pricebuy;
table2.setValueAt(unitbuy1, row1, 4);
table2.setValueAt(sum, row1, 5);
String showtotal2 = table2.getValueAt(row1, 5).toString();
int sum1;
sum1 = Integer.parseInt(showtotal2);
total = total + sum1;
String show = String.valueOf(total);
showtotal1.setText(show);
Double tax = 0.07;
tax = total * tax;
DecimalFormat df = new DecimalFormat("0.00");
String taxshow = String.valueOf(df.format(tax));
showtax.setText(taxshow);
saletotal = total + tax;
String saletotalshow = String.valueOf(df.format(saletotal));
showtotalsale.setText(saletotalshow);
for(int row11 = -1; row11 < row1; row11++) {
if(row11>-1){
String aaa = table2.getValueAt(row1,1).toString();
System.out.println(aaa);
System.out.println(aa);
if(aaa.equalsIgnoreCase(aa)){
JOptionPane.showMessageDialog(null,"สินค้ามีอยู่ในรายการแล้ว");
aaa = "";
return;
}
}
}
}
|
 |
 |
 |
 |
Date :
2015-03-27 11:17:43 |
By :
theerat56 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|