大家帮下忙 看看退出时 jframe 为什么显示不出来
做了一个简单的系统,首先jframe窗口 点击确定,输入用户名 11,密码 11,进入系统操作。输入4 退出时,跳出一jframe界面,可为什么显示不了?import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class KaiShi extends JFrame implements ActionListener{
KaiShi(){
Font f=new Font("楷体_GB2312",Font.BOLD,32);
Color c2=new Color(255,0,0);
JLabel label1=new JLabel("欢迎使用ATM模拟自动取款机程序,点击确定进入!");
JButton button1=new JButton("确定");
label1.setForeground(c2);
label1.setFont(f);
button1.setForeground(c2);
button1.setFont(f);
add(label1,BorderLayout.CENTER);
add(button1,BorderLayout.SOUTH);
setBounds(500,100,800,300);
setVisible(true);
validate();
button1.addActionListener(this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
dispose();
ATM atm=new ATM();
try{
atm.Load_Sys();
}catch(Exception ee){}
}
}
class TuiChu extends JFrame implements ActionListener{
TuiChu(){
Font f=new Font("楷体_GB2312",Font.BOLD,32);
Color c2=new Color(255,0,0);
JLabel label1=new JLabel("感谢您使用本系统,欢迎下次再来,再见!");
JButton button1=new JButton("确定");
label1.setForeground(c2);
label1.setFont(f);
button1.setForeground(c2);
button1.setFont(f);
add(label1,BorderLayout.CENTER);
add(button1,BorderLayout.SOUTH);
setBounds(100,100,800,300);
setVisible(true);
validate();
button1.addActionListener(this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
System.exit(1);
}
}
/*该类为实现客户信息及部分功能*/
class Account {
private String code =null; //信用卡号
private String name =null; //客户姓名
private String password=null; //客户密码
private double money =0.0; //卡里金额
/********************/
public Account(String code,String name,String password,double money)
{
this.code=code;
this.name=name;
this.password=password;
this.money=money;
}
protected String get_Code() {
return code;
}
protected String get_Name() {
return name;
}
protected String get_Password() {
return password;
}
public double get_Money() {
return money;
}
/*得到剩余的钱的数目*/
protected void set_Balance(double mon) {
money -= mon;
}
}
/**********实现具体取款机功能*********/
class ATM {
Account act;
public ATM() {
act=new Account("11","Devil","11",50000);
}
/**********登陆系统**********/
protected void Load_Sys() throws Exception
{
String card,pwd;
int counter=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
do {
System.out.println("请输入您的信用卡号:");
card=br.readLine();
System.out.println("请输入您的密码:");
pwd=br.readLine();
if(!isRight(card,pwd))
{
System.out.println("您的卡号或密码输入有误.");
counter++;
}
else
SysOpter();
}while(counter<3);
Lock_Sys();
}
/**********系统操作**********/
protected void SysOpter() throws Exception
{
int num;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("\n请选择您要操作的项目(1-4):");
System.out.print("\n 1.>取款."+"\n"+
" 2.>查询信息."+"\n"+
" 3.>密码设置."+"\n"+
" 4.>退出系统."+"\n");
num=br.read(); //num为ASICC码转换的整数
switch(num) {
case 49: BetBalance(); break;
case 50: Inqu_Info(); break;
case 51: Set_Password(); break;
case 52: Exit_Sys(); break;
}
}
/**********信息查询**********/
protected void Inqu_Info() throws Exception {
do{ System.out.print("---------------------\n"+
act.get_Code()+"\n"+
act.get_Name()+"\n"+
act.get_Money()+"\n"+
"-----------------------");
SysOpter();
}while(true);
}
/**********取款**********/
public void BetBalance() throws Exception
{
String str=null,str1;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
do {
System.out.println("请输入您要取的数目:");
str=br.readLine();
str1=String.valueOf(act.get_Money());
if(str.compareTo(str1)>0) {
System.out.println("超过已有的钱数,请重新输入您要取的数目:");
}
else {
/*操作成功*/
// act.set_Balance(str);
System.out.println("取款成功,请收好您的钱.");
SysOpter();
}
}while(true);
}
/**********判断卡内是否有钱**********/
protected boolean isBalance() {
if(act.get_Money()<0) {
System.out.println("对不起,您的钱数不够或卡已透支.");
//return false;
}
return true;
}
/********卡号密码是否正确******/
protected boolean isRight(String card,String pwd)
{
if(act.get_Code().equals(card) && act.get_Password().equals(pwd))
return true;
else
return false;
}
/**********密码修改**********/
protected void Set_Password() throws Exception
{
String pwd=null;
int counter=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
do {
System.out.println("请输入旧密码:");
pwd=br.readLine();
if(act.get_Password().equals(pwd))
{
do {
System.out.println("请输入新密码:");
String pwd1=br.readLine();
System.out.println("请再次输入新密码:");
String pwd2=br.readLine();
if(!pwd1.equals(pwd2))
{
System.out.println("两次输入不一致,请再次输入.");
}
else
{
System.out.println("密码修改成功,请使用新密码.");
SysOpter();
}
}while(true);
}
}while(counter>3);
}
/**********锁定机器**********/
protected void Lock_Sys() {
System.out.println("对不起,您的操作有误,卡已被没收.");
JFrame tui=new JFrame("没收窗口");
Font f=new Font("楷体_GB2312",Font.BOLD,32);
Color c2=new Color(255,0,0);
JLabel label1=new JLabel("对不起,您的操作有误,卡已被没收!");
label1.setForeground(c2);
label1.setFont(f);
tui.add(label1);
tui.setBounds(500,100,700,300);
tui.setVisible(true);
tui.validate();
tui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
/**********结束系统**********/
protected void Exit_Sys() {
TuiChu tuichu=new TuiChu();
}
}
public class Text1
{
public static void main(String[] args)
{
KaiShi kaishi=new KaiShi();
}
}
搜索更多相关的解决方案:
jframe
----------------解决方案--------------------------------------------------------
程序代码:
/********** 登陆系统 **********/
protected void Load_Sys() throws Exception {
String card, pwd;
int counter = 0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
boolean flag = false;
do {
System.out.println("请输入您的信用卡号:");
card = br.readLine();
System.out.println("请输入您的密码:");
pwd = br.readLine();
if (!isRight(card, pwd)) {
System.out.println("您的卡号或密码输入有误.");
counter++;
} else{
SysOpter();
flag=true;
break;
}
} while (counter < 3);
if(!flag)
Lock_Sys();
}
系统登录的逻辑不对,假如输入1次就正确登录,退出时,又重新输入信号卡号,这个时候显示窗口的线程跟输入卡号的线程冲突,所以显示不了 protected void Load_Sys() throws Exception {
String card, pwd;
int counter = 0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
boolean flag = false;
do {
System.out.println("请输入您的信用卡号:");
card = br.readLine();
System.out.println("请输入您的密码:");
pwd = br.readLine();
if (!isRight(card, pwd)) {
System.out.println("您的卡号或密码输入有误.");
counter++;
} else{
SysOpter();
flag=true;
break;
}
} while (counter < 3);
if(!flag)
Lock_Sys();
}
----------------解决方案--------------------------------------------------------
恩,正常了。非常感谢!
----------------解决方案--------------------------------------------------------
回复 2楼 linjx0123
恩,正常了。非常感谢!----------------解决方案--------------------------------------------------------