在框架视图或主框架之前插入JDialog [英] Insert JDialog before frameview or main frame

查看:54
本文介绍了在框架视图或主框架之前插入JDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在frameview之前添加Jdialog ...我的frameview包含我的应用程序主页.我只想添加从用户处获取密码的Jdialog,然后在主框架中输入.谁能告诉我如何在java swing中实现这一目标?

i want to add Jdialog before frameview...my frameview consist of my main page of application. i just want to add Jdialog which get password from user and then enter in the Main frame. can any one tell me how can i achieve this in java swing??

推荐答案

MyMainPanel mainPanel = new MyMainPanel();
LoginPanel loginPanel = new LoginPanel();

JFrame mainApp = new JFrame();
mainApp.add( mainPanel );
mainApp.pack();
mainApp.setVisible(true);

JDialog dialog = new JDialog( mainApp, true );
dialog.add( loginPanel );
dialog.setVisible( true );

if( login.isAuthenticated() ) { // after dialog is dismissed we can set the user
    mainPanel.setAuthenticatedUser( loginPanel.getAuthenticatedUser() );
} else {
    System.exit(-1);
}

这将在您的主面板前面显示一个对话框,并且用户在登录之前将无法使用它,因为该对话框是模态的,而您的LoginPanel可以通过不提供任何其他选项(登录除外)来强制用户登录,注册等.

That will show a dialog in front of your main panel and the user won't be able to use it until they login because its modal, and your LoginPanel can force the user to login by not offering any other option but Login, Signup, etc.

这篇关于在框架视图或主框架之前插入JDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆