Saturday, 19 November 2011

MySQL WorkBench

You need MySQL workbench to register on netbeans. As netbeans will by default not have Register MySQL db enabled for you. Configuring that would require the GUI tool for MySQL

Visit MySQL GUI Tools Downloads to download

Friday, 18 November 2011

What Are Web Services?

Web services are distributed application components that are externally available. You can use them to integrate computer applications that are written in different languages and run on different platforms. Web services are language and platform independent because vendors have agreed on common web service standards.
Web service applications are deployed to a Java EE application server, such as GlassFish / Sun Java System Application Server.
This page provides links to some of the NetBeans documents and resources that can help you learn how to develop web service applications with NetBeans IDE.

Thursday, 17 November 2011

Older versions of Java can lead to security threats

Java is well documented. Java was “responsible for between one-third and one-half of all [recent] exploits.” Over the past six month Java was found to be the most common exploit vector in all the cases
Read more about Java and the security threats

Thursday, 10 November 2011

Automatic window lifecycle management

A further major advantage of the NetBeans Window System is that it provides a WindowManager that controls the lifecycle of all the windows defined in the application. The WindowManager notifies allTopComponents about state changes using callback methods, listed as follows:

componentOpened()It is called after the TopComponent has been opened. If multiple TopComponents are opened into the same position (called mode), the NetBeans Window System uses a tabbed container, with one TopComponent per tab. Of all available TopComponents found within a shared tabbed container, only the content of the selected TopComponent is visible.
componentShowing()It notifies the component that its content is now visible. This TopComponent is now either selected or is the only component in a separate container.
componentActivated()It is called after the TopComponent has gained the input focus or has become the selected component.
componentDeactivated()It is called after the TopComponent has lost the input focus.
componentHidden()It notifies the TopComponent that its content is no longer visible.
componentClosed()It is called after the TopComponent has been closed.
Let's illustrate this lifecycle via an example that logs all the callback methods to the output window of NetBeans IDE, which is your development environment on top of the NetBeans Platform.
  1. Create a new NetBeans Platform application and name it WindowSystemExamples.
  2. Add a new module named LifeCycle, with Code Name Base com.netbeansrcp.lifecycle.
  3. Add a TopComponent, with Class Name Prefix prefix LifeCycleDemo, making sure to indicate that it should be automatically opened in the editor area at application startup.
  4. Override the lifecycle methods as follows:
    public void componentOpened() { super.componentOpened(); System.out.println("componentOpened()"); } protected void componentShowing() { super.componentShowing(); System.out.println("componentShowing()"); } protected void componentActivated() { super.componentActivated(); System.out.println("componentActivated()"); } @Override protected void componentDeactivated() { super.componentDeactivated(); System.out.println("componentDeactivated()"); } @Override protected void componentHidden() { super.componentHidden(); System.out.println("componentHidden()"); } @Override public void componentClosed() { super.componentClosed(); System.out.println("componentClosed()"); }
Start the new application. The TopComponent LifeCyleDemoTopComponent is automatically opened at startup. Select the TopComponent and inspect the output in the NetBeans IDE Output Window. You should see the following:
componentOpened() componentShowing() componentActivated()
The TopComponent has passed the first half of its lifecycle and is now activated.
Close the LifeCyleDemoTopComponent and inspect the output again, to understand the second half of the TopComponent lifecycle. You should see the following output:
componentHidden() componentDeactivated() componentClosed()
You have learned that the TopComponent's lifecycle is automatically controlled by the NetBeans Platform. Between the start and the end of the TopComponent's lifecycle are six different states, all managed by the NetBeans Platform, and with notifications sent via callbacks.

Programmatically managing the Window lifecycle

You can manage the lifecycle of a TopComponent programmatically. For this purpose, theTopComponent provides the following methods:
  • open(): Opens the TopComponent
  • requestVisible(): Requests to select to TopComponent
  • requestActive(): Requests to transfer the input focus to the TopComponent
Let's now modify the LifeCycleDemoTopComponent for demonstration purposes.
  1. Add a JButton to the TopComponent, as follows:
  2. Implement an ActionEventListener as follows:
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { this.close(); RequestProcessor.getDefault().post(new java.lang.Runnable() { public void run() { java.awt.EventQueue.invokeLater(new java.lang.Runnable() { public void run() {; } }); } }, 3000); RequestProcessor.getDefault().post(new java.lang.Runnable() { public void run() { java.awt.EventQueue.invokeLater(new java.lang.Runnable() { public void run() { com.netbeansrcp.lifecycle. LifeCycleDemoTopComponent.this.requestActive(); } }); } }, 6000); }
  3. Restart the application. When you click the button, the LifecycleDemoTopComponent is closed via the close() method, called above in the first line of the code you entered.
The RequestProcessor provides a thread pool. The default instance of this pool lets you execute aRunnable after a short delay, thanks to the post() method. As the TopComponent's lifecycle method should be called from the AWT event thread, you do not call them directly in the run() method, but by posting a new Runnable to the EventQueue, which in the end calls the Window System API methods.
The argument 3000 ensures that the execution of the Runnable is delayed for 3000 ms so that theTopComponent is opened again after 3 s.
After six seconds the second Runnable posted to the EventQueue is executed and requestActive() is called for your LifecycleDemoTopComponent. Your TopComponent is now shown in the foreground, if it had been behind other windows previously.
You have learned how to manage the lifecycle of a TopComponent. Via the example you have seen how to open a TopComponent and make it focusable.

Positioning of windows

The NetBeans Window System divides the available space in the main window into areas that are called "modes". Each mode represents a specific area of the main window, providing a container for windows in a predefined position in the frame. You can add windows, that is, TopComponents, to a mode, either declaratively or programmatically.
A standard layout is provided by the NetBeans Window System, corresponding to the layout of NetBeans IDE. For example, the predefined modes correspond to the names used in the corresponding positions in NetBeans IDE, such as "editor" and "explorer". If needed, you can define your own modes, too. No wizard is provided for this purpose in NetBeans IDE, so you need to create the mode definition files yourself manually.
In the previous section you learned about the layer.xml file. To create a default layout for an application, each TopComponent needs to be declaratively registered within the Windows2 | Modes folder, within a subfolder named after the mode in which the TopComponent should be docked.
To demonstrate declarative registration of TopComponents, edit the layer.xml in the LifeCycle module, changing the folder name Windows2 | Modes | editor to Windows | Modes | rightSlidingSide, as shown in the following code snippet:
layer.xml // <folder name="Windows2"> <folder name="Components"> <file name="LifecycleDemoTopComponent.settings" url="LifecycleDemoTopComponentSettings.xml"/> </folder> <folder name="Modes"> <folder name="rightSlidingSide"> <file name="LifecycleDemoTopComponent.wstcref" url="LifecycleDemoTopComponentWstcref.xml"/> </folder> </folder> </folder> //
Select Clean and Build on the application node in the Projects window, to remove the build folder containing the last used window layout, and start the application again. When the application starts up, notice that the LifecycleDemoTopComponent is not opened in the editor mode. Instead, it is represented by a button on the right sidebar of the application (as shown in the screenshot below). That is therightSlidingSide mode, providing a container for minimized windows.
As you have seen, providing a default layout via declarative registrations of TopComponents is rather easy. You only need to create an entry in the layer.xml for the TopComponent, in a folder with the name of the desired mode, within the Windows2 | Modes folder.
Sometimes declarative registration alone is too static for your business needs. Fortunately, positioning ofTopComponents can also be done programmatically. In the next example, you create a TopComponentthat moves to new modes via a click of a button.
  1. Add to the WindowSystemExamples application a new module named Modes, with the Code Name Base com.netbeansrcp.modes.
  2. Within the module, create a TopComponent called ModesDemo, which is opened when the application starts into the "editor" mode.
Add two JButtons to the TopComponent with the texts Back and Forward, as well as a JLabel with an empty initial text. The TopComponent should look as shown in the following screenshot:
In the Source view, add the following code:
private static final String[] MODES = new String[] { "properties", "commonpalette", "rightSlidingSide", "bottomSlidingSide", "output", "debugger", "navigator", "explorer", "leftSlidingSide", "editor" }; private void changeMode(boolean next) { Mode currentMode = WindowManager.getDefault().findMode(this); String currentModeName = currentMode.getName(); String nextModeName = "editor"; for (int i = 0; i < MODES.length; i++) { String modeName = MODES[i]; if (modeName.equals(currentModeName)) { if (next) { nextModeName = (i + 1 < MODES.length) ? MODES[i + 1] : MODES[0]; } else { nextModeName = (i - 1 >= 0) ? MODES[i - 1] : MODES[MODES.length - 1]; } break; } } Mode nextMode = WindowManager.getDefault().findMode(nextModeName); if (nextMode != null) { this.jLabel1.setText(nextModeName); nextMode.dockInto(this);; this.requestActive(); } } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { this.changeMode(true); } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { this.changeMode(false); }
The static string array contains the names of the most important modes. These modes can also be identified dynamically, by calling WindowManager.getDefault().getModes().
The ActionListener delegates the call to the method changeMode() and gives the desired back/forward direction. This method determines via WindowManager.getDefault ().findMode (this) the mode in which theTopComponent is displayed, as well as the name of the current mode.
The string array is then searched and dockInto(this) is called to dock the TopComponent into a different mode.
How to revert to the default layout?
As the layout of the NetBeans Platform is persisted when the application shuts down, first perform a Clean and Build on the application project. With the removal of the build folder, the layout settings are also deleted, so that the default layout is used when the application starts again.
Using the two buttons, you can let the TopComponent be docked in some of the most commonly used modes (as shown in the screenshot below).
You have programmatically docked a TopComponent into various places within the available modes in the application. In the process, you have learned how TopComponents can be docked dynamically, that is, at runtime, into desired positions. Both the declarative and the programmatic approaches to docking should now be familiar to you.

Creating global actions - Netbeans Platform 6.9.1

Understand Netbeans Platform 6.9.1 : Working with Action first

Let’s start by creating an Action to add new TopLevelTasks. It will create a new Task and display it in theTaskEditorPanel. The wizard that you will use in this section will simply create a new ActionListener and register it in the layer.xml file.

  1. Right-click the TaskEditor module project node and choose New | Action. Choose Always Enabled as the Action type as shown in the following screenshot. Click Next>.
    NetBeans Platform 6.9: Working with Actions
  2. Choose Edit as the category of the Action, which determines where in the Options window's Keymap section it will be displayed.
  3. Check the Global Menu Item checkbox. Now you can specify where the Action should appear in the menu bar. Choose Edit and then choose any position you want within the Edit menu. ClickNext>.
    You do not need to insert the Action in the toolbar at this time, nor assign a keyboard shortcut.
    NetBeans Platform 6.9: Working with Actions
  4. Name the Action NewTaskAction, with New as the Display Name. Optionally, specify an icon.
    NetBeans Platform 6.9: Working with Actions
  5. The actionPerformed method of the generated class NewTaskAction should create a new task and display it in a TaskEditor. Therefore, implement the method as follows:
    public void actionPerformed(ActionEvent e) { TaskManager taskMgr = Lookup.getDefault().lookup(TaskManager.class); if (null != taskMgr) { Task task = taskMgr.createTask(); TaskEditorTopComponent win = TaskEditorTopComponent.findInstance(task);; win.requestActive(); } }
  6. Run the application again. In the Edit menu there is now a New menu item. When you select the menu item, a new task is created in the TaskEditor.
To summarize, you have used the New Action wizard to create and register a new global action.

Examining the created files

The wizard created a simple ActionListener and registered it declaratively in the layer.xml file. As a result, the Actions folder now has an Edit subfolder, with this content in the layer.xml file:
<folder name="Actions"> <folder name="Edit"> <file name="com-netbeansrcp-taskeditor-NewTaskAction.instance"> <attr name="delegate" newvalue="com.netbeansrcp.taskeditor.NewTaskAction"/> <attr name="displayName" bundlevalue="com.netbeansrcp. taskeditor.Bundle#CTL_NewTaskAction"/> <attr name="iconBase" stringvalue="com/netbeansrcp/taskeditor/icon.png"/> <attr name="instanceCreate" methodvalue="org.openide.awt.Actions.alwaysEnabled"/> <attr name="noIconInMenu" boolvalue="false"/> </file> </folder> </folder>
Below the Edit folder, you see that an .instance file has been registered. That file represents an instance of the class for which it is registered. A set of attributes have been defined for the file:
The task to be performed when the Action is invoked.
displayNameThe name of the Action, optionally pointing to a key in a bundle file.
iconBaseThe location of the icon displayed for the Action.
instanceCreateThe instance created by the Action registration.
noIconInMenuTrue if the Action does not display an icon.
In addition to the Action registration, the wizard has also created a Menu registration in the layer.xml file:
<folder name="Menu"> <folder name="Edit"> <file name="com-netbeansrcp-taskeditor-NewTaskAction.shadow"> <attr name="originalFile" stringvalue="Actions/Edit/ com-netbeansrcp-taskeditor- NewTaskAction.instance"/> <attr name="position" intvalue="100"/> </file> </folder> </folder>
Within the Edit menu, a shadow file has been registered. Shadow files do not represent an instance, but serve as a symbolic reference, which is a familiar concept from the Unix world. If the Action instance had been directly attached to the menu, deleting the menu registration would cause the removal of the Actionalso. Thanks to the shadow files, removing the menu registration does not mean that the Actionregistration itself is removed, as the Action is registered separately. Also, when you decide to let the user invoke the Action from a toolbar or keyboard shortcut, you will again use shadow files. The Action will then be instantiated once, not each time it is invoked from the various places where the user invokes it from.

Enabling Users to Invoke actions

Let us now allow the user to invoke the action from both a toolbar button and a keyboard shortcut. After all, you can connect Actions to a variety of places. Actions are often attached, for example, to context menus within Explorer views, files of certain MIME types, or the editor. Often these Actions only make sense if they react in a context-sensitive way to the element from whose context menu they are called. This too is supported by the NetBeans Platform.
In this case, though, you simply want to have the Action always enabled and present in the toolbar, as well as from the menu bar where it is already found.


You have already seen how Actions are attached to menus. All that is involved is registering the corresponding Action class in the appropriate position in the layer.xml file. The same approach applies to toolbar buttons, where a new toolbar button is registered within a subfolder of the Toolbars folder, as follows in the layer.xml file:
<folder name="Toolbars"> <folder name="Edit"> <file name="com-netbeansrcp-taskeditor-NewTaskAction.shadow"> <attr name="originalFile" stringvalue="Actions/Edit/com netbeansrcp-taskeditor-NewTaskAction.instance"/> </file> </folder> </folder>
Toolbar buttons must have an icon
For toolbar buttons, it is important that you register an Action for which an icon has been registered in the layer.xml file. Otherwise no icon will be shown for the Action in the toolbar.
Run the application. The Action is now visible in the Edit toolbar.
In summary, you have attached an Action declaratively to a toolbar. You simply had to add a shadow file entry to the relevant location in the layer.xml file.


Actions can be triggered by pressing key combinations on a keyboard. As with menus and toolbars, a keybinding is implemented within the NetBeans Platform declaratively. The relevant folder in this case isShortcuts, while the file that you need to register there is again a shadow file.
Consequently, the name of the shadow file does not relate to the name of the Action that is to be triggered, but instead indicates the key combination in an Emacs-like notation, consisting of a modifier followed by a key designator. A hyphen is required between the modifier and designator.
The valid modifiers are listed as follows:
C—Ctrl key
A—Alt key
S—Shift key
M—Meta key, for example, Command button
As the Ctrl key on the Mac is different to what it is on a conventional PC, the NetBeans Platform further provides us a wildcard, with a corresponding key that varies depending on the operating system:
D—Standard Acceleration Key(for example, PC: Ctrl Key, Mac: Command Key)
O—Alternative Acceleration Key(for example, PC: Alt Key, Mac: Ctrl Key)
As a key designator, the name of each key constant is derived from java.awt.event.KeyEvent, with the leading VK_ of the constant name removed.
You now want to bind your action to the key combination standard accelerator key-A, which on the Mac isCommand-A, while on the PC it is Ctrl-A.
Following the preceding description, register the Action to be invoked from a shortcut as follows in thelayer.xml file:
<folder name="Shortcuts"> <file name="D-A.shadow"> <attr name="originalFile" stringvalue="Actions/Edit/ comnetbeansrcp-taskeditor-NewTaskAction.instance" /> </file> </folder>
Run the application again. Press Ctrl-A on a PC or Command-A on a Mac. When you do so, you should see that the TaskLog registers the creation of a new task.
In summary, you have now declaratively bound an Action to a keyboard shortcut.

Environment for PHP Development in Window

This tutorial shows you two ways of configuring your PHP development environment on the Windows operating system. The first and most convenient way is to install and configure an AMP (Apache, MySQL, PHP) package

Using XAMP Package

Apache HTTP Server
  1. Download the Apache2 HTTP server.
  2. Run the installation file .msi. The installation wizard starts. Follow the instructions.
  3. When the installation is completed, restart the Apache server.
  4. To check that the installation is successful, run the browser and enter http://localhost/ in browser
    The welcome test page should open: 


By default, the Apache server listens to port 80. This port can be already used by other services, for example Skype. To solve the issue, change the port which the server listens to:
  1. Open the Apache web server configuration file httpd.conf. By default the file is located in C:\Program Files\Apache Software Foundation\Apache<version>\conf\
  2. Locate the line Listen 80 and change the port number, for example 8080. Save the file.
  3. Restart the Apache web server.
  4. To check that the web server works, run the browser and enter the URL and specify the port number explicitly: http://localhost:8080

PHP Engine

  1. Download the PHP5 engine.
  2. When the download is complete, run the .msi installation file. The installation wizard starts.
  3. On the Apache Configuration Directory panel, specify the directory where the httpd.conf file is located, the default setting is C:\Program Files\Apache Software Foundation\Apache<version>\conf\. The PHP processing will be enabled automatically.
  4. If you want to use the MySQL database server, choose the Complete installation option or select the MySQL and MySQLi items in the Extensions list.
  5. After the installation is completed, restart the Apache server.
  6. To check that the PHP engine has been installed successfully and PHP processing has been enabled in the Apache configuration:
    • In the Notepad, create a file and type the following text:
    • <?php 
           echo "PHP has been installed successfully!";
    • Save the file in the htdocs folder: C:\Program Files\Apache Software Foundation\Apache<version>\htdocs\test.php
    • Run the browser and enter the following URL: http://localhost:<port>/test.php. The following message should appear "PHP has been successfully installed"


If the page does not open:
  1. Restart the Apache server.
  2. Check that the Apache server configuration file httpd.conf contains the following lines:
      AddType Application/x-httpd-php .php 
      LoadModule php5_module "c:/php/sapi/php5apache2_2.dll"
  3. If the lines are missing, add them, save httpd.conf, and restart Apache.
  4. Refresh the http://localhost:<port>/test.php page.


  1. Download XDebug.
  2. Install XDebug into the php/ folder. 

Set Up the Environment

  1. With default settings, PHP processing will be enabled automatically.
  2. To attach XDebug to the PHP engine, find the php.ini file and add the following lines to it:
    For a thread-safe PHP 5.2 engine:
  3. zend_extension_ts="<path to the php folder>/php_xdebug-<version-number>.dll"
    For a non-thread-safe PHP 5.2 engine:
    zend_extension_nts="<path to the php folder>/php_xdebug-<version-number>.dll"
    For any PHP 5.3 engine:
    zend_extension="<path to the php folder>/php_xdebug-<version-number>.dll"
    Some users also find that they need to include the following lines, although other users do not:
    ; Port number must match debugger port number in NetBeans IDE Tools > Options > PHP
    Make sure the paths you specify match the names and locations of the corresponding files as determined during your installation.
  4. To be sure that previously installed PHP engine supports using the MySQL database server:
    1. Click Start > Control Panel.
    2. On the Control Panel, choose Add or Remove Programs.
    3. On the Add or Remove Programs panel, select the PHP <version number> area and click Change. The PHP Setup Wizard starts. Click Next.
    4. On the Change, repair or remove installation panel, choose Change and click Next.
    5. On the Web Server Setup panel, choose the version of the Apache server - in our example it is Apache 2.2.x Module. Click Next.
    6. On the Apache Configuration Directory panel, specify the directory where the Apache configuration file httpd.conf is located. Click Next.
    7. On the Choose Items to Install panel, expand the Extensions node and choose the MySQL and MySQLi items. Click Next.
    8. On the Ready to change PHP <version number> panel, click Change.
    9. On the Completed the PHP <version number> Setup Wizard panel, click Finish.

NetBeans IDE 7.0.1 release

NetBeans IDE 7.0.1 Release Information

The NetBeans IDE is an award-winning integrated development environment available for Windows, Mac, Linux, and Solaris. The NetBeans project consists of anopen-source IDE and an application platform that enable developers to rapidly create web, enterprise, desktop, and mobile applications using the Java platform, as well as PHP, JavaScript and Ajax, Groovy and Grails, and C/C++.
The NetBeans project is supported by a vibrant developer community and offers extensive documentation and training resources as well as a diverse selection of third-party plugins.

Release Overview

NetBeans IDE 7.0 introduces language support for development to the Java SE 7 specification with JDK 7 language features. The release also provides enhanced integration with the Oracle WebLogic server, as well as support for Oracle Database and GlassFish 3.1. Additional highlights include Maven 3 and HTML5 editing support; a new GridBagLayout designer for improved Swing GUI development; enhancements to the Java editor, and more.
NetBeans IDE 7.0 is available in English, Brazilian Portuguese, Japanese, Russian, and Simplified Chinese.