นี่คือโค้ตที่เขียนค่ะ ลองรันก้อขึ้นนะค่ะ แต่พอกดปุ่มคำนวณกลับขึ้น error เยอะมากเลยค่ะ ไม่รุ้ว่าโค้ตผิดตรงไหน ช่วยดูให้หน่อยนะค่ะ
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
class NaijinSaejao extends Frame implements WindowListener,ActionListener
{
Label lblMoney, lblInterest;
TextField txtMoney, txtInterest;
Button bCalc, bExit;
NaijinSaejao()
{
super("Naijin Saejao IT56.1 NO.25");
this.addWindowListener(this);
GridLayout G = new GridLayout(3,2);
this.setLayout(G);
this.setSize(300,300);
this.setResizable(true);
lblMoney = new Label("เงินฝาก :");
txtMoney = new TextField(20);
lblInterest = new Label("ดอกเบี้ย :");
txtInterest = new TextField(20);
txtInterest.setEnabled(false);
bCalc = new Button("Calulator");
bCalc.addActionListener(this);
bExit = new Button("Exit");
bExit.addActionListener(this);
add(lblMoney); add(txtMoney);
add(lblInterest); add(txtInterest);
add(bCalc); add(bExit);
this.setVisible(true);
}
//---------------------------------------------------------------------
public void windowClosing(WindowEvent W)
{
System.exit(0);
}
public void windowClosed(WindowEvent W){}
public void windowOpened(WindowEvent W){}
public void windowActivated(WindowEvent W){}
public void windowDeactivated(WindowEvent W){}
public void windowIconified(WindowEvent W){}
public void windowDeiconified(WindowEvent W){}
//---------------------------------------------------------------------
public void actionPerformed(ActionEvent A)
{
if (A.getSource()==bCalc)
{
calInt();
}
if (A.getSource()==bExit)
{
System.exit(0);
}
}//end actionPerformed
//---------------------------------------------------------------------
private void calInt()
{
double mon,my;
double i = Double.parseDouble(txtInterest.getText());
my=i/12;
if (i<=100)
{
mon = i*0.002;
txtMoney.setText(String.valueOf(mon));
}
else if (i<=1000)
{
mon = i*0.003;
txtMoney.setText(String.valueOf(mon));
}
else if (i<=10000)
{
mon = i*0.005;
txtMoney.setText(String.valueOf(mon));
}
else
{
mon = i*0.10;
txtMoney.setText(String.valueOf(mon));
}
}//end calDb
//------------------------------------------------------------------------
public static void main(String[] args)
{
NaijinSaejao N = new NaijinSaejao();
}
}
โค้ตการคำนวณดอกเบี้ยเงินฝาก ด้วยโปรแกรมจาวาค่ะ
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
class NaijinSaejao extends Frame implements WindowListener,ActionListener
{
Label lblMoney, lblInterest;
TextField txtMoney, txtInterest;
Button bCalc, bExit;
NaijinSaejao()
{
super("Naijin Saejao IT56.1 NO.25");
this.addWindowListener(this);
GridLayout G = new GridLayout(3,2);
this.setLayout(G);
this.setSize(300,300);
this.setResizable(true);
lblMoney = new Label("เงินฝาก :");
txtMoney = new TextField(20);
lblInterest = new Label("ดอกเบี้ย :");
txtInterest = new TextField(20);
txtInterest.setEnabled(false);
bCalc = new Button("Calulator");
bCalc.addActionListener(this);
bExit = new Button("Exit");
bExit.addActionListener(this);
add(lblMoney); add(txtMoney);
add(lblInterest); add(txtInterest);
add(bCalc); add(bExit);
this.setVisible(true);
}
//---------------------------------------------------------------------
public void windowClosing(WindowEvent W)
{
System.exit(0);
}
public void windowClosed(WindowEvent W){}
public void windowOpened(WindowEvent W){}
public void windowActivated(WindowEvent W){}
public void windowDeactivated(WindowEvent W){}
public void windowIconified(WindowEvent W){}
public void windowDeiconified(WindowEvent W){}
//---------------------------------------------------------------------
public void actionPerformed(ActionEvent A)
{
if (A.getSource()==bCalc)
{
calInt();
}
if (A.getSource()==bExit)
{
System.exit(0);
}
}//end actionPerformed
//---------------------------------------------------------------------
private void calInt()
{
double mon,my;
double i = Double.parseDouble(txtInterest.getText());
my=i/12;
if (i<=100)
{
mon = i*0.002;
txtMoney.setText(String.valueOf(mon));
}
else if (i<=1000)
{
mon = i*0.003;
txtMoney.setText(String.valueOf(mon));
}
else if (i<=10000)
{
mon = i*0.005;
txtMoney.setText(String.valueOf(mon));
}
else
{
mon = i*0.10;
txtMoney.setText(String.valueOf(mon));
}
}//end calDb
//------------------------------------------------------------------------
public static void main(String[] args)
{
NaijinSaejao N = new NaijinSaejao();
}
}