Results 1 to 3 of 3
  1. #1
    skatefreak is offline Member
    Join Date
    Jan 2009
    Posts
    18
    Rep Power
    0

    Exclamation Concepts escaping me?!

    Hello there,
    I have an issue here,
    I have a basic GUI that will be executed from a main class.
    This class is built and gives basic options to the user when they log in as an employee, but i need to provide further options if they log in as a manager.

    So, using inheritance (aka 'extends <basic class>') I'm hoping to insert a further three buttons to give the extra options but am not sure how to go about modifying the interface from the second class without re-writing the entire class.

    Java Code:
    package Interfaces;
    
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.LineBorder;
    import java.io.*;
    import java.io.IOException;
    import javax.swing.JOptionPane;
    import java.awt.GridLayout;
    public class main extends JFrame
    {
    
         JButton modify = new JButton();
         JButton alert = new JButton();
         JButton tarrif = new JButton();
         JButton report = new JButton();
         JTextField a = new JTextField();
         JTextField aa = new JTextField();
         JTextField aaa = new JTextField();
         JTextField aaaa = new JTextField();
    
        static void main() {
            JFrame frame = new JFrame("UserName");
            JButton modify = new JButton("Modify User Details");
            JButton alert = new JButton("Alerts");
            JButton tarrif = new JButton("Tarrifs");
            JButton report = new JButton("Lost/Stolen Reports");
            JLabel a = new JLabel(" ");
            JLabel aa = new JLabel(" ");
            JLabel aaa = new JLabel(" ");
            JLabel aaaa = new JLabel(" ");
    
            GridLayout grid;
            grid = new GridLayout(4, 2);
            frame.setLayout(grid);
            frame.add(modify);
            frame.add(a);
            frame.add(alert);
            frame.add(aa);
            frame.add(tarrif);
            frame.add(aaa);
            frame.add(report);
            frame.add(aaaa);
    
            
            
            frame.pack();
            frame.setLocation(20,20);
            frame.setSize(300, 200);
            frame.setVisible(true);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
    
        public static void main(String[] args) {
    
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    main();
                }
            });
        }
    }
    The second class so far just runs the first class method, this however will look to the second class to run the method and wont allow me to modify the interface...

    Java Code:
    package Interfaces;
    
    }
        public static void main (String []args)
        {
        manMain();
        }
    }
    Any thoughts would be much appreciated on the subject, I'm mostly curious as to weather I'm going about this in the right fashion.

    How exactly would I run the superclass but modify it through the subclass?

    Best regards

    -Chris Jvr

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    You may need to re-think your concepts of inheritance when it comes to GUI. In your non-GUI model portion of the program where you create different Employee types, inheritance makes inherent sense as a Manager is an Employee. However when creating GUIs for this, can you truthfully say that a ManagerForm (or whatever its called) is an EmployeeForm? It's kind of a subtle point, but my opinion is that you're stretching inheritance where it may not be best suited going.

  3. #3
    corlettk is offline Member
    Join Date
    Apr 2009
    Location
    Brisbane
    Posts
    86
    Rep Power
    0

    Default

    Further to what Pete said... an alternative to inheritance is good 'ole modularisation... a GUI "module" is a JPanel... unlike a JFrame a JPanel can be a component in a JFrame, a JAplet, or another JPanel (etc, etc, etc)... and you can show multiple JPanels...

    If the manager-only fields/operations should be visually seperate from the base fields/operations then just create two JPanels... only show the ManagersControlPanel to the managers.

    Cheers. Keith.

Similar Threads

  1. [SOLVED] Java compiling concepts
    By SomeGuyOverThere in forum New To Java
    Replies: 9
    Last Post: 08-20-2008, 10:47 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
  •