January 27, 2021
Hot Topics:

Integrating your Java Application with Existing Network Management Solutions with JMX

  • By Olexiy & Alexander Prokhorenko
  • Send Email »
  • More Articles »

Layer of Distributed Services

Last but not least from the considerable number of layers is the layer of management distributed services. This layer provides the interface that is being used by remote tools to interact with agents.

So, we have very briefly considered the structure of the JMX framework, have received some information on what is necessary and what its basic functions are. Next, we will disassemble the practical use of this technology with a concrete example.

Example of a "controled" application

As an example, we shall consider the ordinary GUI Java application: an applet. This applet will contain only one element, JLabel. As a matter of fact, this applet represents a non-functional window with a text label. With the help of JMX, we will have an opportunity to operate the contents of this label. The appearance of our extremely simple applet is shown below:

All code is divided into two parts (two classes): MainApp.java is a class that represents a launching pad of our window and that contains the main() static method; and CounterFrame.java is a class of frame in which, except for elements of a window, a private property counterValue of int type is also defined; it is responsible for storing the current counter value that is displayed in label in our frame. The setCounterValue() and getCounterValue() methods serve for setting and getting the counter's value, and the incCounterValue() and decCounterValue() methods are intended for increasing and decreasing of counter's value by 1. All these methods, except for getCounterValue(), automatically update the contents of our label with the counter.

You can examine source code:

// MainApp.java
import java.awt.*;
import javax.swing.UIManager;

public class MainApp {
   private boolean packFrame = false;

   public MainApp() {
      CounterFrame frame = new CounterFrame();
      if (packFrame) 

      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      Dimension frameSize = frame.getSize();
      if (frameSize.height > screenSize.height) 
         frameSize.height = screenSize.height;
      if (frameSize.width > screenSize.width)
         frameSize.width = screenSize.width;
      frame.setLocation((screenSize.width - frameSize.width) / 2, 
                        (screenSize.height - frameSize.height) / 2);

  public static void main(String[] args) {
     try {
     } catch (Exception e) {
     new MainApp();

// CounterFrame.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class CounterFrame extends JFrame implements CounterFrameMBean {
   private JPanel contentPane;
   private JLabel jLabel1 = new JLabel();
   private int counterValue = 0; 

   public CounterFrame() {
      try {
      } catch (Exception e) {

   private void init() throws Exception {
      contentPane = (JPanel) this.getContentPane();
      contentPane.setLayout(new BorderLayout());
      this.setSize(new Dimension(400, 300));
      jLabel1.setFont(new java.awt.Font("Dialog", 0, 24));
      setCounterValue(new Integer(0));
      this.getContentPane().add(jLabel1, BorderLayout.CENTER);

   protected void processWindowEvent(WindowEvent e) {
      if (e.getID() == WindowEvent.WINDOW_CLOSING) {

   public Integer getCounterValue() {
      return new Integer(counterValue);

   public void setCounterValue(Integer value) {
      counterValue = value.intValue();

   public void incCounterValue() {

   public void decCounterValue() {

Page 2 of 3

This article was originally published on July 1, 2004

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date