Saturday, September 24, 2011

NetBeans: Setting Events With the Connection Wizard

Connection wizard can help to set events between two components within a form without having to write code manually.

Work on the exercise in last post "HelloNetBeans: Create Java Desktop Application using NetBeans IDE".

- Add a Button on Design Pane
- Right click on Button, Edit Text and enter "Click Me" as the text on the button.
Add a Button

- Switch Connection Mode.
Switch Connection Mode

- Select the component (JButton1) that will fire the event, the selected component is highlighted in red when selected.
- Select the component (JLabel1) whose state you want to affect with the event.
- NetBeans will open Connection Wizard.

- Accept jButton1 as Source Component.
- Expand and select mouse -> mouseClicked as the source Events, with jButton1MouseClicked as Method Name in Event Handler Method.
- Click Next.
Select Source Event

- Accept jLabel1 as Target Component.
- Select Set Property.
- Select text. and click Next.
Specify Target Operation

- Select and Enter Value of any text you want, and click Finish.
Enter Parameters

- NetBeans will generate the code for you.
Code generated by Connection Wizard

- Save and Run it again.
Application Run

2 comments:

  1. hey i want that when i click the browse button which i have created, swing windows named "file chooser" appear on the screen . so please guide me how to do that
    i shall be vary thankful to you if you just email the answer with snapshots please
    email:princeumair10@gmail.com

    ReplyDelete