| career | drupal | java | mac | mysql | perl | scala | uml | unix  

JMeter example source code file (

This example JMeter source code file ( is included in the "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - JMeter tags/keywords

awt, border, end, end, graphaccum, graphaccummodel, graphaccumvisualizer, graphaccumvisualizer1, gui, image, jpanel, jpanel, jscrollpane, jscrollpane, start, start, string, swing

The JMeter source code

 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.

package org.apache.jmeter.visualizers;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.Image;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;

import org.apache.jmeter.samplers.Clearable;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jmeter.visualizers.gui.AbstractVisualizer;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;

 * This class implements a statistical analyser that plots the accumulated time
 * taken to load each set of pages. The number of plots is equivalent to the
 * number of times the set of pages is configured to load.
 * Created 2001/08/11
public class GraphAccumVisualizer extends AbstractVisualizer implements ImageVisualizer, GraphAccumListener, Clearable {
    private static final long serialVersionUID = 240L;

    private static final Logger log = LoggingManager.getLoggerForClass();

    protected transient GraphAccumModel model;

    protected transient GraphAccum graph;

    protected transient JPanel legendPanel;

     * Constructor.
    public GraphAccumVisualizer() {
        model = new GraphAccumModel();
        log.debug("Start : GraphAccumVisualizer1");
        log.debug("End : GraphAccumVisualizer1");

    public String getLabelResource() {
        return "graph_full_results_title"; // $NON-NLS-1$

    public void add(SampleResult res) {

     * Returns the panel where labels can be added.
     * @return a panel where labels can be added
    public Object getWhiteCanvas() {
        return legendPanel;

     * Gets the Image attribute of the GraphVisualizer object.
     * @return the Image value
    public Image getImage() {
        log.debug("Start : getImage1");
        Image result = graph.createImage(graph.getWidth(), graph.getHeight());

        log.debug("End : getImage1");
        return result;

     * Updates the gui to reflect changes.
    public void updateGui() {
        log.debug("Start : updateGui1");
        log.debug("End : updateGui1");

     * Updates gui to reflect small changes.
     * @param s
     *            sample to be added to plot
    public void updateGui(SampleResult s) {
        log.debug("Start : updateGui2");
        log.debug("End : updateGui2");

     * Clear this visualizer data.
    public synchronized void clearData() {
        log.debug("Start : clear1");
        log.debug("End : clear1");

     * Returns a description of this instance.
     * @return description of this instance
    public String toString() {
        String toString = "Show the samples analysys as dot plots";
        return toString;

     * Setup all the swing components.
    private void init() {
        log.debug("Start : init1");
        graph = new GraphAccum(model);

        this.setLayout(new BorderLayout());

        // MAIN PANEL
        JPanel mainPanel = new JPanel();
        Border margin = new EmptyBorder(10, 10, 5, 10);

        mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));

        // TITLE
        JLabel panelTitleLabel = new JLabel(JMeterUtils.getResString("graph_full_results_title")); // $NON-NLS-1$
        Font curFont = panelTitleLabel.getFont();
        int curFontSize = curFont.getSize();

        curFontSize += 4;
        panelTitleLabel.setFont(new Font(curFont.getFontName(), curFont.getStyle(), curFontSize));


        JScrollPane graphScrollPanel = new JScrollPane(graph, JScrollPane.VERTICAL_SCROLLBAR_NEVER,

        graphScrollPanel.setViewportBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
        legendPanel = new JPanel();

        JScrollPane legendScrollPanel = new JScrollPane(legendPanel);
        JSplitPane graphSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, graphScrollPanel, legendScrollPanel);

        this.add(mainPanel, BorderLayout.NORTH);
        this.add(graphSplitPane, BorderLayout.CENTER);
        log.debug("End : init1");

Other JMeter examples (source code examples)

Here is a short list of links related to this JMeter source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.