目前我遇到的问题是,每当我加载一个将我的JTextField setVisible改为true的新图像时,它就会留在图像后面,只有当我用鼠标突出显示它时才会出现。
它实际出现的唯一时间是我第一次在第一张图片上运行程序。
在我的具体情况下,当我进入“输入金额存款/取款:”时,问题就出现了。它只能在第一次输入帐号时第一次运行。
此外,无论何时我将可见性设置为true,我也将opaque设置为true。
我希望它看起来像http://imgur.com/gYo3Enq
这是我去新图片http://imgur.com/s6aAGn8
时的样子这里的参考是所有代码(警告:非常凌乱):
@Override
public void actionPerformed(ActionEvent e) {
//jtf.setVisible(false);
String str = "";
if (screen == Screen.WELCOME_SCREEN) {
screen = Screen.ENTER_ACC_SCREEN;
numberString = "";
jtf.setVisible(true);
jtf.setOpaque(true);
repaint();
}
if (screen == Screen.ENTER_ACC_SCREEN) {
jtf.setVisible(true);
jtf.setBounds(220, 350, 200, 35);
jtf.setOpaque(true);
if (e.getSource() == bp) {
if (cData.customerList(numberString) != null) {
screen = Screen.MAIN_BUTTONS;
repaint();
} else {
JOptionPane jop = new JOptionPane();
jop.showMessageDialog(panel1, "\tInvalid Account Number.\nNo such account exits.\nPlease Re-enter account number.\n");
numberString = "";
}
}
}
if (screen == Screen.MAIN_BUTTONS) {
jtf.setVisible(false);
if (e.getSource().equals(l1)) {
screen = Screen.ACC_INFO_SCREEN;
JTextField checkBal = new JTextField();
JTextField saveBal = new JTextField();
double temp = cData.checkBal(numberString);
String check = String.valueOf(temp);
panelMain.add(checkBal, BorderLayout.CENTER);
checkBal.setText(check);
checkBal.setEditable(false);
checkBal.setVisible(true);
checkBal.setFont(new Font("Arial",1,25));
checkBal.setBounds(340, 125, 200, 25);
double temp2 = cData.saveBal(numberString);
String check2 = String.valueOf(temp2);
panelMain.add(saveBal, BorderLayout.CENTER);
saveBal.setText(check2);
saveBal.setEditable(false);
saveBal.setVisible(true);
saveBal.setFont(new Font("Arial",1,25));
saveBal.setBounds(340, 239, 200, 25);
repaint();
} else if (e.getSource().equals(l2)) {
repaint();
} else if (e.getSource().equals(l3)) {
screen = Screen.WELCOME_SCREEN;
repaint();
} else if (e.getSource().equals(r1)) {
screen = Screen.WITHDRAW_SCREEN;
repaint();
} else if (e.getSource().equals(r2)) {
screen = Screen.DEPOSIT_SCREEN;
repaint();
} else if (e.getSource().equals(r3)) {
screen = Screen.TRANSFER_SCREEN;
repaint();
}
}
if (screen == Screen.ACC_INFO_SCREEN) {
if (e.getSource() == l3) {
screen = Screen.MAIN_BUTTONS;
repaint();
}
}
if (screen == Screen.WITHDRAW_SCREEN_2) {
if (e.getSource() == l3) {
screen = Screen.MAIN_BUTTONS;
numberString = "";
repaint();
}
}
if (screen == Screen.ENTER_ACC_SCREEN || screen == Screen.WITHDRAW_SCREEN || screen == Screen.DEPOSIT_SCREEN || screen == Screen.TRANSFER_SCREEN || screen == Screen.WITHDRAW_SCREEN_2 || screen == Screen.TRANSACTION) {
jtf.setFont(new Font("Arial",1,25));
jtf.setActionCommand("ENTER");
jtf.addActionListener(this);
jtf.setVisible(true);
String actionCommand = e.getActionCommand();
if (screen == Screen.TRANSACTION) {
if (e.getSource() == r1) {
screen = Screen.MAIN_BUTTONS;
numberString = "";
repaint();
} else if (e.getSource()== r2) {
screen = Screen.WELCOME_SCREEN;
numberString = "";
repaint();
}
}
if (screen == screen.WITHDRAW_SCREEN) {
if (e.getSource() == l1) {
screen = Screen.WITHDRAW_SCREEN_2;
numberString = "";
jtf.setBounds(390, 90, 200, 50);
repaint();
jtf.setVisible(true);
jtf.setOpaque(true);
if (e.getSource() == bp) {
int wAmount = Integer.parseInt(numberString);
cData.subtractCheckBal(numberString, wAmount);
screen = Screen.TRANSACTION;
repaint();
if (e.getSource().equals(r1)) {
screen = Screen.MAIN_BUTTONS;
repaint();
} else if (e.getSource().equals(r2)) {
screen = Screen.WELCOME_SCREEN;
repaint();
}
}
} else if (e.getSource() == l2) {
screen = Screen.WITHDRAW_SCREEN_2;
repaint();
jtf.setVisible(true);
jtf.setOpaque(true);
numberString = "";
jtf.setBounds(390, 90, 200, 50);
if (e.getSource() == bp) {
int wAmount = Integer.parseInt(numberString);
cData.subtractSaveBal(numberString, wAmount);
screen = Screen.TRANSACTION;
repaint();
if (e.getSource().equals(r1)) {
screen = Screen.MAIN_BUTTONS;
repaint();
} else if (e.getSource().equals(r2)) {
screen = Screen.WELCOME_SCREEN;
repaint();
}
}
} else if (e.getSource() == l3) {
screen = Screen.MAIN_BUTTONS;
repaint();
}
}
if (screen == screen.DEPOSIT_SCREEN) {
if (e.getSource() == l1) {
screen = Screen.WITHDRAW_SCREEN_2;
jtf.setVisible(true);
jtf.setOpaque(true);
numberString = "";
jtf.setBounds(390, 90, 200, 50);
repaint();
if (e.getSource() == bp) {
int dAmount = Integer.parseInt(numberString);
cData.addCheckBal(numberString, dAmount);
screen = Screen.TRANSACTION;
repaint();
if (e.getSource().equals(r1)) {
screen = Screen.MAIN_BUTTONS;
repaint();
} else if (e.getSource().equals(r2)) {
screen = Screen.WELCOME_SCREEN;
repaint();
}
}
} else if (e.getSource() == l2) {
screen = Screen.WITHDRAW_SCREEN_2;
repaint();
jtf.setVisible(true);
jtf.setOpaque(true);
jtf.setBounds(390, 90, 200, 50);
repaint();
if (e.getSource() == bp) {
int dAmount = Integer.parseInt(numberString);
cData.addSaveBal(numberString, dAmount);
screen = Screen.TRANSACTION;
repaint();
if (e.getSource().equals(r1)) {
screen = Screen.MAIN_BUTTONS;
repaint();
} else if (e.getSource().equals(r2)) {
screen = Screen.WELCOME_SCREEN;
repaint();
}
}
} else if (e.getSource().equals(l3)) {
screen = Screen.MAIN_BUTTONS;
repaint();
}
}
if (screen == Screen.TRANSFER_SCREEN) {
if (e.getSource() == l1) { // transfer from checking to savings
screen = Screen.WITHDRAW_SCREEN_2;
repaint();
jtf.setVisible(true);
jtf.setOpaque(true);
jtf.setBounds(390, 90, 200, 50);
if (e.getSource() == bp) {
int dAmount = Integer.parseInt(numberString);
cData.addSaveBal(numberString, dAmount);
cData.subtractCheckBal(numberString, dAmount);
screen = Screen.TRANSACTION;
repaint();
if (e.getSource().equals(r1)) {
screen = Screen.MAIN_BUTTONS;
repaint();
} else if (e.getSource().equals(l2)) {
screen = Screen.WELCOME_SCREEN;
}
}
} else if (e.getSource() == l2) { // transfer from savings to checking
screen = Screen.WITHDRAW_SCREEN_2;
repaint();
jtf.setVisible(true);
//jtf.setbounds
int dAmount = Integer.parseInt(numberString);
cData.addCheckBal(numberString, dAmount);
cData.subtractSaveBal(numberString, dAmount);
screen = Screen.TRANSACTION;
repaint();
if (e.getSource().equals(r1)) {
screen = Screen.MAIN_BUTTONS;
repaint();
} else if (e.getSource().equals(l2)) {
screen = Screen.WELCOME_SCREEN;
}
} else if (e.getSource().equals(l3)) {
screen = Screen.TRANSFER_SCREEN;
repaint();
jtf.setVisible(false);
}
}
if (e.getSource() == b1) {
numberString += "1";
jtf.setText(numberString);
repaint();
} else if (e.getSource() == b2) {
numberString += "2";
jtf.setText(numberString);
repaint();
} else if (e.getSource() == b3) {
numberString+= "3";
jtf.setText(numberString);
repaint();
} else if (e.getSource() == b4) {
numberString+= "4";
jtf.setText(numberString);
repaint();
} else if (e.getSource() == b5) {
numberString+= "5";
jtf.setText(numberString);
repaint();
} else if (e.getSource() == b6) {
numberString+= "6";
jtf.setText(numberString);
repaint();
} else if (e.getSource() == b7) {
numberString+= "7";
jtf.setText(numberString);
repaint();
} else if (e.getSource() == b8) {
numberString+= "8";
jtf.setText(numberString);
repaint();
} else if (e.getSource() == b9) {
numberString+= "9";
jtf.setText(numberString);
repaint();
} else if (e.getSource() == b0) {
numberString+= "0";
jtf.setText(numberString);
repaint();
} else if (e.getSource() == ba) { // clear button
// clear previous entry
if (numberString.length() > 0) {
numberString = numberString.substring(0, numberString.length() - 1);
}
jtf.setText(numberString);
repaint();
}
}