J2SE 关于JPanel的页面跳转问题
小弟目前在用Swing做一个桌面应用程序遇到一个问题就是JPanel的页面不能正常跳转。
比如下面的代码:
else if ("确定出票" == ((JButton) btn).getName()) {
if (btn == e.getSource()) {
System.out.println("确定出票被点击了");
TvmFrame.getInstance().remove(StationCashTicket.getInstance());
TvmFrame.getInstance().remove(StationCardTicket.getInstance());
TvmFrame.getInstance().remove(PriceCardTicket.getInstance());
TvmFrame.getInstance().remove(PriceCashTicket.getInstance());
TvmFrame.getInstance().add(Ticketing.getInstance()); //始终不能正常的跳到这个页面
TvmFrame.getInstance().repaint();
if (sellingOneWayTicket.sellTickets()) {
System.out.println("开始压币");
coinModulServiceImpl.startManage();
coinModulServiceImpl.stopManage();
} else {
// 当机器出现故障出票失败时将硬币全部退出
coinModulServiceImpl.changeCoin(coinModulServiceImpl.get1NoOfCoin(),0);
coinModulServiceImpl.outCoin();//很多时候都如果出现问题的话都是直接跳到这个页面,上面红色字体的那个页面直接过了
}
}
} else if ("重选站台" == ((JButton) btn).getName()) {
按照逻辑应该是先跳到Ticketing这个页面然后根据sellingOneWayTicket.sellTickets()的执行过程跳到另外一个页面
sellTickets的代码如下:
public boolean sellTickets() {
try {
if (cardSenderService.establishCommu()) {
System.out.println("建立通信成功!");
if (Calculatefares.totalTicketPrice == Calculatefares.coinNumber) {
System.out.println("投币金额足够");
System.out.println("Calculatefares.ticketNumber :"+Calculatefares.ticketNumber );
while (Calculatefares.ticketNumber > 0) {
if (cardSenderService.issueCardToCardreader()) {
System.out.println("出票到写卡器");
if (ticketCardReaderService.writeCard()) {
System.out.println("写卡成功");
if (cardSenderService.issueCardToOutlet()) {
//出卡到客户成功
System.out.println("出票到客户");
TvmFrame.getInstance().remove(Ticketing.getInstance());
TvmFrame.getInstance().add(TicketSuccess.getInstance());
TvmFrame.getInstance().repaint();
Thread.sleep(1000);
TvmFrame.getInstance().remove(TicketSuccess.getInstance());
TvmFrame.getInstance().add(Map.getInstance());
TvmFrame.getInstance().add(TicketPanel.getInstance());
TvmFrame.getInstance().add(StationPanel.getInstance());
TvmFrame.getInstance().add(LinePanel.getInstance());
// ThreadPool.getInstance().getThreadPool().execute(TicketNumberHandler.calculatefares); // 购票线程,当客户选择站点后开启
} else {
//出卡到客户失败
TvmFrame.getInstance().remove(Ticketing.getInstance());
TvmFrame.getInstance().add(Error.getInstance());
TvmFrame.getInstance().repaint();
cardSenderService.callBackCard();
Thread.sleep(1000);
return false;
}
} else {
// 写卡失败
TvmFrame.getInstance().remove(Ticketing.getInstance());
TvmFrame.getInstance().add(Error.getInstance());
TvmFrame.getInstance().repaint();
return false;
}
} else {
// 出票到读卡器失败
TvmFrame.getInstance().remove(Ticketing.getInstance());
TvmFrame.getInstance().add(Error.getInstance());
TvmFrame.getInstance().repaint();
return false;
}
Calculatefares.ticketNumber--;
Thread.sleep(300);
}
}
} else {