Results 1 to 7 of 7
  1. #1
    brontolo is offline Member
    Join Date
    Sep 2010
    Posts
    3
    Rep Power
    0

    Default Pattern Observer

    Hello everyone, I have to make a spreadsheet in java using the pattern within the spreadsheet can be inserted individual values or formulas (addition and subtraction), the problem is that whenever you change a value you must also update formulas that has that value. I thought of using the Observer pattern, but can not implement it correctly you have any suggestions for me on how to connect values and formulas observers thanks

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Can you explain what formulas are you talking about? Seems to me somewhere you've hard coded values and now it's not possible to change time to time, which is a bad practice.

  3. #3
    brontolo is offline Member
    Join Date
    Sep 2010
    Posts
    3
    Rep Power
    0

    Default

    For example, I have the cell with row 2 and column 2 and the value 12 and the cell with row 3 and column 3 with value 10. I also cell line 4 and column 4 in which I write the sum of 12 + 10, specifying the coordinates of the cells on. Now if I edit one of two values (12 or 10) I should automatically update the value of the formula in cell line 4 and column 4. I do not know if I was clear ...
    I need to update the value automatically because the track and asked me why I thought of using the Observer pattern but can not implement it properly so that only updates the values but not formulas in which these values are present.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    If you are working on a spreadsheet with all these things you've mentioned, what Java has to do with. You should explain those kind of thing clearly as much as possible. We cannot imagine stuff over here. :)

  5. #5
    brontolo is offline Member
    Join Date
    Sep 2010
    Posts
    3
    Rep Power
    0

    Default

    Should I make a desktop application that simulates a spreadsheet using java .. the sheet is achieved through a JTable in a JPanel added, all within a JFrame. I need for a university exam ... if you can attach the track ..

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,830
    Rep Power
    19

    Default

    I'm guessing a bit, but isn't there a listener that can be attached to the table for when a change is made to the data? That's how Swing stuff usually works.

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    I think that's the most suitable way to do this, load the content to a table and work through the listeners. But my confusion is OP really did that or looking a way to do it.

Similar Threads

  1. Have I understood how the observer pattern works?
    By kiregad in forum New To Java
    Replies: 1
    Last Post: 05-16-2010, 08:41 AM
  2. Problem with observer pattern
    By livnihai in forum New To Java
    Replies: 5
    Last Post: 10-11-2009, 02:34 PM

Posting Permissions

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