我正在尝试在 java 中创建一个 ATM 模拟。我在调用另一个类时遇到了一些问题。当我运行 WithdrawCash 类时,它运行完美,但是当我通过从选项中选择在 FastCash 中调用它时,会出现一个空白表单。
以下是WithdrawCash的代码:
import java.io.*;
import javax.swing.*;
import java.awt.*;`
import java.awt.event.*;
public class WithdrawCash extends JFrame implements ActionListener{
public static void main(String args[]){
WithdrawCash frame=new WithdrawCash();
frame.setBounds(400,300,400,150);
frame.createGUI();
frame.setTitle("Withdraw Cash Menu:");
frame.setVisible(true);
}//closes main
private JLabel title, menu;
private JTextField number;
private JButton SUBMIT;
private void createGUI(){
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container wm=getContentPane();
wm.setLayout(new FlowLayout());
title = new JLabel("Please choose from the options below (a-d):");
menu = new JLabel("a)Fast Cash b)Normal Cash c)Main Menu d)Logout");
number = new JTextField(10);
SUBMIT = new JButton("SUBMIT");
wm.add(title);
wm.add(menu);
wm.add(number);
wm.add(SUBMIT);
SUBMIT.addActionListener(this);
}//closes createGUI
public void actionPerformed(ActionEvent evt){
String value1=number.getText();
String a,b,c,d,A,B,C,D;
if(number.getText().length()==0){
JOptionPane.showMessageDialog(null, "Please enter the menu option");
number.requestFocus();
}//closes if
switch(value1){
case "a":
case "A": //Fast Cash
JOptionPane.showMessageDialog(null, "Fast Cash");
break;
case "b":
case "B": //Normal Cash
JOptionPane.showMessageDialog(null, "Normal Cash");
break;
case "c":
case "C": //Main Menu
new AccountOpen().setVisible(true);
this.dispose();
break;
case "d":
case "D": //Logout
this.dispose();
break;
default:
JOptionPane.showMessageDialog(null, "Invalid option!! Please type between a-d");
number.setText(null);
number.requestFocus();
}//closes switch
}//closes actionPerformed
}//closes WithdrawCash
FastCash 的代码:
import java.io.*;
import java.sql.*;
import javax.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class FastCash extends JFrame implements ActionListener{
public static void main(String args[]){
FastCash frame=new FastCash();
frame.setBounds(400,300,400,150);
frame.createGUI();
frame.setTitle("Fast Cash Menu:");
frame.setVisible(true);
}//closes main
private JLabel title, menu, menu2;
private JTextField number;
private JButton SUBMIT;
private void createGUI(){
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container fc=getContentPane();
fc.setLayout(new FlowLayout());
title = new JLabel("Please choose from the options below (1-10):");
menu = new JLabel("1)500 2)1000 3)2000 4)5000 5)10000 6)15000");
menu2 = new JLabel("7)20000 8)Withdrawal menu 9)Main Menu 10)Logout");
number = new JTextField(10);
SUBMIT = new JButton("SUBMIT");
fc.add(title);
fc.add(menu);
fc.add(menu2);
fc.add(number);
fc.add(SUBMIT);
SUBMIT.addActionListener(this);
}//closes createGUI
public void actionPerformed(ActionEvent evnt){
int value1=Integer.parseInt(number.getText());
if(number.getText().length()==0){
JOptionPane.showMessageDialog(null, "Please enter the menu option");
number.requestFocus();
}//closes if
switch(value1){
case 1:
JOptionPane.showMessageDialog(null, "500");
break;
case 2:
JOptionPane.showMessageDialog(null, "1000");
break;
case 3:
JOptionPane.showMessageDialog(null, "2000");
break;
case 4:
JOptionPane.showMessageDialog(null, "5000");
break;
case 5:
JOptionPane.showMessageDialog(null, "10000");
break;
case 6:
JOptionPane.showMessageDialog(null, "15000");
break;
case 7:
JOptionPane.showMessageDialog(null, "20000");
break;
case 8:
new WithdrawCash().setVisible(true);
this.dispose();
break;
case 9: //Main Menu
new AccountOpen().setVisible(true);
this.dispose();
break;
case 10:
this.dispose();
break;
default:
JOptionPane.showMessageDialog(null, "Invalid option!! Please type between 1-10");
number.setText(null);
number.requestFocus();
}//closes switch
}//closes actionPerformed
}//closes FastCash
注意:当我尝试打开 AccountOpen(我的主菜单)时,它会从我的 FastCash 类完美打开,那么 WithdrawCash 类有什么问题?
请帮我。任何帮助,将不胜感激。谢谢。