troubleshooting Question

How to resolve the parameter and methods errors to a separate class for action listener performer class

Avatar of Vanavah Edwards
Vanavah Edwards asked on
10 Comments3 Solutions268 ViewsLast Modified:
I have separated my action listener inner class (snippet ID=8238792) from my main to a separate class (snippet ID=8238791) . Now they are a few errors that comes up in the action listener separated class mainly line 7, 30, 31  in class headers.
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.*;

import javax.swing.*;
import javax.swing.text.DateFormatter;
import javax.swing.JComboBox;

import com.jgoodies.forms.builder.DefaultFormBuilder;
import com.jgoodies.forms.factories.Borders;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;


import java.sql.Connection;
import java.sql.Statement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;

public class MOCA{

	private static JComboBox cb1, cb2;

	public static void main(String[] args) {

 		// START ComboBox Image Setup
	       ImageIcon[] images;
			String[] comboStrings = {"create new po", "browse and select"};
	        images = new ImageIcon[comboStrings.length];	//array size
	        Integer[] intArray = new Integer[comboStrings.length];
	        ComboBoxRenderer renderer= new ComboBoxRenderer();
	        for (int i = 0; i < comboStrings.length; i++) {
	            intArray[i] = new Integer(i);
	            images[i] = renderer.createImageIcon("images/" + comboStrings[i] + ".jpg");  // creates image; send path

	            Image img = images[i].getImage();	// scales image size   
	            Image newimg = img.getScaledInstance(30,30, java.awt.Image.SCALE_SMOOTH);
	            images[i] = new ImageIcon(newimg);
	            if (images[i] != null) {  // sets image description
	     // END ComboBox Image Setup

	        cb1 = new JComboBox(images);
	        cb1.setRenderer(renderer);  // displays image description

	        String[] xxx = {"1111", "2222", "3333"};
	        cb2 = new JComboBox(xxx);

	        ActionListenerPerformer alp = new ActionListenerPerformer();
	        JFrame f = new JFrame("teerer");
	        JPanel p = new JPanel();
	        f.setSize(300, 300);
//        buildPanel sohscr = new buildPanel(); // make an object of the class
//        sohscr.buildPanel(); // call the method in the class

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

import javax.swing.JComboBox;

public class ActionListenerPerformer implements ActionListener {

	private static JComboBox cb1, cb2;

	public ActionListenerPerformer(ActionEvent e) {
		if (e.getSource().equals(cb1)) {
	          System.out.println("You've seleccted - "+cb1.getSelectedItem());
	  	if (e.getSource().equals(cb2)) {
	          System.out.println("You've seleccted - "+cb2.getSelectedItem());
	  	if(cb1.getSelectedItem().equals("create new po")) {
	  		System.out.println("or right cb1 = "+cb1.getSelectedItem());
		if(cb1.getSelectedItem().equals("browse and select")) {
			System.out.println("or right cb1 = "+cb1.getSelectedItem());
		if(cb2.getSelectedItem().equals("1111")) {
		  	System.out.println("or right cb2 = "+cb2.getSelectedItem());
	public static void main(String[] args) {
		ActionListenerPerformer ap = new ActionListenerPerformer(); 
import java.awt.Component;
import java.awt.Dimension;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

public class ComboBoxRenderer extends JLabel implements ListCellRenderer {
        public ComboBoxRenderer() {

        public Component getListCellRendererComponent(
            JList list,
            Object value,
            int index,
            boolean isSelected,
            boolean cellHasFocus)
            if (isSelected) {
            } else {

            ImageIcon icon = (ImageIcon)value;
//	        setPreferredSize(new Dimension(100, 100)); // for a explicit size
	        setPreferredSize(null); // for a pack size

            return this;

    	//** RECEIVES THE PATH; CREATES THE IMAGEICON, or null if the path was invalid. */
        protected static ImageIcon createImageIcon(String path) { imgURL = ImageComboBox.class.getResource(path);
            if (imgURL != null) {
                return new ImageIcon(imgURL);
            } else {
                System.err.println("Couldn't find file: " + path);
                    return null;
Join our community to see this answer!
Unlock 3 Answers and 10 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros