Results 1 to 6 of 6
  1. #1
    clj89 is offline Member
    Join Date
    Oct 2011
    Posts
    14
    Rep Power
    0

    Default Reference object

    How do you reference an object that is private in a different class? There is this method you see below and I need to reference it in another class. I had tried doing: createCustomerDisplay = new JScrollPane; in the new class but that didn't work and doesn't make sense when I look at again since it won't contain everything it needs to.


    Java Code:
    private JScrollPane createCustomerDisplay() {
    		customerDB = new JTable(new CustomerTableModel(customers));
    
    		customerDB.doLayout();
    		customerDB.setShowGrid(true);
    
    		// make it so only rows can be selected.
    		customerDB.setRowSelectionAllowed(true);
    		customerDB.setColumnSelectionAllowed(false);
    
    		JScrollPane scrollpane = new JScrollPane(customerDB);
    		customerDB.setFillsViewportHeight(true);
    
    		return scrollpane;
    	}

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

    Default Re: Reference object

    I'm not sure I understand what you're trying to do. Can you post more detail about the problem you're trying to solve?

  3. #3
    clj89 is offline Member
    Join Date
    Oct 2011
    Posts
    14
    Rep Power
    0

    Default Re: Reference object

    okay. Overall, once a customer has been added to the system, the display needs to be updated. The above method code is a part of the GUI; MainScreen.java but within the controller for this class;CustomerScreenHandler, it needs to update the display on the GUI. This may help a little more.

    Java Code:
    public void addNewCustomer(String name, String number, String address) {
    		// TODO Adds the customer with the given information into the database
    		pro_Model.addCustomer(name, number, address);
    	}
    		/**
    		 * Updates the main screen
    		 */
    		public void update(){
    		// TODO tells the customer display on the main screen to update.
    		// Added getters and setters to MainScreen.java so you can access the customer database panel (cDB) and the customer display
    		// remove the display from the db
    		// set the customer display to mainScreen.createCustomerDisplay() (You'll need a reference to the main screen object)
    		// add the new customer display to the customer db (center of a border layout)
    		
    		ms_View.getcDB().remove(ms_View.getCustomerDisplay());
    		ms_View.getCustomerDB().remove(ms_View.getCustomerDisplay());
    		
    		ms_View.setCustomerDisplay(customerDisplay);
    		ms_View.setCustomerDisplay(customerDisplay);
    		
    		ms_View.getcDB().add(customerDisplay, BorderLayout.CENTER);
    		ms_View.getCustomerDB().add(customerDisplay, BorderLayout.CENTER);
    	}
    and the reason you see two of each is because I'm waiting to hear from a group member to know which one to use.

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

    Default Re: Reference object

    I don't think that you want your control messing with scrollpanes and removing or adding components. Rather why not have the control either update that data displayed by the view (usually change the text displayed) or update the model and have the view listen for changes to the model and update accordingly?

    For instance, you could extract the JTable's model from the JTable and update the data that it holds, or you could give the JTable an entirely new model. There's no need to mess with the components of the view, methinks.
    Last edited by Fubarable; 10-22-2011 at 10:47 PM.

  5. #5
    clj89 is offline Member
    Join Date
    Oct 2011
    Posts
    14
    Rep Power
    0

    Default Re: Reference object

    That was the initial plan, but the view starting getting real messy so it was thought to move some things to the controller. Guess we should just leave it in the view to make it easier though.

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

    Default Re: Reference object

    Quote Originally Posted by clj89 View Post
    That was the initial plan, but the view starting getting real messy so it was thought to move some things to the controller. Guess we should just leave it in the view to make it easier though.
    Your thoughts of messing with the view components in the controller is much messier still, especially when all you're trying to do is change the data being displayed. So change the data, but leave the components untouched (unless necessary, but here it's not necessary).

Similar Threads

  1. object and reference
    By aizen92 in forum New To Java
    Replies: 11
    Last Post: 04-01-2011, 08:39 PM
  2. Object and reference
    By katie in forum New To Java
    Replies: 2
    Last Post: 10-19-2009, 03:45 PM
  3. Very new to Java, how to reference an object
    By tornado in forum New To Java
    Replies: 3
    Last Post: 12-05-2008, 12:51 AM
  4. Object reference to number
    By dayneo in forum New To Java
    Replies: 4
    Last Post: 05-27-2008, 01:23 PM
  5. Getting the Object Reference Name
    By Deathmonger in forum New To Java
    Replies: 2
    Last Post: 03-12-2008, 02:51 PM

Tags for this Thread

Posting Permissions

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