| 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, jpanel, jpanel, jtextfield, non-nls-1, non-nls-1, override, string, swing, testelement, whilecontroller, whilecontroller, whilecontrollergui

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.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

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

public class WhileControllerGui extends AbstractControllerGui implements ActionListener {

    private static final long serialVersionUID = 240L;

    private static final String CONDITION_LABEL = "while_controller_label"; // $NON-NLS-1$

     * A field allowing the user to specify the condition (not yet used).
    private JTextField theCondition;

    /** The name of the condition field component. */
    private static final String CONDITION = "While_Condition"; // $NON-NLS-1$

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

     * 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 WhileController) {
            theCondition.setText(((WhileController) element).getCondition());


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

     * Implements JMeterGUIComponent.modifyTestElement(TestElement)
    public void modifyTestElement(TestElement controller) {
        if (controller instanceof WhileController) {
            if (theCondition.getText().length() > 0) {
                ((WhileController) controller).setCondition(theCondition.getText());
            } else {
                ((WhileController) controller).setCondition(""); // $NON-NLS-1$

     * 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 "while_controller_title"; // $NON-NLS-1$

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

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


     * Create a GUI panel containing the condition. TODO make use of the field
     * @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(CONDITION_LABEL));
        conditionPanel.add(conditionLabel, BorderLayout.WEST);

        // TEXT FIELD
        // This means exit if last sample failed
        theCondition = new JTextField("");  // $NON-NLS-1$
        conditionPanel.add(theCondition, BorderLayout.CENTER);

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

        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.