-1

I'm in need of a Jframe code that can add and remove item while the frame is not on or in other words there's another frame open that adds the object into it.

I tried using

    int index=box_task.getSelectedIndex();
    box_task.removeItemAt(index);

but every time I return to that specific frame it revert backs to its original form

  • "*...but every time I return to that specific frame it revert backs to its original form*" -- then your code is doing something wrong, code that you are currently *not showing us*, and we can only guess the possible reasons. My current best guess is that you may possibly be changing the state of the wrong reference, of a JFrame that is not displayed, but why force us to guess? Please ask a complete question, one that is answerable. Best to 1) read the [ask] to check out question requirements, and 2) create and post a valid [mre] program. The link will explain. – Hovercraft Full Of Eels Sep 01 '23 at 11:10
  • So, be careful of how many objects you create (how many times you call `new SuchAndSuch()`), since each time you do this, you create a new reference. Also, best to give one class public methods that allow the other class to mutate it (change its state) in a controlled way -- same as for any other collection of OOP-compliant classes. – Hovercraft Full Of Eels Sep 01 '23 at 11:12
  • Also, look into separating your program's model, its data and logic, from its view, so that there exists only *one source of truth*, and so that your code has low coupling and high cohesion. – Hovercraft Full Of Eels Sep 01 '23 at 11:14
  • Please see [my answer to a somewhat similar question](https://stackoverflow.com/a/19461276/) as well as [this answer here](https://stackoverflow.com/a/20454403/) for more suggestions. – Hovercraft Full Of Eels Sep 01 '23 at 11:15
  • And also the obligitory: [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/questions/9554636) – Hovercraft Full Of Eels Sep 01 '23 at 11:39

0 Answers0