Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 14 of 14

Thread: previous tab's functions no longer working when new tab is created

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default previous tab's functions no longer working when new tab is created

    So I've created a program that allows you to create a tab when you click on a JButton. that button allows you to name the tab and then it is created. once the tab is created, it adds a new JPanel to the JFrame and stores the tab into an ArrayList. Within that JPanel are more buttons that have other functions.

    I won't get into all the details on what each button does, but basically when I create a new tab again, the previous tab's button's eventhandler no longer functions.

    Does anyone know why this is happening and how I can fix it?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: previous tab's functions no longer working when new tab is created

    Does anyone know why this is happening and how I can fix it?
    Not without seeing some code. Make a small, complete program that compiles, executes and shows the problem.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: previous tab's functions no longer working when new tab is created

    Ok i cut it down as much as I could. still a lot to read through, sorry..

    Basically the program allows the user to create a java program with visuals then translate it into code and export it to a java file

    import javax.swing.DefaultListModel;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JDialog;
    import javax.swing.JFileChooser;
    import javax.swing.JLabel;
    import javax.swing.JList;
    import javax.swing.JOptionPane;
    import javax.swing.JTabbedPane;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import javax.swing.ListSelectionModel;
    import javax.swing.SpringLayout;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
     
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.GridLayout;
     
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.ArrayList;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
     
    @SuppressWarnings("serial")
    public class BeginnerJava extends JFrame {
     
    	private JTabbedPane tabs;
    	private JFileChooser fc = new JFileChooser();
    	private JButton create, open, delete, exportCode, saveProject, newProject, createVariable, deleteVariable,
    	createMethod, deleteMethod, mainMethod, constructor;
    	private JPanel template, controlPanel, logoPanel;
    	private JFrame frame;
    	private JList<String> displayMethod, displayVariable;
    	private DefaultListModel<String> variableList, methodList;
    	private boolean haveMainMethod = false; 
    	private boolean haveConstructor = false;
     
    	private ArrayList<JTabbedPane> myTabs = new ArrayList<JTabbedPane>();
    	private ArrayList<ClassCreation> myClasses = new ArrayList<ClassCreation>();
     
    	private ArrayList<MethodCreation> myMethods = new ArrayList<MethodCreation>();
    	private ArrayList<VariableCreation> myVariables = new ArrayList<VariableCreation>();
     
    	private ArrayList<MethodCreation> methodNames = new ArrayList<MethodCreation>();
    	private ArrayList<VariableCreation> variableNames = new ArrayList<VariableCreation>();
     
    	private ArrayList<MethodCreation> main = new ArrayList<MethodCreation>(); //holds main method
    	private ArrayList<MethodCreation> cons = new ArrayList<MethodCreation>(); //holds constructor
     
    	private ArrayList<ArrayList> methodArray = new ArrayList<ArrayList>(); //holds arrays of methods for each class
     
    	ClassCreation newClass;
    	MethodCreation newMethod, name;
     
    	public static void main(String[] args) {
    		@SuppressWarnings("unused")
    		BeginnerJava bg = new BeginnerJava();
     
    	}
     
        public BeginnerJava() {
        	frame = new JFrame("Java for Beginners");
        	frame.setLayout(new BorderLayout());
     
       	 	tabs = new JTabbedPane();
       	 	controlPanel = controlPanel();
       	 	logoPanel = logo();
     
       	 	frame.add(tabs, BorderLayout.CENTER);
       	 	frame.add(controlPanel, BorderLayout.NORTH);
       	 	frame.add(logoPanel, BorderLayout.SOUTH);
       	 	frame.setSize(400, 600);
       	 	frame.setVisible(true);
       	 	frame.setResizable(false);
      	   	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
      	   	pack();
        }
     
     
     
    	private JPanel controlPanel() {
    		JPanel controlPanel = new JPanel();
    		controlPanel.setPreferredSize(new Dimension(300,30));
     
    		//start new project
    		ImageIcon newIcon = new ImageIcon("http://www.javaprogrammingforums.com/images/new.png");
    		newProject = new JButton(newIcon);
    		newProject.setPreferredSize(new Dimension(20,20));
    		newProject.addActionListener(new EventHandler());
     
    		//open existing project
    		ImageIcon openIcon = new ImageIcon("http://www.javaprogrammingforums.com/images/open.png");
    		open = new JButton(openIcon);
    		open.setPreferredSize(new Dimension(20,20));
    		open.addActionListener(new EventHandler());
     
    		//save project
    		ImageIcon saveIcon = new ImageIcon("http://www.javaprogrammingforums.com/images/save.png");
    		saveProject = new JButton(saveIcon);
    		saveProject.setPreferredSize(new Dimension(20,20));
    		saveProject.addActionListener(new EventHandler());
    		saveProject.setEnabled(false);
     
    		//create class
    		ImageIcon createIcon = new ImageIcon("http://www.javaprogrammingforums.com/images/create.png");
    		create = new JButton(createIcon);
    		create.setPreferredSize(new Dimension(20,20));
    		create.addActionListener(new EventHandler());
     
    		//delete class
    		ImageIcon deleteIcon = new ImageIcon("http://www.javaprogrammingforums.com/images/delete.png");
    		delete = new JButton(deleteIcon);
    		delete.setPreferredSize(new Dimension(20,20));
    		delete.setEnabled(false);
    		delete.addActionListener(new EventHandler());
     
    		controlPanel.add(newProject);
    		controlPanel.add(open);
    		controlPanel.add(saveProject);
    		controlPanel.add(create);
    		controlPanel.add(delete);
     
    		return controlPanel;
    	}
     
    	private JPanel logo() {
    		JPanel panel = new JPanel();
    		panel.setPreferredSize(new Dimension(300,570));
    		panel.setLayout(new BorderLayout());
     
    		ImageIcon image = new ImageIcon("http://www.javaprogrammingforums.com/images/logo.png");
        	JLabel imageLabel = new JLabel(image);
        	panel.add(imageLabel, BorderLayout.CENTER);
     
    		return panel;
    	}
     
    	private JPanel makeClassTemplate() {
    		JPanel template = new JPanel();
    		template.setPreferredSize(new Dimension(300,700));
    		SpringLayout layout = new SpringLayout();
    		template.setLayout(layout);
     
    		JTextArea variableText = new JTextArea("Variables:");
    		variableText.setBackground(null);
    		layout.putConstraint(SpringLayout.WEST, variableText, 45, SpringLayout.WEST, template);
    		layout.putConstraint(SpringLayout.NORTH, variableText, 10, SpringLayout.NORTH, template);
     
    		ImageIcon createIcon = new ImageIcon("http://www.javaprogrammingforums.com/images/create.png");
    		createVariable = new JButton(createIcon);
    		createVariable.setPreferredSize(new Dimension(20,20));
    		createVariable.createToolTip();
    		createVariable.setToolTipText("Create Variable");
    		layout.putConstraint(SpringLayout.WEST, createVariable, 25, SpringLayout.WEST, template);
    		layout.putConstraint(SpringLayout.NORTH, createVariable, 30, SpringLayout.NORTH, template);
    		createVariable.addActionListener(new EventHandler());
     
    		ImageIcon deleteIcon = new ImageIcon("http://www.javaprogrammingforums.com/images/delete.png");
    		deleteVariable = new JButton(deleteIcon);
    		deleteVariable.setPreferredSize(new Dimension(20,20));
    		deleteVariable.createToolTip();
    		deleteVariable.setToolTipText("Delete Variable");
    		deleteVariable.setEnabled(false);
    		layout.putConstraint(SpringLayout.WEST, deleteVariable, 25, SpringLayout.WEST, template);
    		layout.putConstraint(SpringLayout.NORTH, deleteVariable, 50, SpringLayout.NORTH, template);
    		deleteVariable.addActionListener(new EventHandler());
     
    		variableList = new DefaultListModel<String>();
    		displayVariable = new JList<String>(variableList);
    		displayVariable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    		displayVariable.setLayoutOrientation(JList.HORIZONTAL_WRAP);
    		layout.putConstraint(SpringLayout.WEST, displayVariable, 45, SpringLayout.WEST, template);
    		layout.putConstraint(SpringLayout.NORTH, displayVariable, 30, SpringLayout.NORTH, template);
    		displayVariable.setPreferredSize(new Dimension(300,200));
    		displayVariable.addListSelectionListener(new EventHandler());
     
    		JTextArea methodText = new JTextArea("Methods:");
    		methodText.setBackground(null);
    		layout.putConstraint(SpringLayout.WEST, methodText, 45, SpringLayout.WEST, template);
    		layout.putConstraint(SpringLayout.NORTH, methodText, 240, SpringLayout.NORTH, template);
     
    		//create method
    		createIcon = new ImageIcon("http://www.javaprogrammingforums.com/images/create.png");
    		createMethod = new JButton(createIcon);
    		createMethod.setPreferredSize(new Dimension(20,20));
    		createMethod.createToolTip();
    		createMethod.setToolTipText("Create Method");
    		layout.putConstraint(SpringLayout.WEST, createMethod, 25, SpringLayout.WEST, template);
    		layout.putConstraint(SpringLayout.NORTH, createMethod, 260, SpringLayout.NORTH, template);
    		createMethod.addActionListener(new EventHandler());
     
    		//delete method
    		deleteIcon = new ImageIcon("http://www.javaprogrammingforums.com/images/delete.png");
    		deleteMethod = new JButton(deleteIcon);
    		deleteMethod.setPreferredSize(new Dimension(20,20));
    		deleteMethod.createToolTip();
    		deleteMethod.setToolTipText("Delete Method");
    		deleteMethod.setEnabled(false);
    		layout.putConstraint(SpringLayout.WEST, deleteMethod, 25, SpringLayout.WEST, template);
    		layout.putConstraint(SpringLayout.NORTH, deleteMethod, 280, SpringLayout.NORTH, template);
    		deleteMethod.addActionListener(new EventHandler());
     
    		methodList = new DefaultListModel<String>();
    		displayMethod = new JList<String>(methodList);
    		displayMethod.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    		displayMethod.setLayoutOrientation(JList.HORIZONTAL_WRAP);
    		layout.putConstraint(SpringLayout.WEST, displayMethod, 45, SpringLayout.WEST, template);
    		layout.putConstraint(SpringLayout.NORTH, displayMethod, 260, SpringLayout.NORTH, template);
    		displayMethod.setPreferredSize(new Dimension(300,200));
    		displayMethod.addListSelectionListener(new EventHandler());
     
    		ImageIcon export = new ImageIcon("http://www.javaprogrammingforums.com/images/save.png");
    		exportCode = new JButton(export);
    		exportCode.setPreferredSize(new Dimension(20,20));
    		exportCode.createToolTip();
    		exportCode.setToolTipText("Export Code");
    		layout.putConstraint(SpringLayout.WEST, exportCode, 370, SpringLayout.WEST, template);
    		layout.putConstraint(SpringLayout.NORTH, exportCode, 0, SpringLayout.NORTH, template);
    		exportCode.addActionListener(new EventHandler());
     
    		mainMethod = new JButton("Add Main Method");
    		layout.putConstraint(SpringLayout.WEST, mainMethod, 193, SpringLayout.WEST, template);
    		layout.putConstraint(SpringLayout.NORTH, mainMethod, 470, SpringLayout.NORTH, template);
    		mainMethod.addActionListener(new EventHandler());
     
    		constructor = new JButton("Add Constructor");
    		layout.putConstraint(SpringLayout.WEST, constructor, 63, SpringLayout.WEST, template);
    		layout.putConstraint(SpringLayout.NORTH, constructor, 470, SpringLayout.NORTH, template);
    		constructor.addActionListener(new EventHandler());
     
    		template.add(createVariable);
    		template.add(deleteVariable);
    		template.add(displayVariable);
    		template.add(variableText);
    		template.add(exportCode);
    		template.add(methodText);
    		template.add(createMethod);
    		template.add(deleteMethod);
    		template.add(displayMethod);
    		template.add(constructor);
    		template.add(mainMethod);
     
    		template.validate();
     
    		return template;
    	}
     
    	private void makeMethod() {
    		String[] buttonTxt1 = {"public", "private", "protected"};
    		JComboBox<Object> methodType1 = new JComboBox<Object>(buttonTxt1);
    		methodType1.setSelectedIndex(0);
    		methodType1.addActionListener(new EventHandler());
     
    		String[] buttonTxt2 = {"", "static"};
    		JComboBox<Object> methodType2 = new JComboBox<Object>(buttonTxt2);
    		methodType2.setSelectedIndex(0);
    		methodType2.addActionListener(new EventHandler());
     
    		String[] buttonTxt3 = {"", "abstract" , "final"};
    		JComboBox<Object> methodType3 = new JComboBox<Object>(buttonTxt3);
    		methodType3.setSelectedIndex(0);
    		methodType3.addActionListener(new EventHandler());
     
    		String[] buttonTxt4 = {"void","int","double","long","byte","float","char","String"};
    		JComboBox<Object> methodType4 = new JComboBox<Object>(buttonTxt4);
    		methodType4.setSelectedIndex(0);
    		methodType4.addActionListener(new EventHandler());
     
    		JDialog dialog;
    		JOptionPane optionPane = new JOptionPane();
    		optionPane.setLayout(new GridLayout(4,1));
     
            optionPane.setMessage("Method Type");
            optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
            optionPane.add(methodType1);
            optionPane.add(methodType2);
            optionPane.add(methodType3);
            optionPane.add(methodType4);
            dialog = optionPane.createDialog(null, "Method Type");
            dialog.setVisible(true);
     
            String st = JOptionPane.showInputDialog(null, "Enter Method Name: ");
            String pick1 = methodType1.getSelectedItem().toString();
    		String pick2 = methodType2.getSelectedItem().toString();
    		String pick3 = methodType3.getSelectedItem().toString();
    		String pick4 = methodType4.getSelectedItem().toString();
    		String methodName = st;
     
    		newMethod = new MethodCreation(pick1, pick2, pick3, pick4, methodName);
    		myMethods.add(newMethod);
    		methodArray.add(myMethods);
    		name = new MethodCreation(methodName);
    		methodNames.add(name);
    	}
     
    	private void makeVariable() {
    		String[] buttonTxt1 = {"public", "private", "protected"};
    		JComboBox<Object> methodType1 = new JComboBox<Object>(buttonTxt1);
    		methodType1.setSelectedIndex(0);
    		methodType1.addActionListener(new EventHandler());
     
    		String[] buttonTxt2 = {"", "static"};
    		JComboBox<Object> methodType2 = new JComboBox<Object>(buttonTxt2);
    		methodType2.setSelectedIndex(0);
    		methodType2.addActionListener(new EventHandler());
     
    		String[] buttonTxt3 = {"", "abstract" , "final"};
    		JComboBox<Object> methodType3 = new JComboBox<Object>(buttonTxt3);
    		methodType3.setSelectedIndex(0);
    		methodType3.addActionListener(new EventHandler());
     
    		String[] buttonTxt4 = {"void","int","double","long","byte","float","char","String"};
    		JComboBox<Object> methodType4 = new JComboBox<Object>(buttonTxt4);
    		methodType4.setSelectedIndex(0);
    		methodType4.addActionListener(new EventHandler());
     
    		JDialog dialog;
    		JOptionPane optionPane = new JOptionPane();
    		optionPane.setLayout(new GridLayout(4,1));
     
            optionPane.setMessage("Method Type");
            optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
            optionPane.add(methodType1);
            optionPane.add(methodType2);
            optionPane.add(methodType3);
            optionPane.add(methodType4);
            dialog = optionPane.createDialog(null, "Method Type");
            dialog.setVisible(true);
     
            String st = JOptionPane.showInputDialog(null, "Enter Method Name: ");
            String pick1 = methodType1.getSelectedItem().toString();
    		String pick2 = methodType2.getSelectedItem().toString();
    		String pick3 = methodType3.getSelectedItem().toString();
    		String pick4 = methodType4.getSelectedItem().toString();
    		String methodName = st;
     
    		newMethod = new MethodCreation(pick1, pick2, pick3, pick4, methodName);
    		myMethods.add(newMethod);
    		methodArray.add(myMethods);
    		name = new MethodCreation(methodName);
    		methodNames.add(name);
    	}
     
    	private void createClass() {
     
    		//public or private
    		String[] buttonTxt1 = {"public", "private"};
    		JComboBox<Object> classType1 = new JComboBox<Object>(buttonTxt1);
    		classType1.setSelectedIndex(0);
    		classType1.addActionListener(new EventHandler());
     
    		//abstract, final , or neither
    		String[] buttonTxt2 = {"","abstract","final"};
    		JComboBox<Object> classType2 = new JComboBox<Object>(buttonTxt2);
    		classType2.setSelectedIndex(0);
    		classType2.addActionListener(new EventHandler());
     
    		JDialog dialog;
    		JOptionPane optionPane = new JOptionPane();
    		optionPane.setLayout(new GridLayout(2,1));
     
    		methodList = new DefaultListModel<String>();
    		variableList = new DefaultListModel<String>();
     
            optionPane.setMessage("Class Type");
            optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
            optionPane.add(classType1);
            optionPane.add(classType2);
            dialog = optionPane.createDialog(null, "Class Type");
            dialog.setVisible(true);
     
    		String st = JOptionPane.showInputDialog(null, "Enter Class Name:");	
    		Pattern whiteSpace = Pattern.compile("\\s");
    		Matcher matcher = whiteSpace.matcher(st);
    		boolean found = matcher.find();
    		String className = st;
    		String pick1 = classType1.getSelectedItem().toString();
    		String pick2 = classType2.getSelectedItem().toString();
     
    		if(found == true || st.equals("")) {
    			//will not create a new tab unless there are no spaces
    			JOptionPane.showMessageDialog(null, "Class name cannot be empty or contain spaces or symbols", "Error", JOptionPane.WARNING_MESSAGE);				
    			st = JOptionPane.showInputDialog(null, "Enter Class Name:");
    		}
     
    		if(!st.equals("")) {
    				logoPanel.setVisible(false);
    				newClass = new ClassCreation(pick1, pick2, className);
    				template = makeClassTemplate();
    				tabs.add(st, template);
    				tabs.setSelectedComponent(template);
    				myTabs.add(tabs);
    				myClasses.add(newClass);
    		}
     
    	}
     
        private class EventHandler implements ActionListener, ListSelectionListener{
     
    		@Override
    		public void actionPerformed(ActionEvent e) {
    			Object b = e.getSource();
    			String str = e.getActionCommand();
     
    			if(b.equals(create)) {
    				myMethods.clear();
    				methodNames.clear();
    				createClass();
    			}
     
    			if(tabs.getTabCount()>=1) {
    				//enables delete & save if there is at least one tab
    				delete.setEnabled(true);
    				saveProject.setEnabled(true);
    			}
     
    			if(b.equals(delete)) {
    				tabs.remove(tabs.getSelectedIndex());
    				if(tabs.getTabCount()<1){
    					delete.setEnabled(false);
    					saveProject.setEnabled(false);
    					logoPanel.setVisible(true);
    				}
    			}
     
    			if(b.equals(open)) {
    				int returnVal = fc.showOpenDialog(BeginnerJava.this);
    				if(returnVal == JFileChooser.APPROVE_OPTION) {
    					String file = fc.getSelectedFile().getPath();
    					try {
    						openFile(file);
    					} catch (ClassNotFoundException | IOException e1) {
    						// TODO Auto-generated catch block
    						e1.printStackTrace();
    					}
    				}
    			}
     
    			if(b.equals(exportCode)) {
    				String name = tabs.getTitleAt(tabs.getSelectedIndex());
    				File outFile = new File(name + ".java");
    				if(outFile.exists()) {
     
    				}
                    PrintWriter textStream;
                    try
                    {
                    		textStream = new PrintWriter(outFile);
     
                    		//calls ClassCreation's toString
                    		textStream.println(newClass);
     
                    		if(methodArray.size() != 0) {
                    			if(methodArray.get(tabs.getSelectedIndex()).size() <= 1) {
                    			for(int i = 0; i < methodArray.get(tabs.getSelectedIndex()).size(); i++)
                           			//gets currently selected tabs ArrayList that is filled with it's methods
                           			if(methodArray.get(i).size() != 0) {
                           				textStream.println(methodArray.get(i).get(i).toString());
                           			}
                    			}
     
                    			else {
                    				for(int i = 0; i < methodArray.get(tabs.getSelectedIndex()-1).size(); i++)
                               			//gets currently selected tabs ArrayList that is filled with it's methods
                               			if(methodArray.get(i).size() != 0) {
                               				textStream.println(methodArray.get(i).get(i).toString());
     
                               			}
                        			}
                    			}
     
                    		if(main.size() != 0)
                				textStream.println(main.get(0).mainMethod());
     
                    		if(cons.size() != 0)
                    			textStream.println(cons.get(0).constructor(name));
     
                    		textStream.println("}");
                    		haveMainMethod = false;
                    		haveConstructor = false;
     
                        	textStream.close();         
                    } catch (FileNotFoundException e1)
                    {
                            e1.printStackTrace();
                    }      
    			}
     
    			if(b.equals(createMethod)) {
    				makeMethod();
    				methodList.clear();
    				deleteMethod.setEnabled(true);
    				for(int i = 0; i < methodNames.size(); i++) {
    					methodList.addElement(methodNames.get(i).getName());
    				}
    				if(haveMainMethod == true)
        				methodList.addElement("main");
     
            		if(haveConstructor == true)
            			methodList.addElement("constructor");
    			}
     
    			if(b.equals(deleteMethod)) {
    				int index = displayMethod.getSelectedIndex();
    				methodList.remove(index);
    				myMethods.remove(index);
    				if(myMethods.size()<1)
    					deleteMethod.setEnabled(false);
    			}
     
    			if(b.equals(createVariable)) {
    				makeVariable();
    				variableList.clear();
    				deleteVariable.setEnabled(true);
    				for(int i = 0; i < variableNames.size(); i++) {
    					variableList.addElement(variableNames.get(i).getName());
    				}
    			}
     
    			if(b.equals(deleteVariable)) {
     
    			}
     
    			if(b.equals(newProject)) {
    				methodArray.clear();
    				myClasses.clear();
    				myMethods.clear();
    				myVariables.clear();
    				tabs.removeAll();
    			}
     
    			if(str.equals("Add Main Method")) {
    				//creates main method
    				newMethod = new MethodCreation();
    				mainMethod.setEnabled(false);
    				deleteMethod.setEnabled(true);
    				haveMainMethod = true;
    				main.add(newMethod);
    				methodList.addElement("main");
    			}
     
    			if(str.equals("Add Constructor")) {
    				//creates constructor
    				newMethod = new MethodCreation();
    				constructor.setEnabled(false);
    				deleteMethod.setEnabled(true);
    				haveConstructor = true;
    				cons.add(newMethod);
    				methodList.addElement("constructor");
    			}
     
    		}
    		@Override
    		public void valueChanged(ListSelectionEvent arg0) {
    			// TODO Auto-generated method stub
     
    		}
        }
     
        private void openFile(String file) throws ClassNotFoundException, IOException {
     
     
        }
     
    }

    import java.util.ArrayList;
     
     
    public class ClassCreation {
     
    	private String className, classType1, classType2;
     
    	public ClassCreation(String classType1, String classType2, String className) {
    		this.classType1 = classType1;
    		this.classType2 = classType2;
    		this.className = className;
    	}
     
    	public String toString() {
    		if(classType2 != "") 
    			return  classType1 + " " + classType2 + " class" + " " + className + " {" + "\n";
     
    		else return classType1 + " " + "class" + " " + className + " {" + "\n";
    	}
     
    }

     
    public class MethodCreation {
    	private String methodName, methodType1, methodType2, methodType3, methodType4;
     
    	public MethodCreation(String methodType1, String methodType2, String methodType3, String methodType4, String methodName) {
    		this.methodType1 = methodType1;
    		this.methodType2 = methodType2;
    		this.methodType3 = methodType3;
    		this.methodType4 = methodType4;
    		this.methodName = methodName;
    	}
     
    	public MethodCreation() {
     
    	}
     
    	public MethodCreation(String methodName) {
    		this.methodName = methodName;
    	}
     
    	public String getName() {
    		return methodName;
    	}
     
    	public String mainMethod() {
    		return "    public static void main(String[] args) {" + "\n" + "    }" + "\n";
    	}
     
    	public String constructor(String className) {
    		return "    public " + className + "() {" + "\n" + "    }" + "\n"; 
    	}
     
    	public String toString() {
    		if(methodType2 == "" && methodType3 == "")
    			return "    " + methodType1 + " " + methodType4 + " " + methodName + "() {" + "\n" + "    }" + "\n";
     
    		else if(methodType3 =="abstract")
    			return "    " + methodType1 + " " + methodType2 + " " + methodType3 + " " + methodType4 + " " + methodName + "();";
     
    		else if(methodType2 == "") 
    			return "    " + methodType1 + " " + methodType3 + " " + methodType4 + " " +  methodName + "() {" + "\n" + "    }" + "\n";
     
    		else if(methodType3 == "")
    			return "    " + methodType1 + " " + methodType2 + " " + methodType4 + " " + methodName + "() {" + "\n" + "    }" + "\n";
     
    		return "    " + methodType1 + " " + methodType2 + " " + methodType3 + " " + methodType4 + " " + methodName + "() {" + "\n" + "    }" + "\n";
    	}
     
    }

    public class VariableCreation {
     
    private String variableName, variableType1, variableType2, variableType3;
     
    	public VariableCreation(String variableType1, String variableType2, String variableType3, String variableName) {
    		this.variableType1 = variableType1;
    		this.variableType2 = variableType2;
    		this.variableType3 = variableType3;
    		this.variableName = variableName;
    	}
     
    	public String toString() {
    		if(variableType2 != "") 
    			return variableType1 + " " + variableType2 + " " + variableType3 + " " + variableName + " {" + "\n" + "}";
     
    		else return variableType1 + " " + variableType2 + " " + variableName + " {" + "\n" + "}";
    	}
     
    	public String getName() {
    		return variableName;
    	}
     
    }
    Last edited by captain; April 26th, 2012 at 12:39 PM.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: previous tab's functions no longer working when new tab is created

    How can the posted code be compiled and tested There aren't import statements and I don't see a main() method.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Feb 2012
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: previous tab's functions no longer working when new tab is created

    I'm sorry I just tried to cut it down as much as possible. i edited it. check again please

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: previous tab's functions no longer working when new tab is created

    The code does not compile without errors.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Feb 2012
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: previous tab's functions no longer working when new tab is created

    Wow i'm sorry. I cut some of the methodcreation class out. hope that helps. also the jbuttons have icons set for them, but that shouldn't stop it from compiling

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: previous tab's functions no longer working when new tab is created

    600+ lines are too many to work with. Try to cut it down to 200.

    when I create a new tab again, the previous tab's button's eventhandler no longer functions.
    That is all that needs to be in the testing code.
    Last edited by Norm; April 26th, 2012 at 12:52 PM.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Feb 2012
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: previous tab's functions no longer working when new tab is created

    I was able to cut it down to about 340 lines and it still compiles
    import javax.swing.DefaultListModel;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JDialog;
    import javax.swing.JFileChooser;
    import javax.swing.JList;
    import javax.swing.JOptionPane;
    import javax.swing.JTabbedPane;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import javax.swing.ListSelectionModel;
    import javax.swing.SpringLayout;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.ArrayList;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
     
    @SuppressWarnings("serial")
    public class Example extends JFrame {
     
    	private JTabbedPane tabs;
    	private JFileChooser fc = new JFileChooser();
    	private JButton create, open, delete, exportCode, saveProject, newProject, createVariable, deleteVariable,
    	createMethod, deleteMethod, mainMethod, constructor;
    	private JPanel template, controlPanel, logoPanel;
    	private JFrame frame;
    	private JList<String> displayMethod;
    	private DefaultListModel<String> methodList;
    	private boolean haveMainMethod = false; 
    	private boolean haveConstructor = false;
     
    	private ArrayList<JTabbedPane> myTabs = new ArrayList<JTabbedPane>();
    	private ArrayList<ClassCreation> myClasses = new ArrayList<ClassCreation>();
     
    	private ArrayList<MethodCreation> myMethods = new ArrayList<MethodCreation>();
    	private ArrayList<VariableCreation> myVariables = new ArrayList<VariableCreation>();
     
    	private ArrayList<MethodCreation> methodNames = new ArrayList<MethodCreation>();
     
    	private ArrayList<ArrayList> methodArray = new ArrayList<ArrayList>(); //holds arrays of methods for each class
     
    	ClassCreation newClass;
    	MethodCreation newMethod, name;
     
    	public static void main(String[] args) {
    		@SuppressWarnings("unused")
    		Example ex = new Example();
     
    	}
     
        public Example() {
        	frame = new JFrame("Java for Beginners");
        	frame.setLayout(new BorderLayout());
     
       	 	tabs = new JTabbedPane();
       	 	controlPanel = controlPanel();
     
       	 	frame.add(tabs, BorderLayout.CENTER);
       	 	frame.add(controlPanel, BorderLayout.NORTH);
       	 	frame.add(logoPanel, BorderLayout.SOUTH);
       	 	frame.setSize(400, 600);
       	 	frame.setVisible(true);
       	 	frame.setResizable(false);
      	   	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
      	   	pack();
        }
     
    	private JPanel controlPanel() {
    		JPanel controlPanel = new JPanel();
    		controlPanel.setPreferredSize(new Dimension(300,30));
     
    		//start new project
    		ImageIcon newIcon = new ImageIcon("http://www.javaprogrammingforums.com/images/new.png");
    		newProject = new JButton(newIcon);
    		newProject.setPreferredSize(new Dimension(20,20));
    		newProject.addActionListener(new EventHandler());
     
    		//create class
    		ImageIcon createIcon = new ImageIcon("http://www.javaprogrammingforums.com/images/create.png");
    		create = new JButton(createIcon);
    		create.setPreferredSize(new Dimension(20,20));
    		create.addActionListener(new EventHandler());
     
    		//delete class
    		ImageIcon deleteIcon = new ImageIcon("http://www.javaprogrammingforums.com/images/delete.png");
    		delete = new JButton(deleteIcon);
    		delete.setPreferredSize(new Dimension(20,20));
    		delete.setEnabled(false);
    		delete.addActionListener(new EventHandler());
     
    		controlPanel.add(newProject);
    		controlPanel.add(create);
    		controlPanel.add(delete);
     
    		return controlPanel;
    	}
     
    	private JPanel makeClassTemplate() {
    		JPanel template = new JPanel();
    		template.setPreferredSize(new Dimension(300,700));
    		SpringLayout layout = new SpringLayout();
    		template.setLayout(layout);
     
    		JTextArea methodText = new JTextArea("Methods:");
    		methodText.setBackground(null);
    		layout.putConstraint(SpringLayout.WEST, methodText, 45, SpringLayout.WEST, template);
    		layout.putConstraint(SpringLayout.NORTH, methodText, 240, SpringLayout.NORTH, template);
     
    		//create method
    		ImageIcon createIcon = new ImageIcon("http://www.javaprogrammingforums.com/images/create.png");
    		createMethod = new JButton(createIcon);
    		createMethod.setPreferredSize(new Dimension(20,20));
    		createMethod.createToolTip();
    		createMethod.setToolTipText("Create Method");
    		layout.putConstraint(SpringLayout.WEST, createMethod, 25, SpringLayout.WEST, template);
    		layout.putConstraint(SpringLayout.NORTH, createMethod, 260, SpringLayout.NORTH, template);
    		createMethod.addActionListener(new EventHandler());
     
    		//delete method
    		ImageIcon deleteIcon = new ImageIcon("http://www.javaprogrammingforums.com/images/delete.png");
    		deleteMethod = new JButton(deleteIcon);
    		deleteMethod.setPreferredSize(new Dimension(20,20));
    		deleteMethod.createToolTip();
    		deleteMethod.setToolTipText("Delete Method");
    		deleteMethod.setEnabled(false);
    		layout.putConstraint(SpringLayout.WEST, deleteMethod, 25, SpringLayout.WEST, template);
    		layout.putConstraint(SpringLayout.NORTH, deleteMethod, 280, SpringLayout.NORTH, template);
    		deleteMethod.addActionListener(new EventHandler());
     
    		methodList = new DefaultListModel<String>();
    		displayMethod = new JList<String>(methodList);
    		displayMethod.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    		displayMethod.setLayoutOrientation(JList.HORIZONTAL_WRAP);
    		layout.putConstraint(SpringLayout.WEST, displayMethod, 45, SpringLayout.WEST, template);
    		layout.putConstraint(SpringLayout.NORTH, displayMethod, 260, SpringLayout.NORTH, template);
    		displayMethod.setPreferredSize(new Dimension(300,200));
    		displayMethod.addListSelectionListener(new EventHandler());
     
    		ImageIcon export = new ImageIcon("http://www.javaprogrammingforums.com/images/save.png");
    		exportCode = new JButton(export);
    		exportCode.setPreferredSize(new Dimension(20,20));
    		exportCode.createToolTip();
    		exportCode.setToolTipText("Export Code");
    		layout.putConstraint(SpringLayout.WEST, exportCode, 370, SpringLayout.WEST, template);
    		layout.putConstraint(SpringLayout.NORTH, exportCode, 0, SpringLayout.NORTH, template);
    		exportCode.addActionListener(new EventHandler());
     
    		template.add(exportCode);
    		template.add(methodText);
    		template.add(createMethod);
    		template.add(deleteMethod);
    		template.add(displayMethod);
     
    		template.validate();
     
    		return template;
    	}
     
    	private void makeMethod() {
    		String[] buttonTxt1 = {"public", "private", "protected"};
    		JComboBox<Object> methodType1 = new JComboBox<Object>(buttonTxt1);
    		methodType1.setSelectedIndex(0);
    		methodType1.addActionListener(new EventHandler());
     
    		String[] buttonTxt2 = {"", "static"};
    		JComboBox<Object> methodType2 = new JComboBox<Object>(buttonTxt2);
    		methodType2.setSelectedIndex(0);
    		methodType2.addActionListener(new EventHandler());
     
    		String[] buttonTxt3 = {"", "abstract" , "final"};
    		JComboBox<Object> methodType3 = new JComboBox<Object>(buttonTxt3);
    		methodType3.setSelectedIndex(0);
    		methodType3.addActionListener(new EventHandler());
     
    		String[] buttonTxt4 = {"void","int","double","long","byte","float","char","String"};
    		JComboBox<Object> methodType4 = new JComboBox<Object>(buttonTxt4);
    		methodType4.setSelectedIndex(0);
    		methodType4.addActionListener(new EventHandler());
     
    		JDialog dialog;
    		JOptionPane optionPane = new JOptionPane();
    		optionPane.setLayout(new GridLayout(4,1));
     
            optionPane.setMessage("Method Type");
            optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
            optionPane.add(methodType1);
            optionPane.add(methodType2);
            optionPane.add(methodType3);
            optionPane.add(methodType4);
            dialog = optionPane.createDialog(null, "Method Type");
            dialog.setVisible(true);
     
            String st = JOptionPane.showInputDialog(null, "Enter Method Name: ");
            String pick1 = methodType1.getSelectedItem().toString();
    		String pick2 = methodType2.getSelectedItem().toString();
    		String pick3 = methodType3.getSelectedItem().toString();
    		String pick4 = methodType4.getSelectedItem().toString();
    		String methodName = st;
     
    		newMethod = new MethodCreation(pick1, pick2, pick3, pick4, methodName);
    		myMethods.add(newMethod);
    		methodArray.add(myMethods);
    		name = new MethodCreation(methodName);
    		methodNames.add(name);
    	}
     
    	private void createClass() {	
    		//public or private
    		String[] buttonTxt1 = {"public", "private"};
    		JComboBox<Object> classType1 = new JComboBox<Object>(buttonTxt1);
    		classType1.setSelectedIndex(0);
    		classType1.addActionListener(new EventHandler());
     
    		//abstract, final , or neither
    		String[] buttonTxt2 = {"","abstract","final"};
    		JComboBox<Object> classType2 = new JComboBox<Object>(buttonTxt2);
    		classType2.setSelectedIndex(0);
    		classType2.addActionListener(new EventHandler());
     
    		JDialog dialog;
    		JOptionPane optionPane = new JOptionPane();
    		optionPane.setLayout(new GridLayout(2,1));
     
    		methodList = new DefaultListModel<String>();
     
            optionPane.setMessage("Class Type");
            optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
            optionPane.add(classType1);
            optionPane.add(classType2);
            dialog = optionPane.createDialog(null, "Class Type");
            dialog.setVisible(true);
     
    		String st = JOptionPane.showInputDialog(null, "Enter Class Name:");	
    		Pattern whiteSpace = Pattern.compile("\\s");
    		Matcher matcher = whiteSpace.matcher(st);
    		boolean found = matcher.find();
    		String className = st;
    		String pick1 = classType1.getSelectedItem().toString();
    		String pick2 = classType2.getSelectedItem().toString();
     
    		if(found == true || st.equals("")) {
    			//will not create a new tab unless there are no spaces
    			JOptionPane.showMessageDialog(null, "Class name cannot be empty or contain spaces or symbols", "Error", JOptionPane.WARNING_MESSAGE);				
    			st = JOptionPane.showInputDialog(null, "Enter Class Name:");
    		}
     
    		if(!st.equals("")) {
    				logoPanel.setVisible(false);
    				newClass = new ClassCreation(pick1, pick2, className);
    				template = makeClassTemplate();
    				tabs.add(st, template);
    				tabs.setSelectedComponent(template);
    				myTabs.add(tabs);
    				myClasses.add(newClass);
    		}
     
    	}
     
        private class EventHandler implements ActionListener, ListSelectionListener{
    	@Override
    		public void actionPerformed(ActionEvent e) {
    			Object b = e.getSource();
     
    			if(b.equals(create)) {
    				myMethods.clear();
    				methodNames.clear();
    				createClass();
    			}
     
    			if(tabs.getTabCount()>=1) {
    				//enables delete & save if there is at least one tab
    				delete.setEnabled(true);
    				saveProject.setEnabled(true);
    			}
     
    			if(b.equals(delete)) {
    				tabs.remove(tabs.getSelectedIndex());
    				if(tabs.getTabCount()<1){
    					delete.setEnabled(false);
    					saveProject.setEnabled(false);
    					logoPanel.setVisible(true);
    				}
    			}
     
     
    			if(b.equals(exportCode)) {
    				//exports code   
    			}
     
    			if(b.equals(createMethod)) {
    				makeMethod();
    				methodList.clear();
    				deleteMethod.setEnabled(true);
    				for(int i = 0; i < methodNames.size(); i++) {
    					methodList.addElement(methodNames.get(i).getName());
    				}
    				if(haveMainMethod == true)
        				methodList.addElement("main");
     
            		if(haveConstructor == true)
            			methodList.addElement("constructor");
    			}
     
    			if(b.equals(deleteMethod)) {
    				int index = displayMethod.getSelectedIndex();
    				methodList.remove(index);
    				myMethods.remove(index);
    				if(myMethods.size()<1)
    					deleteMethod.setEnabled(false);
    			}
     
    			if(b.equals(newProject)) {
    				methodArray.clear();
    				myClasses.clear();
    				myMethods.clear();
    				myVariables.clear();
    				tabs.removeAll();
    			}
     
     
    		}
    		@Override
    		public void valueChanged(ListSelectionEvent arg0) {
    			// TODO Auto-generated method stub
     
    		}
        }  
    }
    Last edited by captain; April 26th, 2012 at 01:07 PM.

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: previous tab's functions no longer working when new tab is created

    The last posted code does not compile without errors. It is missing many class definitions.


    Running: D:\Java\jdk1.7.0\bin\javac.exe -Xlint Example2.java

    Example2.java:29: error: cannot find symbol
    private JFileChooser fc = new JFileChooser();
    ^
    symbol: class JFileChooser
    location: class Example2
    Example2.java:30: error: cannot find symbol
    private JButton create, open, delete, exportCode, saveProject, newProject, createVariable, deleteVariable,
    ^
    symbol: class JButton
    location: class Example2
    Example2.java:35: error: cannot find symbol
    private DefaultListModel<String> methodList;
    ^
    symbol: class DefaultListModel
    location: class Example2
    Example2.java:40: error: cannot find symbol
    private ArrayList<ClassCreation> myClasses = new ArrayList<ClassCreation>();
    ^
    symbol: class ClassCreation
    location: class Example2
    Example2.java:42: error: cannot find symbol
    private ArrayList<MethodCreation> myMethods = new ArrayList<MethodCreation>();
    ^
    symbol: class MethodCreation
    location: class Example2
    Example2.java:43: error: cannot find symbol
    private ArrayList<VariableCreation> myVariables = new ArrayList<VariableCreation>();
    ^
    symbol: class VariableCreation
    location: class Example2
    Example2.java:45: error: cannot find symbol
    private ArrayList<MethodCreation> methodNames = new ArrayList<MethodCreation>();
    ^
    symbol: class MethodCreation
    location: class Example2
    Example2.java:49: error: cannot find symbol
    ClassCreation newClass;
    ^
    symbol: class ClassCreation
    location: class Example2
    Example2.java:50: error: cannot find symbol
    MethodCreation newMethod, name;
    ^
    symbol: class MethodCreation
    location: class Example2
    Example2.java:29: error: cannot find symbol
    private JFileChooser fc = new JFileChooser();
    ^
    symbol: class JFileChooser
    location: class Example2
    Example2.java:40: error: cannot find symbol
    private ArrayList<ClassCreation> myClasses = new ArrayList<ClassCreation>();
    ^
    symbol: class ClassCreation
    location: class Example2
    Example2.java:42: error: cannot find symbol
    private ArrayList<MethodCreation> myMethods = new ArrayList<MethodCreation>();
    ^
    symbol: class MethodCreation
    location: class Example2
    Example2.java:43: error: cannot find symbol
    private ArrayList<VariableCreation> myVariables = new ArrayList<VariableCreation>();
    ^
    symbol: class VariableCreation
    location: class Example2
    Example2.java:45: error: cannot find symbol
    private ArrayList<MethodCreation> methodNames = new ArrayList<MethodCreation>();
    ^
    symbol: class MethodCreation
    location: class Example2
    Example2.java:47: warning: [rawtypes] found raw type: ArrayList
    private ArrayList<ArrayList> methodArray = new ArrayList<ArrayList>(); //holds arrays of methods for each class
    ^
    missing type arguments for generic class ArrayList<E>
    where E is a type-variable:
    E extends Object declared in class ArrayList
    Example2.java:47: warning: [rawtypes] found raw type: ArrayList
    private ArrayList<ArrayList> methodArray = new ArrayList<ArrayList>(); //holds arrays of methods for each class
    ^
    missing type arguments for generic class ArrayList<E>
    where E is a type-variable:
    E extends Object declared in class ArrayList
    Example2.java:54: error: cannot find symbol
    BeginnerJava bg = new BeginnerJava();
    ^
    symbol: class BeginnerJava
    location: class Example2
    Example2.java:54: error: cannot find symbol
    BeginnerJava bg = new BeginnerJava();
    ^
    symbol: class BeginnerJava
    location: class Example2
    Example2.java:81: error: cannot find symbol
    ImageIcon newIcon = new ImageIcon("images/new.png");
    ^
    symbol: class ImageIcon
    location: class Example2
    Example2.java:81: error: cannot find symbol
    ImageIcon newIcon = new ImageIcon("images/new.png");
    ^
    symbol: class ImageIcon
    location: class Example2
    Example2.java:82: error: cannot find symbol
    newProject = new JButton(newIcon);
    ^
    symbol: class JButton
    location: class Example2
    Example2.java:87: error: cannot find symbol
    ImageIcon createIcon = new ImageIcon("images/create.png");
    ^
    symbol: class ImageIcon
    location: class Example2
    Example2.java:87: error: cannot find symbol
    ImageIcon createIcon = new ImageIcon("images/create.png");
    ^
    symbol: class ImageIcon
    location: class Example2
    Example2.java:88: error: cannot find symbol
    create = new JButton(createIcon);
    ^
    symbol: class JButton
    location: class Example2
    Example2.java:93: error: cannot find symbol
    ImageIcon deleteIcon = new ImageIcon("images/delete.png");
    ^
    symbol: class ImageIcon
    location: class Example2
    Example2.java:93: error: cannot find symbol
    ImageIcon deleteIcon = new ImageIcon("images/delete.png");
    ^
    symbol: class ImageIcon
    location: class Example2
    Example2.java:94: error: cannot find symbol
    delete = new JButton(deleteIcon);
    ^
    symbol: class JButton
    location: class Example2
    Example2.java:118: error: cannot find symbol
    ImageIcon createIcon = new ImageIcon("images/create.png");
    ^
    symbol: class ImageIcon
    location: class Example2
    Example2.java:118: error: cannot find symbol
    ImageIcon createIcon = new ImageIcon("images/create.png");
    ^
    symbol: class ImageIcon
    location: class Example2
    Example2.java:119: error: cannot find symbol
    createMethod = new JButton(createIcon);
    ^
    symbol: class JButton
    location: class Example2
    Example2.java:128: error: cannot find symbol
    ImageIcon deleteIcon = new ImageIcon("images/delete.png");
    ^
    symbol: class ImageIcon
    location: class Example2
    Example2.java:128: error: cannot find symbol
    ImageIcon deleteIcon = new ImageIcon("images/delete.png");
    ^
    symbol: class ImageIcon
    location: class Example2
    Example2.java:129: error: cannot find symbol
    deleteMethod = new JButton(deleteIcon);
    ^
    symbol: class JButton
    location: class Example2
    Example2.java:138: error: cannot find symbol
    methodList = new DefaultListModel<String>();
    ^
    symbol: class DefaultListModel
    location: class Example2
    Example2.java:147: error: cannot find symbol
    ImageIcon export = new ImageIcon("images/save.png");
    ^
    symbol: class ImageIcon
    location: class Example2
    Example2.java:147: error: cannot find symbol
    ImageIcon export = new ImageIcon("images/save.png");
    ^
    symbol: class ImageIcon
    location: class Example2
    Example2.java:148: error: cannot find symbol
    exportCode = new JButton(export);
    ^
    symbol: class JButton
    location: class Example2
    Example2.java:169: error: cannot find symbol
    JComboBox<Object> methodType1 = new JComboBox<Object>(buttonTxt1);
    ^
    symbol: class JComboBox
    location: class Example2
    Example2.java:169: error: cannot find symbol
    JComboBox<Object> methodType1 = new JComboBox<Object>(buttonTxt1);
    ^
    symbol: class JComboBox
    location: class Example2
    Example2.java:174: error: cannot find symbol
    JComboBox<Object> methodType2 = new JComboBox<Object>(buttonTxt2);
    ^
    symbol: class JComboBox
    location: class Example2
    Example2.java:174: error: cannot find symbol
    JComboBox<Object> methodType2 = new JComboBox<Object>(buttonTxt2);
    ^
    symbol: class JComboBox
    location: class Example2
    Example2.java:179: error: cannot find symbol
    JComboBox<Object> methodType3 = new JComboBox<Object>(buttonTxt3);
    ^
    symbol: class JComboBox
    location: class Example2
    Example2.java:179: error: cannot find symbol
    JComboBox<Object> methodType3 = new JComboBox<Object>(buttonTxt3);
    ^
    symbol: class JComboBox
    location: class Example2
    Example2.java:184: error: cannot find symbol
    JComboBox<Object> methodType4 = new JComboBox<Object>(buttonTxt4);
    ^
    symbol: class JComboBox
    location: class Example2
    Example2.java:184: error: cannot find symbol
    JComboBox<Object> methodType4 = new JComboBox<Object>(buttonTxt4);
    ^
    symbol: class JComboBox
    location: class Example2
    Example2.java:188: error: cannot find symbol
    JDialog dialog;
    ^
    symbol: class JDialog
    location: class Example2
    Example2.java:208: error: cannot find symbol
    newMethod = new MethodCreation(pick1, pick2, pick3, pick4, methodName);
    ^
    symbol: class MethodCreation
    location: class Example2
    Example2.java:211: error: cannot find symbol
    name = new MethodCreation(methodName);
    ^
    symbol: class MethodCreation
    location: class Example2
    Example2.java:218: error: cannot find symbol
    JComboBox<Object> classType1 = new JComboBox<Object>(buttonTxt1);
    ^
    symbol: class JComboBox
    location: class Example2
    Example2.java:218: error: cannot find symbol
    JComboBox<Object> classType1 = new JComboBox<Object>(buttonTxt1);
    ^
    symbol: class JComboBox
    location: class Example2
    Example2.java:224: error: cannot find symbol
    JComboBox<Object> classType2 = new JComboBox<Object>(buttonTxt2);
    ^
    symbol: class JComboBox
    location: class Example2
    Example2.java:224: error: cannot find symbol
    JComboBox<Object> classType2 = new JComboBox<Object>(buttonTxt2);
    ^
    symbol: class JComboBox
    location: class Example2
    Example2.java:228: error: cannot find symbol
    JDialog dialog;
    ^
    symbol: class JDialog
    location: class Example2
    Example2.java:232: error: cannot find symbol
    methodList = new DefaultListModel<String>();
    ^
    symbol: class DefaultListModel
    location: class Example2
    Example2.java:257: error: cannot find symbol
    newClass = new ClassCreation(pick1, pick2, className);
    ^
    symbol: class ClassCreation
    location: class Example2
    53 errors
    2 warnings

    57 error(s)
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: previous tab's functions no longer working when new tab is created

    Why does the test code need JFileChooser for a GUI problem???
    If you don't understand my answer, don't ignore it, ask a question.

  12. #12
    Junior Member
    Join Date
    Feb 2012
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: previous tab's functions no longer working when new tab is created

    I could only see one possibility that was in the main method. I changed it to Example ex = new Example(); I honestly don't know what else it could be. It compiles in eclipse for me.

  13. #13
    Junior Member
    Join Date
    Feb 2012
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: previous tab's functions no longer working when new tab is created

    Quote Originally Posted by Norm View Post
    Why does the test code need JFileChooser for a GUI problem???
    that was in there with my save code. I just forgot to take it out

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: previous tab's functions no longer working when new tab is created

    Can you create ONE file with all the parts that compiles, executes and shows the problem?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Previous Search history for JtextField in swings
    By kumaruri in forum AWT / Java Swing
    Replies: 2
    Last Post: April 18th, 2012, 08:37 PM
  2. MySQL reading, next en previous button
    By superdave in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 29th, 2011, 09:26 AM
  3. Need to uninstall the previous version of java?
    By akanksha4000 in forum Java Theory & Questions
    Replies: 1
    Last Post: March 25th, 2011, 09:40 AM
  4. slow motion replays of previous games
    By WhatIsJavaAnyhow in forum Java Theory & Questions
    Replies: 10
    Last Post: December 3rd, 2010, 03:45 PM
  5. new arrayList element overwrites all previous
    By twinkletoes in forum Object Oriented Programming
    Replies: 2
    Last Post: April 2nd, 2010, 07:45 AM