| 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

actionlistener, awt, borderlayout, borderlayout, event, gui, ifcontroller, ifcontroller, ifcontrollerpanel, jcheckbox, jpanel, jpanel, jtextfield, non-nls-1, non-nls-1, override, 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.control.gui;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import org.apache.jmeter.control.IfController;
import org.apache.jmeter.gui.util.FocusRequester;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.util.JMeterUtils;

 * The user interface for a controller which specifies that its subcomponents
 * should be executed while a condition holds. This component can be used
 * standalone or embedded into some other component.

public class IfControllerPanel extends AbstractControllerGui implements ActionListener {

    private static final long serialVersionUID = 240L;

     * A field allowing the user to specify the number of times the controller
     * should loop.
    private JTextField theCondition;

    private JCheckBox useExpression;

    private JCheckBox evaluateAll;

     * Boolean indicating whether or not this component should display its name.
     * If true, this is a standalone component. If false, this component is
     * intended to be used as a subpanel for another component.
    private boolean displayName = true;

     * Create a new LoopControlPanel as a standalone component.
    public IfControllerPanel() {

     * Create a new IfControllerPanel as either a standalone or an embedded
     * component.
     * @param displayName
     *            indicates whether or not this component should display its
     *            name. If true, this is a standalone component. If false, this
     *            component is intended to be used as a subpanel for another
     *            component.
    public IfControllerPanel(boolean displayName) {
        this.displayName = displayName;

     * A newly created component can be initialized with the contents of a Test
     * Element object by calling this method. The component is responsible for
     * querying the Test Element object for the relevant information to display
     * in its GUI.
     * @param element
     *            the TestElement to configure
    public void configure(TestElement element) {
        if (element instanceof IfController) {
            IfController ifController = (IfController) element;


     * Implements JMeterGUIComponent.createTestElement()
    public TestElement createTestElement() {
        IfController controller = new IfController();
        return controller;

     * Implements JMeterGUIComponent.modifyTestElement(TestElement)
    public void modifyTestElement(TestElement controller) {
        if (controller instanceof IfController) {
            IfController ifController = (IfController) controller;

     * Implements JMeterGUIComponent.clearGui
    public void clearGui() {
        theCondition.setText(""); // $NON-NLS-1$

     * Invoked when an action occurs. This implementation assumes that the
     * target component is the infinite loops checkbox.
     * @param event
     *            the event that has occurred
    public void actionPerformed(ActionEvent event) {
        new FocusRequester(theCondition);

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

     * Initialize the GUI components and layout for this component.
    private void init() {
        // Standalone
        if (displayName) {
            setLayout(new BorderLayout(0, 5));
            add(makeTitlePanel(), BorderLayout.NORTH);

            JPanel mainPanel = new JPanel(new BorderLayout());
            mainPanel.add(createConditionPanel(), BorderLayout.NORTH);
            add(mainPanel, BorderLayout.CENTER);

        } else {
            // Embedded
            setLayout(new BorderLayout());
            add(createConditionPanel(), BorderLayout.NORTH);

     * Create a GUI panel containing the condition.
     * @return a GUI panel containing the condition components
    private JPanel createConditionPanel() {
        JPanel conditionPanel = new JPanel(new BorderLayout(5, 0));

        // Condition LABEL
        JLabel conditionLabel = new JLabel(JMeterUtils.getResString("if_controller_label")); // $NON-NLS-1$
        conditionPanel.add(conditionLabel, BorderLayout.WEST);

        // TEXT FIELD
        theCondition = new JTextField(""); // $NON-NLS-1$
        conditionPanel.add(theCondition, BorderLayout.CENTER);

                + theCondition.getPreferredSize().width), BorderLayout.NORTH);

        JPanel optionPanel = new JPanel();

        // Use expression instead of Javascript
        useExpression = new JCheckBox(JMeterUtils.getResString("if_controller_expression")); // $NON-NLS-1$

        // Evaluate All checkbox
        evaluateAll = new JCheckBox(JMeterUtils.getResString("if_controller_evaluate_all")); // $NON-NLS-1$

        return conditionPanel;

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.