อยากให้โปรเเกรม
ถอนเงินได้มากกว่า 100 บาทถ้าน้อยกว่า ก็ขึ้นขอความ ว่าถอนไม่ได้
หรือถอดเงินมากกว่าเงินที่มี ก็ขึ้นขอความ ว่าถอนไม่ได้
คิดไม่ออกแล้วว่าจะทำไงต่อ
Code หลักๆตามนี้ครับ ปล.เเก้ไข code
[code]package javaproject;
import java.awt.event.KeyEvent;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
import java.sql.*;
public class Withdraw extends javax.swing.JFrame {
Connection conn;
ResultSet rs;
PreparedStatement pst;
public Withdraw() {
super("withdrwal");
initComponents();
conn =Connect.ConnecrDB();
jButton1.setEnabled(false);
jButton2.setEnabled(false);
jButton3.setEnabled(false);
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// exit Button
JOptionPane.showMessageDialog(null,"กลับหน้าเมนู");
new MainMenu().setVisible(true);
this.setVisible(false);
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// Withdraw Button
try{
String v1=jTextField5.getText();
String v2=jTextField7.getText();
// String value3=jTextField3.getText();
String sql="update Account set Balance ='"+ v2 +"'where Balance='"+ v1 +"'";
pst=conn.prepareStatement(sql);
pst.execute(); // executeQuery giving me an error and not applicable as per
JOptionPane.showMessageDialog(null,"จำนวนเงินถูกถอนแล้ว!");
jTextField1.setText(""); //clear
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jTextField6.setText("");
jTextField7.setText("");
} catch (Exception e){
JOptionPane.showMessageDialog(null,e);
}
try{
rs.close();
pst.close();
}catch(Exception e){ // fetcher for basura codes and exception for java
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// View Button
// Compute Button
try{
String v1=jTextField5.getText();
String v2=jTextField6.getText();
//int sub = Integer.parseInt(v2)- Integer.parseInt(v1);
//int sub = (Integer.parseInt(v2))- (Integer.parseInt(v1));
int sub = Integer.valueOf(jTextField5.getText()) - Integer.valueOf(jTextField6.getText());
String sub1 = String.valueOf(sub);
jTextField7.setText(sub1);
rs.close();
pst.close();
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// Check Button for Balance Inquiry
String sql="select * from Account where Acc=?";
try{
pst=conn.prepareStatement(sql);
pst.setString(1, jTextField1.getText());
rs=pst.executeQuery();
if(rs.next()){
String add1=rs.getString("Name"); // this is name of the DB Variable
jTextField2.setText(add1);
String add2=rs.getString("Cardno"); // this is name of the DB Variable
jTextField3.setText(add2);
String add3=rs.getString("Ctype"); // this is name of the DB Variable
jTextField4.setText(add3);
String add4=rs.getString("Balance"); // this is name of the DB Variable
jTextField5.setText(add4);
}
rs.close();
pst.close();
}catch (Exception e){
JOptionPane.showMessageDialog(null,e);
}
}
[/code]
Java ถามเรื่อง Code ทำโปรแกรม ATM
ถอนเงินได้มากกว่า 100 บาทถ้าน้อยกว่า ก็ขึ้นขอความ ว่าถอนไม่ได้
หรือถอดเงินมากกว่าเงินที่มี ก็ขึ้นขอความ ว่าถอนไม่ได้
คิดไม่ออกแล้วว่าจะทำไงต่อ
Code หลักๆตามนี้ครับ ปล.เเก้ไข code
[code]package javaproject;
import java.awt.event.KeyEvent;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
import java.sql.*;
public class Withdraw extends javax.swing.JFrame {
Connection conn;
ResultSet rs;
PreparedStatement pst;
public Withdraw() {
super("withdrwal");
initComponents();
conn =Connect.ConnecrDB();
jButton1.setEnabled(false);
jButton2.setEnabled(false);
jButton3.setEnabled(false);
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// exit Button
JOptionPane.showMessageDialog(null,"กลับหน้าเมนู");
new MainMenu().setVisible(true);
this.setVisible(false);
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// Withdraw Button
try{
String v1=jTextField5.getText();
String v2=jTextField7.getText();
// String value3=jTextField3.getText();
String sql="update Account set Balance ='"+ v2 +"'where Balance='"+ v1 +"'";
pst=conn.prepareStatement(sql);
pst.execute(); // executeQuery giving me an error and not applicable as per
JOptionPane.showMessageDialog(null,"จำนวนเงินถูกถอนแล้ว!");
jTextField1.setText(""); //clear
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jTextField6.setText("");
jTextField7.setText("");
} catch (Exception e){
JOptionPane.showMessageDialog(null,e);
}
try{
rs.close();
pst.close();
}catch(Exception e){ // fetcher for basura codes and exception for java
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// View Button
// Compute Button
try{
String v1=jTextField5.getText();
String v2=jTextField6.getText();
//int sub = Integer.parseInt(v2)- Integer.parseInt(v1);
//int sub = (Integer.parseInt(v2))- (Integer.parseInt(v1));
int sub = Integer.valueOf(jTextField5.getText()) - Integer.valueOf(jTextField6.getText());
String sub1 = String.valueOf(sub);
jTextField7.setText(sub1);
rs.close();
pst.close();
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// Check Button for Balance Inquiry
String sql="select * from Account where Acc=?";
try{
pst=conn.prepareStatement(sql);
pst.setString(1, jTextField1.getText());
rs=pst.executeQuery();
if(rs.next()){
String add1=rs.getString("Name"); // this is name of the DB Variable
jTextField2.setText(add1);
String add2=rs.getString("Cardno"); // this is name of the DB Variable
jTextField3.setText(add2);
String add3=rs.getString("Ctype"); // this is name of the DB Variable
jTextField4.setText(add3);
String add4=rs.getString("Balance"); // this is name of the DB Variable
jTextField5.setText(add4);
}
rs.close();
pst.close();
}catch (Exception e){
JOptionPane.showMessageDialog(null,e);
}
}
[/code]