gpt4 book ai didi

java - 在frameview或主框架之前插入JDialog

转载 作者:行者123 更新时间:2023-12-01 19:10:25 29 4
gpt4 key购买 nike

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 可以通过除了登录之外不提供任何其他选项来强制用户登录,注册等

关于java - 在frameview或主框架之前插入JDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8606099/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com