Page 1 of 3 123 LastLast
Results 1 to 20 of 44
Like Tree1Likes

Thread: Need Help: Eclipse is failing to recognize 3 classes

  1. #1
    MattTuck is offline Member
    Join Date
    Mar 2015
    Location
    A Place With Windows
    Posts
    71
    Rep Power
    0

    Exclamation Need Help: Eclipse is failing to recognize 3 classes

    Hey guys, I'm working in Eclipse getting all sorts of red and not being allowed to compile my program. Can someone explain to me why/what's going on?

    Here are the three parts of the code causing the problem:

    1.)
    Java Code:
        public void PanelSwap() 
        {
            super(new BorderLayout());
            
            contentPane1 = new LogInGUI();
            contentPane2 = new HomeGUI();
    
            add(contentPane1);
        }
    2.)
    Java Code:
    private static void createAndShowGUI() 
    	{
            // Create and set up the window.
            JFrame frame = new JFrame("Athena Pre-Alpha");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
            // Create and set up the content pane.
            JComponent newContentPane = new PanelSwap();
            newContentPane.setOpaque(true); // content panes must be opaque
            frame.setContentPane(newContentPane);
    
            // Display the window.
            frame.pack();
            frame.setVisible(true);
        }
    3.)(in "public static void LogInGUI()")
    Java Code:
    		///User Name, Password, and Enter Button
    		JPanel subpanel_2 = new JPanel();
    		TextField name, password;
    		name = new TextField("User Name");
    		password = new TextField("Password");
    		JButton button = new JButton("Enter");
    		actionPerformed click = new actionPerformed();
            button.addActionListener(this);
    		///Builds SubPanel_2
    		subpanel_2.add(f1_label2);
    		subpanel_2.add(user_type);
    		subpanel_2.add(name);
    		subpanel_2.add(password);
    		subpanel_2.add(button, BorderLayout.SOUTH);
    		///////
    		
    		
    		/*
    To sum it up, it's trying to call me out on not building these classes: LogInGUI(), HomeGUI(), and PanelSwap... And in PanelSwap keeps saying, "Constructor call must be the first statement in a constructor"

    Here is the whole code:
    Java Code:
    /**
     * Author: 			Matt Tucker
     *
     * Date Started:	12AUG15
     * 
     * Description: 	A Java app that is to be organized via unique tabs, 
     * 					representing a different facet of the classroom 
     * 					experience(i.e. Notes, Tests, ect.). The tabs are 
     * 					also to be limited in functionality by the user's 
     * 					roll in the classroom(i.e. parent, student, teacher).
     */
    
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    
    public class Athena extends JPanel implements ActionListener 
    {
    	Boolean register;
    	static String[] type={"Student", "Teacher", "Parent"};
    	Boolean done1=false;
    	static String user_type;
    	JComponent contentPane1, contentPane2;
    	
    
    	public static void main(String[] args) 
    	{
    		javax.swing.SwingUtilities.invokeLater(new Runnable() 
    		{
                public void run() 
                {
                    createAndShowGUI();
                }
            });
    	}
    
        public void PanelSwap() 
        {
            super(new BorderLayout());
            
            contentPane1 = new LogInGUI();
            contentPane2 = new HomeGUI();
    
            add(contentPane1);
        }
    	
    	private static void createAndShowGUI() 
    	{
            // Create and set up the window.
            JFrame frame = new JFrame("Athena Pre-Alpha");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
            // Create and set up the content pane.
            JComponent newContentPane = new PanelSwap();
            newContentPane.setOpaque(true); // content panes must be opaque
            frame.setContentPane(newContentPane);
    
            // Display the window.
            frame.pack();
            frame.setVisible(true);
        }
    	
    	public static void LogInGUI()
    	{
    		JPanel f1_panel = new JPanel();
    		f1_panel.setPreferredSize(new Dimension(550, 500));
    		
    		JPanel subpanel_1= new JPanel();
    		JLabel f1_label=new JLabel("Log In");
    		subpanel_1.add(f1_label, BorderLayout.NORTH);
    		
    		///Operator Type
    		JLabel f1_label2 = new JLabel("Please Select a User Type");
    		JComboBox user_type = new JComboBox(type);
    		////////// ADD LISTENER //////////
    		
    		
    		///User Name, Password, and Enter Button
    		JPanel subpanel_2 = new JPanel();
    		TextField name, password;
    		name = new TextField("User Name");
    		password = new TextField("Password");
    		JButton button = new JButton("Enter");
    		actionPerformed click = new actionPerformed();
            button.addActionListener(this);
    		///Builds SubPanel_2
    		subpanel_2.add(f1_label2);
    		subpanel_2.add(user_type);
    		subpanel_2.add(name);
    		subpanel_2.add(password);
    		subpanel_2.add(button, BorderLayout.SOUTH);
    		///////
    		
    		
    		/*
    		///New User Register
    		JPanel subpanel_3 = new JPanel();
    		JLabel f1_label3 = new JLabel("Not Registered Yet?");
    		JButton reg = new JButton("Register");
    		subpanel_3.add(f1_label3);
    		subpanel_3.add(reg);
    		*/
    		
    		
    		///Adds Subpanels to Main Panel(f1_panel)
    		f1_panel.add(subpanel_1, BorderLayout.NORTH);
    		f1_panel.add(subpanel_2, BorderLayout.CENTER);
    		//f1_panel.add(subpanel_3, BorderLayout.SOUTH);
    	
    	}
    	
    	public static void HomeGUI()
    	{
    		
    		////	Tabs	////
    		JTabbedPane tab_panels = new JTabbedPane();
    		////**Tab 1_Home**////
    		// Create Panel
    		JPanel panel_1 = new JPanel();
    		panel_1.setPreferredSize(new Dimension(550, 500));
    		// "JTabbedPane Object".addTab("String", component);
    		tab_panels.addTab("Home", panel_1);
    		
    		////**Tab 2_Grades**////
    		// Create Panel
    		JPanel panel_2 = new JPanel();
    		panel_2.setPreferredSize(new Dimension(550, 500));
    		// "JTabbedPane Object".addTab("String", component);
    		if(user_type=="Teacher")
    		{
    			//Show All Grades and Class Average
    			/*
    			 * Pull data from class_grades.txt
    			 * Graph each student's grade
    			 * Graph the class average grade
    			 */
    		}
    		if(user_type=="Student")
    		{
    			//Show Student Grades and Class Average
    			/* 
    			 * Graph the student's grade
    			 * Graph the class average grade
    			 */
    		}
    		if(user_type=="Parent")
    		{
    			//Show Student Grades and Class Average
    			/* 
    			 * Graph the student's grade
    			 * Graph the class average grade
    			 */
    		}
    		tab_panels.addTab("Grades", panel_2);
    		////**Tab 3_Notes**////
    		JPanel panel_3 = new JPanel();
    		
    		if(user_type=="Teacher")
    		{
    			//Add Notes and Show All Student Notes 
    		}
    		if(user_type=="Student")
    		{
    			//Show Teacher's Notes and Student's Notes
    		}
    		if(user_type=="Parent")
    		{
    			//Show Teacher's Notes and Student's Notes
    		}		
    		tab_panels.addTab("Notes", panel_3);
    		
    		
    		////**Tab 4_Presentation**////
    		JPanel panel_4 = new JPanel();
    		if(user_type=="Teacher")
    		{
    			//Show Class Presentations
    		}
    		if(user_type=="Student")
    		{
    			//Show Class Presentations
    		}
    		if(user_type=="Parent")
    		{
    			//Show Class Presentations
    		}
    		tab_panels.addTab("Presentation", panel_4);
    		
    		////**Tab 5_Tests and Quizzes**////
    		JPanel panel_5 = new JPanel();
    		if(user_type=="Teacher")
    		{
    			//Add/Make Tests and Quizzes
    		}
    		if(user_type=="Student")
    		{
    			//Show Dates for Tests and Quizzes and Allow Access to Take them
    		}
    		if(user_type=="Parent")
    		{
    			//Show Dates for Tests and Quizzes
    		}
    		tab_panels.addTab("Tests and Quizzes", panel_5);
    		
    		////**Tab 6_Homework**////
    		JPanel panel_6 = new JPanel();
    		
    		if(user_type=="Teacher")
    		{
    			//Add/Make Homework
    		}
    		if(user_type=="Student")
    		{
    			//Show Dates for Homework and Allow Access to Take them
    		}
    		if(user_type=="Parent")
    		{
    			//Show Dates for Homework and Related Notes
    		}
    		tab_panels.addTab("Homework", panel_6);
    		
    	}
    	
    	public void actionPerformed(ActionEvent arg0) 
    	{
    
            for (Component component : getComponents())
                    remove(contentPane1);
                    add(contentPane2);
    
            repaint();
            revalidate();	
    	}
    	
    	/*
    	public static void RegisterGUI()
    	{
    		
    	}
    	*/
        
    
    
    }
    Last edited by Norm; 08-13-2015 at 04:16 AM. Reason: Added * for correct comments

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Need Help: Eclipse is failing to recognize 3 classes

    PanelSwap is a method so you can't use super in that context. LogInGUI and HomeGUI are methods, not classes so you can't instantiate them. And there are a few other problems too. You should probably go thru the tutorials (see my signature).

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Need Help: Eclipse is failing to recognize 3 classes

    Note re Java naming conventions: Class names should begin with an uppercase letter, method names with a lowercase letter.

    Also class names should be things or nouns and method names should be actions or verbs.
    The names: LogInGUI and HomeGUI look like the names of classes
    createLogInGUI and createHomeGUI would be the names of methods.
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    MattTuck is offline Member
    Join Date
    Mar 2015
    Location
    A Place With Windows
    Posts
    71
    Rep Power
    0

    Default Re: Need Help: Eclipse is failing to recognize 3 classes

    So, I rewrote it, and got most of the errors to go away.... I'm not seeing why I'm still getting an error for PanelSwap... I followed another tutorial to a t(posted below) that worked using this structure.


    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    
    import javax.swing.*;
    
    public class Athena_2 extends JPanel implements ActionListener 
    {
    	Boolean register;
    	static String[] type={"Student", "Teacher", "Parent"};
    	Boolean done1=false;
    	static String user_type;
    	JComponent contentPane1, contentPane2;
    
        JPanel f1_panel = new JPanel();
        JTabbedPane tab_panels = new JTabbedPane();
    
        public PanelSwap() 
        {
            //////////////LOG IN Screen////////////////
            f1_panel.setPreferredSize(new Dimension(550, 500));
    		
    		JPanel subpanel_1= new JPanel();
    		JLabel f1_label=new JLabel("Log In");
    		subpanel_1.add(f1_label, BorderLayout.NORTH);
    		
    		///Operator Type
    		JLabel f1_label2 = new JLabel("Please Select a User Type");
    		JComboBox user_type_box = new JComboBox(type);
    		
    		
    		///User Name, Password, and Enter Button
    		JPanel subpanel_2 = new JPanel();
    		TextField name, password;
    		name = new TextField("User Name");
    		password = new TextField("Password");
    		JButton button = new JButton("Enter");
    		button.addActionListener(this);
    		///Builds SubPanel_2
    		subpanel_2.add(f1_label2);
    		subpanel_2.add(user_type_box);
    		subpanel_2.add(name);
    		subpanel_2.add(password);
    		subpanel_2.add(button, BorderLayout.SOUTH);
    		///////
    		
    		
    		
    		///New User Register
    		//JPanel subpanel_3 = new JPanel();
    		//JLabel f1_label3 = new JLabel("Not Registered Yet?");
    		//JButton reg = new JButton("Register");
    		//subpanel_3.add(f1_label3);
    		//subpanel_3.add(reg);
    		
    		
    		
    		///Adds Subpanels to Main Panel(f1_panel)
    		f1_panel.add(subpanel_1, BorderLayout.NORTH);
    		f1_panel.add(subpanel_2, BorderLayout.CENTER);
    		//f1_panel.add(subpanel_3, BorderLayout.SOUTH);
            
            
            ///////////////////////////Tabs_Athena//////////////////////////
    		
    		////**Tab 1_Home**////
    		// Create Panel
    		JPanel panel_1 = new JPanel();
    		panel_1.setPreferredSize(new Dimension(550, 500));
    		// "JTabbedPane Object".addTab("String", component);
    		tab_panels.addTab("Home", panel_1);
    		
    		////**Tab 2_Grades**////
    		// Create Panel
    		JPanel panel_2 = new JPanel();
    		panel_2.setPreferredSize(new Dimension(550, 500));
    		// "JTabbedPane Object".addTab("String", component);
    		if(user_type=="Teacher")
    		{
    			//Show All Grades and Class Average
    			//
    			// Pull data from class_grades.txt
    			// Graph each student's grade
    			// Graph the class average grade
    			//
    		}
    		if(user_type=="Student")
    		{
    			//Show Student Grades and Class Average
    			// 
    			// Graph the student's grade
    			// Graph the class average grade
    			//
    		}
    		if(user_type=="Parent")
    		{
    			//Show Student Grades and Class Average
    			// 
    			// Graph the student's grade
    			// Graph the class average grade
    			//
    		}
    		tab_panels.addTab("Grades", panel_2);
    		////**Tab 3_Notes**////
    		JPanel panel_3 = new JPanel();
    		
    		if(user_type=="Teacher")
    		{
    			//Add Notes and Show All Student Notes 
    		}
    		if(user_type=="Student")
    		{
    			//Show Teacher's Notes and Student's Notes
    		}
    		if(user_type=="Parent")
    		{
    			//Show Teacher's Notes and Student's Notes
    		}		
    		tab_panels.addTab("Notes", panel_3);
    		
    		
    		////**Tab 4_Presentation**////
    		JPanel panel_4 = new JPanel();
    		if(user_type=="Teacher")
    		{
    			//Show Class Presentations
    		}
    		if(user_type=="Student")
    		{
    			//Show Class Presentations
    		}
    		if(user_type=="Parent")
    		{
    			//Show Class Presentations
    		}
    		tab_panels.addTab("Presentation", panel_4);
    		
    		////**Tab 5_Tests and Quizzes**////
    		JPanel panel_5 = new JPanel();
    		if(user_type=="Teacher")
    		{
    			//Add/Make Tests and Quizzes
    		}
    		if(user_type=="Student")
    		{
    			//Show Dates for Tests and Quizzes and Allow Access to Take them
    		}
    		if(user_type=="Parent")
    		{
    			//Show Dates for Tests and Quizzes
    		}
    		tab_panels.addTab("Tests and Quizzes", panel_5);
    		
    		////**Tab 6_Homework**////
    		JPanel panel_6 = new JPanel();
    		
    		if(user_type=="Teacher")
    		{
    			//Add/Make Homework
    		}
    		if(user_type=="Student")
    		{
    			//Show Dates for Homework and Allow Access to Take them
    		}
    		if(user_type=="Parent")
    		{
    			//Show Dates for Homework and Related Notes
    		}
    		tab_panels.addTab("Homework", panel_6);
            /////////////Add panels////////
            add(f1_panel);
        }
    
        /** Listens to the buttons and perfomr the swap. */
        public void actionPerformed(ActionEvent e) 
        {
    
            for (Component component : getComponents())
            	{
            	remove(f1_panel);
            	add(tab_panels);
            	}
    
            repaint();
            revalidate();
        }
    
        /*
         * Create the GUI and show it.
         */
        private static void createAndShowGUI() 
        {
            // Create and set up the window.
            JFrame frame = new JFrame("PanelSwap");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
            // Create and set up the content pane.
            JComponent newContentPane = new PanelSwap();
            newContentPane.setOpaque(true); // content panes must be opaque
            frame.setContentPane(newContentPane);
    
            // Display the window.
            frame.pack();
            frame.setVisible(true);
        }
    
        public static void main(String[] args) 
        {
            // Creates and Shows GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() 
            {
                public void run() {
                    createAndShowGUI();
                }
            });
        }
    }

    Here's the tutorial example:
    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class PanelSwap extends JPanel implements ActionListener {
    
        JPanel firstPanel = new JPanel();
        JPanel secondPanel = new JPanel();
    
        public PanelSwap() {
            super(new BorderLayout());
            firstPanel.setBackground(Color.RED);
    
            secondPanel.setBackground(Color.YELLOW);
    
            JButton swap1 = new JButton("SwapToYellow");
            swap1.addActionListener(this);
    
            JButton swap2 = new JButton("SwapToRed");
            swap2.addActionListener(this);
    
            firstPanel.add(swap1);
            secondPanel.add(swap2);
    
            add(firstPanel);
        }
    
        /** Listens to the buttons and perfomr the swap. */
        public void actionPerformed(ActionEvent e) {
    
            for (Component component : getComponents())
                if (firstPanel == component) {
                    remove(firstPanel);
                    add(secondPanel);
    
                } else {
                    remove(secondPanel);
                    add(firstPanel);
                }
    
            repaint();
            revalidate();
        }
    
        //
        // Create the GUI and show it. For thread safety, this method should be
        // invoked from the event-dispatching thread.
        //
        private static void createAndShowGUI() {
            // Create and set up the window.
            JFrame frame = new JFrame("PanelSwap");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
            // Create and set up the content pane.
            JComponent newContentPane = new PanelSwap();
            newContentPane.setOpaque(true); // content panes must be opaque
            frame.setContentPane(newContentPane);
    
            // Display the window.
            frame.pack();
            frame.setVisible(true);
        }
    
        public static void main(String[] args) {
            // Schedule a job for the event-dispatching thread:
            // creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
                }
            });
        }
    }
    Last edited by MattTuck; 08-13-2015 at 06:22 AM.

  5. #5
    MattTuck is offline Member
    Join Date
    Mar 2015
    Location
    A Place With Windows
    Posts
    71
    Rep Power
    0

    Default Re: Need Help: Eclipse is failing to recognize 3 classes

    Nevermind.... it was a DUHHHHHHH issue

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Need Help: Eclipse is failing to recognize 3 classes

    The "I'm comparing objects with == instead of equals()" kind of duurrr?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: Need Help: Eclipse is failing to recognize 3 classes

    IN this case it's a "my constructor name does not match the class name"...:)
    MattTuck likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    MattTuck is offline Member
    Join Date
    Mar 2015
    Location
    A Place With Windows
    Posts
    71
    Rep Power
    0

    Default Re: Need Help: Eclipse is failing to recognize 3 classes

    So, I fixed the method name and am starting to add all the ins and outs to the program... one of them being, when the user logs in and selects a user type, in the user_type_box combo box, it updates the string, user_type. It doesn't seem to be working.... I made the combo box a universal, up dated the listener, and added it to the combo box. the listener no reads:
    Java Code:
    public void actionPerformed(ActionEvent e) 
        {
    
            for (Component component : getComponents())
            {
            	if(button == component)
            	{
            	remove(f1_panel);
            	add(tab_panels);
            	}
            	
            	else if(user_type_box == component)
            	{
            		user_type.equals(user_type_box.getSelectedItem());
            	}
            }
    
            repaint();
            revalidate();
        }

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Need Help: Eclipse is failing to recognize 3 classes

    It doesn't seem to be working
    Please explain.

    NOTE: Comments are very useful for explaining what sections of code are supposed to do and how they are going to do it. Can you add comments to your code explaining what the method you just posted is supposed to be doing?
    Last edited by Norm; 08-14-2015 at 04:01 AM.
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    MattTuck is offline Member
    Join Date
    Mar 2015
    Location
    A Place With Windows
    Posts
    71
    Rep Power
    0

    Default Re: Need Help: Eclipse is failing to recognize 3 classes

    Here is that chunk with a few added comments
    Java Code:
    public void actionPerformed(ActionEvent e) //Action Listener 
        {
    
            for (Component component : getComponents())//Get's name of Object the Listener is being applied to/used by
            {
            	if(button == component)//If the Object is the Button Object(Enter Button) on the "Log In" Panel
            	{
            	remove(f1_panel);//Remove "Log In" Panel
            	add(tab_panels);//Show "Athena" Panel... Panel with multiple tabs
            	}
            	
            	else if(user_type_box == component)//If the Object is the ComboBox, user_type_box, on the "Log In" Panel
            	{
            		user_type.equals(user_type_box.getSelectedItem());//Set the string, user_type, equal to the value selected in the ComboBox, user_type_box
            	}
            }
    
            repaint();//Rebuild JFrame
            revalidate();
        }




    Here is the entire thing:
    Java Code:
    /*
     * Author: 			Matt Tucker
     *
     * Date Started:	12AUG15
     * 
     * Description: 	A Java app that is to be organized via unique tabs, 
     * 					representing a different facet of the classroom 
     * 					experience(i.e. Notes, Tests, ect.). The tabs are 
     * 					also to be limited in functionality by the user's 
     * 					roll in the classroom(i.e. parent, student, teacher).
     *//
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class Athena_2 extends JPanel implements ActionListener 
    {
    	static String[] type={"Student", "Teacher", "Parent"};//User type Array
    	String user_type;//User type String
        String[] period={"Class Selection"};//Class String Array
        String[] student={"Student Selection"};//Student Array
    	JComboBox user_type_box = new JComboBox(type);//Builds Drop Down Box Object
    	JComboBox period_box = new JComboBox(period);//Builds Drop Down Box Object
    	JComboBox student_box = new JComboBox(student);//Builds Drop Down Box Object
    	JButton button = new JButton("Enter");//Builds "Enter" Button
        JPanel f1_panel = new JPanel();
        JTabbedPane tab_panels = new JTabbedPane();
    
        public Athena_2() 
        {
            //////////////LOG IN Screen////////////////
            f1_panel.setPreferredSize(new Dimension(550, 500));
    		
    		JPanel subpanel_1= new JPanel();
    		JLabel f1_label=new JLabel("Log In");
    		subpanel_1.add(f1_label, BorderLayout.NORTH);
    		
    		///Operator Type
    		JLabel f1_label2 = new JLabel("Please Select a User Type");
    		
    		//Listeners
    		user_type_box.addActionListener(this);
    		button.addActionListener(this);
    		
    		///User Name, Password, and Enter Button
    		JPanel subpanel_2 = new JPanel();
    		TextField name, password;
    		name = new TextField("User Name");
    		password = new TextField("Password");
    		///Builds SubPanel_2
    		subpanel_2.add(f1_label2);
    		subpanel_2.add(user_type_box);
    		subpanel_2.add(name);
    		subpanel_2.add(password);
    		subpanel_2.add(button, BorderLayout.SOUTH);
    		
    		
    		
    		///New User Register
    		JPanel subpanel_3 = new JPanel();
    		JLabel f1_label3 = new JLabel("Not Registered Yet?");
    		JButton reg = new JButton("Register");
    		subpanel_3.add(f1_label3);
    		subpanel_3.add(reg);
    		
    		
    		
    		///Adds Subpanels to Main Panel(f1_panel)
    		f1_panel.add(subpanel_1, BorderLayout.NORTH);
    		f1_panel.add(subpanel_2, BorderLayout.CENTER);
    		//f1_panel.add(subpanel_3, BorderLayout.SOUTH);
            
            
            ///////////////////////////Tabs_Athena//////////////////////////
    		
    		////**Tab 1_Home**////
    		// Create Panel
    		JPanel panel_1 = new JPanel();
    		panel_1.setPreferredSize(new Dimension(550, 500));
    		panel_1.add(period_box);
    		tab_panels.addTab("Home", panel_1); // "JTabbedPane Object".addTab("String", component);
    		
    		////**Tab 2_Grades**////
    		// Create Panel
    		JPanel panel_2 = new JPanel();
    		panel_2.setPreferredSize(new Dimension(550, 500));
    		if(user_type=="Teacher")
    		{
    			panel_2.add(student_box);
    			//Show All Grades and Class Average
    			/*
    			 * Pull data from class_grades.txt
    			 * Graph each student's grade
    			 * Graph the class average grade
    			 *//
    		}
    		if(user_type=="Student")
    		{
    			//Show Student Grades and Class Average
    			/* 
    			 * Graph the student's grade
    			 * Graph the class average grade
    			 *//
    		}
    		if(user_type=="Parent")
    		{
    			//Show Student Grades and Class Average
    			/* 
    			 * Graph the student's grade
    			 * Graph the class average grade
    			 *//
    		}
    		tab_panels.addTab("Grades", panel_2);// "JTabbedPane Object".addTab("String", component);
    		
    		////**Tab 3_Notes**////
    		JPanel panel_3 = new JPanel();
    		
    		if(user_type=="Teacher")
    		{
    			//Add Notes and Show All Student Notes 
    		}
    		if(user_type=="Student")
    		{
    			//Show Teacher's Notes and Student's Notes
    		}
    		if(user_type=="Parent")
    		{
    			//Show Teacher's Notes and Student's Notes
    		}		
    		tab_panels.addTab("Notes", panel_3);
    		
    		////**Tab 4_Presentation**////
    		JPanel panel_4 = new JPanel();
    		if(user_type=="Teacher")
    		{
    			//Show Class Presentations
    		}
    		if(user_type=="Student")
    		{
    			//Show Class Presentations
    		}
    		if(user_type=="Parent")
    		{
    			//Show Class Presentations
    		}
    		tab_panels.addTab("Presentation", panel_4);
    		
    		////**Tab 5_Tests and Quizzes**////
    		JPanel panel_5 = new JPanel();
    		if(user_type=="Teacher")
    		{
    			//Add/Make Tests and Quizzes
    		}
    		if(user_type=="Student")
    		{
    			//Show Dates for Tests and Quizzes and Allow Access to Take them
    		}
    		if(user_type=="Parent")
    		{
    			//Show Dates for Tests and Quizzes
    		}
    		tab_panels.addTab("Tests and Quizzes", panel_5);
    		
    		////**Tab 6_Homework**////
    		JPanel panel_6 = new JPanel();
    		
    		if(user_type=="Teacher")
    		{
    			//Add/Make Homework
    		}
    		if(user_type=="Student")
    		{
    			//Show Dates for Homework and Allow Access to Take them
    		}
    		if(user_type=="Parent")
    		{
    			//Show Dates for Homework and Related Notes
    		}
    		tab_panels.addTab("Homework", panel_6);
            
    		/////////////Add panel////////
            add(f1_panel);
        }
    
        ///// Listener //////
        public void actionPerformed(ActionEvent e) 
        {
    
            for (Component component : getComponents())
            {
            	if(button == component)
            	{
            	remove(f1_panel);
            	add(tab_panels);
            	}
            	
            	else if(user_type_box == component)
            	{
            		user_type.equals(user_type_box.getSelectedItem());
            	}
            }
    
            repaint();
            revalidate();
        }
    
        ////Builds GUI
        private static void createAndShowGUI() 
        {
            // Create and set up the window.
            JFrame frame = new JFrame("PanelSwap");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
            // Create and set up the content pane.
            JComponent newContentPane = new Athena_2();
            newContentPane.setOpaque(true); // content panes must be opaque
            frame.setContentPane(newContentPane);
    
            // Display the window.
            frame.pack();
            frame.setVisible(true);
        }
        
        /////Presents and execute GUI
        public static void main(String[] args) 
        {
            // Creates and Shows GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() 
            {
                public void run() {
                    createAndShowGUI();
                }
            });
        }
    }
    Last edited by MattTuck; 08-14-2015 at 04:44 AM.

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Need Help: Eclipse is failing to recognize 3 classes

    Why does the actionPerformed() method get a list of all the components and go through all of them comparing them against two components?
    Would you expect those two components to always be in that list?
    When would either of them not to be in the list?

    Note: The ActionEvent object has a reference to the component that had the event. Call its method to get the source of the event if that is what you want.
    If you don't understand my response, don't ignore it, ask a question.

  12. #12
    MattTuck is offline Member
    Join Date
    Mar 2015
    Location
    A Place With Windows
    Posts
    71
    Rep Power
    0

    Default Re: Need Help: Eclipse is failing to recognize 3 classes

    This is what I'm understanding you to be suggesting....

    Java Code:
    public void actionPerformed(ActionEvent e) //Action Listener 
        {
     
            for (Component component : getComponents())//Get's name of Object the Listener is being applied to/used by
            {
                user_type.equals(user_type_box.getSelectedItem());//Set the string, user_type, equal to the value selected in the ComboBox, user_type_box
                remove(f1_panel);//Remove "Log In" Panel
                add(tab_panels);//Show "Athena" Panel... Panel with multiple tabs
            }
     
            repaint();//Rebuild JFrame
            revalidate();
        }
    In short, drop the if statement...

    Or are you saying that I can drop the if statement, AND throw
    Java Code:
                user_type.equals(user_type_box.getSelectedItem());//Set the string, user_type, equal to the value selected in the ComboBox, user_type_box
    up top into Athena_2?

  13. #13
    MattTuck is offline Member
    Join Date
    Mar 2015
    Location
    A Place With Windows
    Posts
    71
    Rep Power
    0

    Default Re: Need Help: Eclipse is failing to recognize 3 classes

    At this point it might be helpful for me to explain, what I am looking for is dropdown box("Students....") to appear in the "Grades" tab when "Teacher" is selected in the "Log In" panel... However for it, the "Grades" tab, to be empty when anything else is selected("Student" or "Parent").

  14. #14
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Need Help: Eclipse is failing to recognize 3 classes

    Java Code:
    user_type.equals(user_type_box.getSelectedItem());
    Very creative thinking there. But it's wrong. I suggest you do a google for "java equals" and see what you come up with.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Need Help: Eclipse is failing to recognize 3 classes

    I still don't understand why there is a for loop. Can you explain why it is needed?

    helpful for me to explain,
    The comments in post#13 should be in the code in post#12
    If you don't understand my response, don't ignore it, ask a question.

  16. #16
    MattTuck is offline Member
    Join Date
    Mar 2015
    Location
    A Place With Windows
    Posts
    71
    Rep Power
    0

    Default Re: Need Help: Eclipse is failing to recognize 3 classes

    No real reason to be there I suppose, over engineering the code... That said, dropping the for-loop and making "component" a universal... It still fails to work...

  17. #17
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Need Help: Eclipse is failing to recognize 3 classes

    It still fails to work...
    please explain what the code is supposed to do. The comments with the code don't explain clearly what it is trying to do.
    If you don't understand my response, don't ignore it, ask a question.

  18. #18
    MattTuck is offline Member
    Join Date
    Mar 2015
    Location
    A Place With Windows
    Posts
    71
    Rep Power
    0

    Default Re: Need Help: Eclipse is failing to recognize 3 classes

    Gimbal2,
    Java Code:
    user_type=(String) (user_type_box.getSelectedItem());
    Because "==" and ".equals" are used to compare values, right?

  19. #19
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Need Help: Eclipse is failing to recognize 3 classes

    == to compare primitives and to test if two object variables refer to the same object.
    equals() to compare the contents of two objects
    If you don't understand my response, don't ignore it, ask a question.

  20. #20
    MattTuck is offline Member
    Join Date
    Mar 2015
    Location
    A Place With Windows
    Posts
    71
    Rep Power
    0

    Default Re: Need Help: Eclipse is failing to recognize 3 classes

    Ok, so at this point in the code, what I'm wanting is to be presented with a nice "Log In" screen(does not check user name and password yet). While on the "Log In" screen the user is presented with a drop down requesting the user type(JComboBox user_type_box{"Teacher", "Student", "Parent"}), and two text box, one for user name and the other for password, then finally an enter button to change the panel(f1_panel to tab_panels).

    The thought here is that I can use the JComboBox to define the type of user(user_type=(String) (user_type_box.getSelectedItem())), which will changed what is presented in the following page.


    Here is the code again, in its entirety with added notes/comments:
    Java Code:
    //
     * Author: 			Matt Tucker
     *
     * Date Started:	14AUG15
     * 
     * Description: 	A Java app that is to be organized via unique tabs, 
     * 					representing a different facet of the classroom 
     * 					experience(i.e. Notes, Tests, ect.). The tabs are 
     * 					also to be limited in functionality by the user's 
     * 					roll in the classroom(i.e. parent, student, teacher).
     * 
     * 
     * NOTE:			1.)Things to still be added: Registration(Prompt and 
     * 					Panel), user_name and password check, populate tabs.
     * 
     * 					2.)Things to figure out: How to pass selected value
     * 					from user_type_box to user_type.
     * 					
     //
    
    
    import java.awt.*;
    import java.awt.event.*;
    
    import javax.swing.*;
     
    public class Athena extends JPanel implements ActionListener 
    {
    	static String[] type={"Student", "Teacher", "Parent"};//User type Array
    	String user_type;//User type String
        String[] period={"Class Selection"};//Class String Array
        String[] student={"Student Selection"};//Student Array
    	JComboBox user_type_box = new JComboBox(type);//Builds Drop Down Box Object
    	JComboBox period_box = new JComboBox(period);//Builds Drop Down Box Object
    	JComboBox student_box = new JComboBox(student);//Builds Drop Down Box Object
    	JButton button = new JButton("Enter");//Builds "Enter" Button
    	//JButton reg = new JButton("Register");//
        JPanel f1_panel = new JPanel();
        JTabbedPane tab_panels = new JTabbedPane();
     
        public Athena() 
        {
            ////////////////LOG IN Screen//////////////////
            f1_panel.setPreferredSize(new Dimension(550, 500));
            
            ///Title
            JPanel subpanel_1= new JPanel();
            JLabel f1_label=new JLabel("Log In");
            subpanel_1.add(f1_label, BorderLayout.NORTH);
            
            ///Operator Type
            JLabel f1_label2 = new JLabel("Please Select a User Type");//Prompt for "user_type_box" 
    //which will be used to define a value for "user_type"
            
            ///User Name, Password, and Enter Button
            JPanel subpanel_2 = new JPanel();
            TextField name, password;
            name = new TextField("User Name");//Text Box to Enter User Name
            password = new TextField("Password");//Text Box to Enter Password
            JButton button = new JButton("Enter");//Enter Button to Navigate to next Panel(*Later, 
    //Checks Values Entered into User Name and Password*)
            button.addActionListener(this);
            
            ///Builds SubPanel_2
            subpanel_2.add(f1_label2);
            subpanel_2.add(user_type_box);//"user_type_box" is used to define a value for "user_type"
            subpanel_2.add(name);
            subpanel_2.add(password);
            subpanel_2.add(button, BorderLayout.SOUTH); 
            
            ///New User Register(*ADD LATER, WILL BE USED TO NAVIGATE TO REGISTRATION*)
            //JPanel subpanel_3 = new JPanel();
            //JLabel f1_label3 = new JLabel("Not Registered Yet?");
            //JButton reg = new JButton("Register");
            //subpanel_3.add(f1_label3);
            //subpanel_3.add(reg);
            
            ///Adds Subpanels to f1_panel
            f1_panel.add(subpanel_1, BorderLayout.NORTH);
            f1_panel.add(subpanel_2, BorderLayout.CENTER);
            //f1_panel.add(subpanel_3, BorderLayout.SOUTH);
    
            /////////////Add panel//////////
            add(f1_panel);
             
             
            ///////////////////////////Tabs_Athena////////////////////////// 
            
            ////**Tab 1_Home**////
            // Create Panel
            JPanel panel_1 = new JPanel();
            panel_1.setPreferredSize(new Dimension(550, 500));
    		//panel_1.add(period_box); //*ADD LATER LIMIT TAB PRESENTATION BASED ON SELECTED 
    //CLASS TIME/PERIOD*
            tab_panels.addTab("Home", panel_1);// "JTabbedPane Object".addTab("String", component);
             
            ////**Tab 2_Grades**////
            // Create Panel
            JPanel panel_2 = new JPanel();
            panel_2.setPreferredSize(new Dimension(550, 500));
            //The following if-statements limit what is presented in the tabs based on "user_type"
            //"user_type" is defined by earlier selection in "user_type_box"
            if(user_type=="Teacher")//If "Teacher" is selected, "Grades" Tab should be populated 
    //Accordingly
            {
            	panel_2.add(student_box);
                //Show All Grades and Class Average
                //
                // Pull data from class_grades.txt
                // Graph each student's grade
                // Graph the class average grade
                //
            }
            if(user_type=="Student")
            {
                //Show Student Grades and Class Average
                // 
                // Graph the student's grade
                // Graph the class average grade
                //
            }
            if(user_type=="Parent")
            {
                //Show Student Grades and Class Average
                // 
                // Graph the student's grade
                // Graph the class average grade
                //
            }
            tab_panels.addTab("Grades", panel_2);
            
            ////**Tab 3_Notes**////
            JPanel panel_3 = new JPanel();
             
            if(user_type=="Teacher")
            {
                //Add/Delete/Show Notes and Show All Student Notes 
            }
            if(user_type=="Student")
            {
                //Show Teacher's Notes and Student's Notes
            }
            if(user_type=="Parent")
            {
                //Show Teacher's Notes and Student's Notes
            }       
            tab_panels.addTab("Notes", panel_3);// "JTabbedPane Object".addTab("String", component);
             
             
            ////**Tab 4_Presentation**////
            JPanel panel_4 = new JPanel();
            if(user_type=="Teacher")
            {
                //Add/Delete/Show Class Presentations
            }
            if(user_type=="Student")
            {
                //Show Class Presentations
            }
            if(user_type=="Parent")
            {
                //Show Class Presentations
            }
            tab_panels.addTab("Presentation", panel_4);
             
            ////**Tab 5_Tests and Quizzes**////
            JPanel panel_5 = new JPanel();
            if(user_type=="Teacher")
            {
                //Add/Delete/Make/Show Tests and Quizzes
            }
            if(user_type=="Student")
            {
                //Show Dates for Tests and Quizzes and Allow Access to Take them
            }
            if(user_type=="Parent")
            {
                //Show Dates for Tests and Quizzes
            }
            tab_panels.addTab("Tests and Quizzes", panel_5);
             
            ////**Tab 6_Homework**////
            JPanel panel_6 = new JPanel();
             
            if(user_type=="Teacher")
            {
                //Add/Delete/Make/Show Homework
            }
            if(user_type=="Student")
            {
                //Show Dates for Homework and Allow Access to Take them
            }
            if(user_type=="Parent")
            {
                //Show Dates for Homework and Related Notes
            }
            tab_panels.addTab("Homework", panel_6);
        }
     
        /////////////LISETENER////////////////////
        public void actionPerformed(ActionEvent e) 
        {
            user_type=(String) (user_type_box.getSelectedItem());
            remove(f1_panel);
            add(tab_panels);
            repaint();
            revalidate();
            System.out.println("This is the selected user type: "+user_type);//Checks if value is being 
    //passed to user_type
            //Note: Why is it failing to modify the tabs? I expect the "Grades" tab to be populated by a 
    //ComboBox when "Teacher" is selected!
        }
     
        ///////////////BUILDS GUI////////////////////
        private static void createAndShowGUI() 
        {
            // Creates and Sets Up the Window
            JFrame frame = new JFrame("Athena");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
            // Create and Set Up the Content Pane.
            JComponent newContentPane = new Athena();
            newContentPane.setOpaque(true);
            frame.setContentPane(newContentPane);
     
            // Display the window.
            frame.pack();
            frame.setVisible(true);
        }
     
        public static void main(String[] args) 
        {
            // Creates and Shows GUI
            javax.swing.SwingUtilities.invokeLater(new Runnable() 
            {
                public void run() {
                    createAndShowGUI();
                }
            });
        }
    }
    Last edited by MattTuck; 08-14-2015 at 09:27 PM.

Page 1 of 3 123 LastLast

Similar Threads

  1. Writing classes in Eclipse
    By killmenow in forum Eclipse
    Replies: 6
    Last Post: 05-20-2012, 04:06 PM
  2. How to use 3rd party classes in Eclipse
    By hahncj55408 in forum New To Java
    Replies: 2
    Last Post: 12-02-2011, 08:40 AM
  3. Replies: 0
    Last Post: 06-30-2011, 03:46 PM
  4. Replies: 0
    Last Post: 02-01-2009, 08:43 AM
  5. Replies: 0
    Last Post: 12-04-2007, 11:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •