Kullanıyorum Şu anda bir ATM projesi için bir sınıfım var. Benim eylemde, 4 düğüme sahibim (yirmi, elli, yüz ve diğer). Para yatırmayı hesaba katarız. Tasarruflardan cilveli mevduat ayırmak istiyorum ama aynı java dosyasına sahip olmak istiyorum. Benim öznitelik olarakif (boolean == true) actionPerformed durumunda
Ben kullanıcı chequing (true boolean veya kaydetme (yanlış boolean) için gidiyorsa karar verir
private triggerChecker checker;
.
kod aşağıda benim actionPerformed metoduna gösteriyor olacak
public void actionPerformed(ActionEvent e)
{
//Loop through the keypad array to see if any of the buttons were pressed
for (int i = 0; i < 10; i++)
{
if (e.getSource() == keypad[i])
{
//Edit the input display
cardID = cardID + i;
display.setText("\n\n\tPlease enter amount of money:" + "\n\t" +cardID);
}
}
if(e.getSource() == keypad[11]){
cardID = "";
display.setText("\n\n\tPlease enter amount of money:" + "\n\t" +cardID);
}
if(checker.getCheck() == true){
if (e.getSource() == twenty)
{
display.setText(feature.DepositTOC(20.0));
display.setFont(new Font("Arial", Font.BOLD,18));
display.setVisible(true);
}
if (e.getSource() == fifty)
{
display.setText(feature.DepositTOC(50.0));
display.setFont(new Font("Arial", Font.BOLD,18));
display.setVisible(true);
}
if (e.getSource() == hundred)
{
display.setText(account.toString());
display.setFont(new Font("Arial", Font.BOLD,20));
display.setVisible(true);
}
if (e.getSource() == other)
{
cardID = "";
display.setText("\n\n\tPlease enter amount of money:" + "\n\t" +cardID);
}
if(e.getSource() == keypad[12]){
double num = Double.parseDouble(cardID);
display.setText(feature.DepositTOC(num));
display.setFont(new Font("Arial", Font.BOLD,18));
display.setVisible(true);
}
}
if(checker.getCheck() == false){
if (e.getSource() == twenty)
{
display.setText(feature.DepositTOS(20.0));
display.setFont(new Font("Arial", Font.BOLD,18));
display.setVisible(true);
}
if (e.getSource() == fifty)
{
display.setText(feature.DepositTOS(50.0));
display.setFont(new Font("Arial", Font.BOLD,18));
display.setVisible(true);
}
if (e.getSource() == hundred)
{
display.setText(account.toString());
display.setFont(new Font("Arial", Font.BOLD,20));
display.setVisible(true);
}
if (e.getSource() == other)
{
cardID = "";
display.setText("\n\n\tPlease enter amount of money:" + "\n\t" +cardID);
}
if(e.getSource() == keypad[12]){
double num = Double.parseDouble(cardID);
display.setText(feature.DepositTOS(num));
display.setFont(new Font("Arial", Font.BOLD,18));
display.setVisible(true);
}}
}
Eğer (boolean == true) actionPerformed içinde yapamayacağımı hissedebiliyorum. Eğer bir fikriniz varsa, lütfen bana bir ipucu ve yardım ile çalışmak için istekli olduğumu söyleyin. Birini benim için bütün bir işlevi yazmayı planlamak. Teşekkür
denetleyicisi sınıf
public class triggerChecker {
private boolean checkW, checkD, checkWC, checkWS, checkDC, checkDS;
public triggerChecker(){
checkW = false;
checkD = false;
checkWC = false;
checkWS = false;
checkDC = false;
checkDS = false;
}
public void setCheckW(boolean s){
checkW = s;
}
public void setCheckD(boolean s){
checkD = s;
}
public void setCheckWC(boolean s){
checkWC = s;
}
public void setCheckWS(boolean s){
checkWS = s;
}
public void setCheckDC(boolean s){
checkDC = s;
}
public void setCheckDS(boolean s){
checkDS = s;
}
public boolean getCheckW(){
return checkW;
}
public boolean getCheckD(){
return checkD;
}
public boolean getCheckWC(){
return checkWC;
}
public boolean getCheckWS(){
return checkWS;
}
public boolean getCheckDC(){
return checkDC;
}
public boolean getCheckDS(){
return checkDS;
}
}
Hiçbir zaman "someBoolean == true" yazmanız gerekmiyor - 'someBoolean' eşdeğerdir (benzer şekilde'! SomeBoolean' 'someBoolean == false' öğesine eşdeğerdir) –
yapmanız gerekmiyorsa (checker.getCheck() = = true) {bunun yerine kullanın (checker.getCheck()) { –
Evet ama bu benim sorunuma yardımcı olmaz. Will? –