java 内部窗口,用Java制作窗口

;) I'm trying to do a sequence of GUI windows in Java. Firstly, question about the design. I'm planning to have 8/9 similar types of windows:

a greeting intro with a timer

after few second of displaying the above - a window like "enter ur name" "enter ur surname"

question window with two radiobuttons

"enter ur password" window

window with just plain text and "next" button (apart from the 1st one, they all have it)

a window with some text and then a bit that can be copied with "copy" button next to it

same as the 2nd one, but with "paste" button next to one of the entries

a pop exit window

big window displaying names, numbers and rectangular shapes

I thought about doing one abstract class "DummyWindow" which would be the base for any other one and then expand it. What do you say? Also, what would you advise regarding the actual code approach to the windows? Thanks a lot.

解决方案

So you'll want to use Swing. Here is a simple hello world demo you can copy and paste.

For what you're doing you'll want to look at using CardLayout. CardLayout makes creating wizards, like the one you describe, very simple. I'd create several subclasses of JPanel for each individual screen you plan on displaying. Those series of JPanel can be added together in a larger JPanel using CardLayout. Each of the sub-screens will be an individual screen that is displayed alone. Then that larger panel can be face-plated on a JFrame or JDialog.

I also recommend using TableLayout over GridBagLayout, GridLayout, nested BoxLayout which is provided in Swing. You can learn about TableLayout here and download it:

I usually subclass things like JPanel for window-like things because JPanel is just a simple container, and that can be added to JFrame, JDialog, etc without any internal changes. If you subclass JFrame, JWindow, or JDialog you can only ever be that. JPanel gives you flexibility.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值