在Java swing中切换屏幕 [英] Switching between screens in Java swing

查看:324
本文介绍了在Java swing中切换屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Android中为我的客户构建了大型应用程序. 新项目是用Java为PC构建相同的应用程序.所以我已经开始使用秋千进行开发. 在Android中构建时,我将类与具有内容视图的活动一起使用,并且可以在活动之间进行切换. 在Java中,我建立了多个扩展JFrame的类,并且希望在它们之间进行切换. 正确的方法是什么?

I had build big application for my client in Android. The new project is to build the same app for PC in Java. So i have started developing with use of swing. When building in Android i use classes with activities that had content views and i could switch between activities. In java i have build multiple classes that extends JFrame and i wish to switch between them. What is the right way to to this?

是这个

new_class.setVisible(true);
old_class.setVisible(false);

正确的方法?

推荐答案

使用Swing的一般方法是使用适当的策略(通常为CardLayout,但细节决定成败). 此GUI 显示了其他一些选项(JSplitPane和嵌套布局):

The general approach using Swing would be to either combine all the GUI elements 'screens' in one top level container using the appropriate strategy (generally a CardLayout, but the devil is in the details). This GUI shows some other options (JSplitPane & nested layouts):

另请参阅此答案.

对于逻辑上在 容器中的其他任何功能,请使用(可能)模式对话框或JOptionPane.例如.从主机架弹出的登录:

For any other functionality which would logically be in a different container, use a (possibly) modal dialog or a JOptionPane. E.G. a log-in, popped from the main frame:

要考虑的另一件事是,Swing(带有台式机显示器)使我们能够向用户提供更丰富的组件集.例如,通常通过在每个目录中使用一个列表来浏览Android SD卡文件系统,然后更改列表的内容或在输入新目录时进行查看.在Swing中,您可以为此使用一个JTree.因此,相比用于选项卡或电话的桌面GUI工具包,对不同屏幕"的需求要少得多.

Another thing to take into account is that Swing (with a desktop monitor) allows us to offer a richer set of components to the user. For instance, surfing around the Android SD card file system would generally be achieved by using one list per directory, and either changing the content of the list or view on entering a new directory. In Swing you might use a single JTree for that. So there is much less need for 'different screens' in a desktop GUI toolkit, over one designed to be used on a tab or phone.

这是文件浏览器中使用的树.

这篇关于在Java swing中切换屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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