Desarrollaremos un simple plugin para NetBeans que verifica si un sitio web esta activo, es un modulo de carácter educativo por lo cual me he enfocado en la simplicidad desarrollando Action atraves de clases directas sin utilizar el asistente Action.
Creamos un proyecto Modulo

Indicamos el nombre

indicamos el nombre del paquete ,marcamos Generar capa XML
![]()
El IDE crea el proyecto

Crear una clase MyAccion.java

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
Definimos los tipos de
mensajes a desplegar
/**
*
* @author avbravo
*/
public class MyAccion implements ActionListener {
public void actionPerformed(ActionEvent e) {
// TODO implement action body
String msg = "Servidor Gbi funcionando!";
int msgType = NotifyDescriptor.INFORMATION_MESSAGE;
int msgTypeError = NotifyDescriptor.ERROR_MESSAGE;
try {
URL url = new URL("http://www.google.com/");
URLConnection urlConnection = url.openConnection();
Indicamos el sitio a conectarse
BufferedReader in = new BufferedReader(new
InputStreamReader(urlConnection.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
//System.out.println("" + inputLine);
break;
}
Mensaje("Conexión a google exitosa", msgType);
} catch (MalformedURLException me) {
Mensaje("MalformedURLException: " + me.getLocalizedMessage().toString(),
msgTypeError);
} catch (IOException ioe) {
Mensaje("IOException: " + ioe.getLocalizedMessage().toString(), msgTypeError);
}
}
private void Mensaje(String msg, int msgType) {
try {
NotifyDescriptor d = new NotifyDescriptor.Message(msg, msgType);
DialogDisplayer.getDefault().notify(d);
} catch (Exception ex) {
}
}
}
Agregamos las bibliotecas

Agregamos una imagen de 16x16 pixeles

Editamos el archivo layer.xml

Instalamos el plugin

Se carga el icono en el barra del IDE

Al darle click nos muestra el mensaje
Creamos un proyecto Modulo

Indicamos el nombre

indicamos el nombre del paquete ,marcamos Generar capa XML
El IDE crea el proyecto

Crear una clase MyAccion.java

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
Definimos los tipos de
mensajes a desplegar
/**
*
* @author avbravo
*/
public class MyAccion implements ActionListener {
public void actionPerformed(ActionEvent e) {
// TODO implement action body
String msg = "Servidor Gbi funcionando!";
int msgType = NotifyDescriptor.INFORMATION_MESSAGE;
int msgTypeError = NotifyDescriptor.ERROR_MESSAGE;
try {
URL url = new URL("http://www.google.com/");
URLConnection urlConnection = url.openConnection();
Indicamos el sitio a conectarse
BufferedReader in = new BufferedReader(new
InputStreamReader(urlConnection.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
//System.out.println("" + inputLine);
break;
}
Mensaje("Conexión a google exitosa", msgType);
} catch (MalformedURLException me) {
Mensaje("MalformedURLException: " + me.getLocalizedMessage().toString(),
msgTypeError);
} catch (IOException ioe) {
Mensaje("IOException: " + ioe.getLocalizedMessage().toString(), msgTypeError);
}
}
private void Mensaje(String msg, int msgType) {
try {
NotifyDescriptor d = new NotifyDescriptor.Message(msg, msgType);
DialogDisplayer.getDefault().notify(d);
} catch (Exception ex) {
}
}
}
Agregamos las bibliotecas

Agregamos una imagen de 16x16 pixeles

Editamos el archivo layer.xml

Instalamos el plugin

Se carga el icono en el barra del IDE

Al darle click nos muestra el mensaje

Comments