NetBeans4 Developing GUI Practice

xiaoxiao2021-03-06  65

Before using NB4, I tried Eclipse's VE, not easy, and the speed is a bit slow. The most critical is no key components I want to use: JLAYEREDPANE. In the following section, I will use NB4 Beta2 (JDK5.0) to do a small GUI program to simulate the View Stack effect. What is View Stack? There is a Container called Viewstack in Flex, which manages multiple views, and easy to switch, this thing is useful when design interface. Viewstack is like JlayeredPane in Java Swing.

First open NetBeans, create a new Java Application, named JViewStackDemo (the hook before the Create Main Class)

Then create a JFrame from this new Application, name to main

NB automatically switches to the Form Designer status, select JLayeredPane in JLRAME in Swing Palette. This JlayeredPane is our viewstack.

Set the size of JLAYEREDPANE: 400x300

Add 3 JPanel to JLAYEREDPANE, treat them as views in our viewstack. This should be like this after the operation.

Add a JLabel to each Panel to identify, I started "View One", "View TWO", "View Three"

Set the size of Panel to 400x300

Add menubar to JFrame, build a menu to control the content displayed in the ViewStack. Click Test Form to see

Ok, now you have written the code, find this class in the Projects view, right click on the Methods: HideallViewsBut, this method takes a parameter: Component But This view.

After adding, enter the source code editing area, see if there is an error message, not finding the COMPONENT definition, we can use the NB's Fix Imports feature to fix this problem.

In this picture, we can see the NB code prompt function, as well as Javadoc prompts.

HideAllViewsbut after completion.

Tall back, add an event handler to the MenuItem in the Inspector in the Form Designer, and double-click MenuiteM, NB will automatically generate related code.

Complete each MenuItem to implement the switch of the View.

Tap, press F6, compile the running screen

Executable Program (JAR) Download:

20041006-jviewstackDemo.jar Source code download:

20041006-JViewStackDemo.rar

转载请注明原文地址:https://www.9cbs.com/read-110114.html

New Post(0)