Swing中如何设置默认打开窗口?

发布于 2025-01-04 15:26:42 字数 354 浏览 3 评论 0原文

我有一个应用程序,对于两种不同类型的应用程序用户有两个不同的登录窗口,比如说一个是客户端,另一个是管理员,现在我想要一个选项在两个登录窗口上设置默认打开窗口,例如一个复选框,其标签为设置这是您的默认登录窗口..

我怎样才能实现这个目标?

我可以使用 .properties 文件来设置默认窗口吗? (以及如何?)

或者,首先加载并决定首先加载的默认 GUI 窗口的 Main.java 类?

我更喜欢第二种方式......但欢迎您的意见,也请提供一些示例代码来完成此任务。

I have an application that has two different login windows for two different types of users of application, say one is client and the other is administrator , now i want to have an option on both the Login windows to set the default opening window, something like a checkbox having label as set this is as your default Login window ..

How can i achieve this??

May i use a .properties file to set the default window? (and How?)

Or, a Main.java class which loads first and decides the default GUI window to load first??

I preferred the 2nd way...but your views are welcomed, also please provide some example codes to accomplish this task.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

没︽人懂的悲伤 2025-01-11 15:26:42

在两个登录窗口上添加 JCheckbox。当用户成功登录时,查找复选框的值,使用以下方法设置首选项:

private static enum LoginWindow {
    CLIENT, ADMIN;
}
...
Preferences prefs = Preferences.userNodeForPackage(this);
if (client.getSetAsDefaultCheckbox().getValue())
    prefs.put("PREF_WIND",LoginWindow.CLIENT.name());
else if (admin.getSetAsDefaultCheckbox().getValue())
    prefs.put("PREF_WIND",LoginWindow.ADMIN.name());

当您加载应用程序时:

Preferences prefs = Preferences.userNodeForPackage(this);
String prefWindow = prefs.get("PREF_WIND",null);
if (prefWindow!=null) {
    LoginWindow loginWindow = LoginWindow.valueOf(prefWindow);
    switch(loginWindow) {
    case ADMIN:
         // switch to admin
         break;
    case CLIENT:
         // switch to client
         break;
    }
} else
    // Default

add a JCheckbox on both login windows. When the user logs in succesfully, look up the value of the checkboxes, set a preference using:

private static enum LoginWindow {
    CLIENT, ADMIN;
}
...
Preferences prefs = Preferences.userNodeForPackage(this);
if (client.getSetAsDefaultCheckbox().getValue())
    prefs.put("PREF_WIND",LoginWindow.CLIENT.name());
else if (admin.getSetAsDefaultCheckbox().getValue())
    prefs.put("PREF_WIND",LoginWindow.ADMIN.name());

When you load your application:

Preferences prefs = Preferences.userNodeForPackage(this);
String prefWindow = prefs.get("PREF_WIND",null);
if (prefWindow!=null) {
    LoginWindow loginWindow = LoginWindow.valueOf(prefWindow);
    switch(loginWindow) {
    case ADMIN:
         // switch to admin
         break;
    case CLIENT:
         // switch to client
         break;
    }
} else
    // Default
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文