开发者

Swing event architecture

I'm building a rich client application based on Swing. And I'm wondering what is the best architecture for event's handling.

My classes are :

  • MyFrame
  • FirstPanel, with a jbutton
  • SecondPanel with a jLabel
开发者_如何学C

I start the application with a FirstPanel within a MyFrame.

Then, I add an action listener to the button in the FirstPanel, and I whant this action to (1) close the FirstPane then (2) open a new SecondPanel in the running MyFrame

How to do it ?

Edit - Example

I want to show at startup a list of users, stored in a file, then the user click on his name or click on "new user". When he clicks on "new user", a second panel appears, with a form to create a new user and store it in the file.

In this example, MyFrame is the main frame, created by the main() method.

Then the ListUsersPanel appears.

Then, the NewUserPanel appears if I click on "new user".

My question is : how do I design my classes/listeners to manage all this ?

** Edit - example 2 ** What if I have a JFrame that contains 2 JPanels, and I want a button in Panel1 that change a label in Panel2 ?


In this situation normally you just use a modal JDialog to display the new user form. Might need to refresh your list of users once the new form has been completed and the dialog is closed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜