Solved

Adding a JList with 2 features remove/replace

Posted on 2004-05-02
50
503 Views
Last Modified: 2010-03-31
Hello everyone out there I hope someone wants to help me with this question.

Below is the code of one class I'm using with buttons and the button color change code as well. Another class for Listening and creating lists.

MyListener creates a list out of actionCommands and a ListModel the names of the buttons to go into a JList. The outline is this. A user presses a button it changes color to indicate it was pressed,  MyListener records that action into a list as an actionCommand. What I need and want is to have the JList list the name of the button as well. There are 2 features needed to be available. The user can delete an item from the JList and it is removed from both lists. or can replace an item in the list by highlighting it and pressing another button and it is replaced in both lists.

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Kempos extends JPanel implements ActionListener
{
     JCheckBox check;
     JLabel label;
     JPanel gridPanel;
     ArrayList kemposArrayList;
     ArrayList arrayList;
     public Kempos()
     {
          kemposArrayList = new ArrayList();
          label = new JLabel();
          //Call it like this . . .
          gridPanel = new JPanel();
          gridPanel.setLayout(new GridLayout(0, 3));
          // Setting MY layout...
          setLayout(new BorderLayout());
          add(label, BorderLayout.NORTH);
          add(gridPanel, BorderLayout.CENTER);
          label.setText("              Kempos");
          label.setForeground(Color.red);
          setBackground(Color.white);
          looprow : for (int row = 0; row < 20; row++)
          {
               for (int col = 0; col < 3; col++)
               {
                    int n = (20 * col + row + 1);
                    if (n > 50)
                    {
                         break looprow;
                    }
                    JButton onOffButton = new JColoredButton("" + n, Color.green, Color.black);
                    onOffButton.addActionListener(this);
                    onOffButton.setActionCommand("kp" + n + ".wav");
                    gridPanel.add(onOffButton);
               }
          }
     }

     public static void main(String[] args)
     {
          JFrame frame = new JFrame();
          frame.getContentPane().add(new Kempos());
          frame.setSize(400, 400);
          frame.setVisible(true);

          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     }

     public void actionPerformed(ActionEvent e)
{
                               
          JColoredButton button = (JColoredButton)e.getSource();
         
          int index = kemposArrayList.indexOf(button) ;

          if (index > -1)
          {
               kemposArrayList.remove(index); // removal of button
               kemposArrayList.remove(index); // removal of timing.wav

               button.setDefaultColor();
          }
          else
          {
               kemposArrayList.add(button);
               kemposArrayList.add("timing.wav");
 
               button.setPressedColor();
          }
         
          System.out.println(kemposArrayList);
}  

}

class JColoredButton extends JButton
{
     private Color foreground;
     private Color deafultForeground;
     private Color background;
     private Color defaultBackground;

     public JColoredButton(String label, Color background, Color foreground)
     {
          super(label);
          this.background = background;
          this.foreground = foreground;
          defaultBackground = getBackground();
          deafultForeground = getForeground();
     }
     
     public void setPressedColor()
     {
          setBackground(background);
          setForeground(foreground);
     }
     
     public void setDefaultColor()
     {
          setBackground(defaultBackground);
          setForeground(deafultForeground);
     }
}          





public class MyListener implements ActionListener {

    private List theList = new ArrayList();
    private DefaultListModel theList = new DefaultListModel();

    public MyListener() {
     }

    public void addButton(JButton theButtonToAdd) {
       theButtonToAdd.addActionListener(this);  // Listen for the button to be pressed
    }

    public void actionPerformed(ActionEvent e) {
       JButton button = (JButton)e.getSource();
       String command = button.getActionCommand();
       if (thList.contains(command))
       {
          theList.remove(command);
          nameList.remove(button.getText());
       }
       else
       {
          theList.add(command);
          nameList.add(button.getText());
       }
    }

    public List getList() { return theList; }
    public getNameList() { return nameList; }
}
0
Comment
Question by:Drop_of_Rain
  • 20
  • 19
  • 11
50 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 10975255
In MyListener you have twice the variable "theList".
0
 

Author Comment

by:Drop_of_Rain
ID: 10975263
One should be nameList Right, just change it
0
 
LVL 92

Expert Comment

by:objects
ID: 10975469
when should the buttons change colour?
0
 

Author Comment

by:Drop_of_Rain
ID: 10975494
Well that doesn't have to happen lets talk about it. It is just so the user sees the button got pressed that all. What would use suggest?
0
 
LVL 92

Expert Comment

by:objects
ID: 10975501
so you want it in a different colour if the corresponding audio has been added one or more times to the list
0
 

Author Comment

by:Drop_of_Rain
ID: 10975529
Lets keep it simple, do you think if the button just did its normal movement and made a sound would be ok what do you think
0
 
LVL 92

Expert Comment

by:objects
ID: 10975645
ok a plain JButton it is :)
0
 
LVL 92

Accepted Solution

by:
objects earned 400 total points
ID: 10975714
this should get you started:

public class ListManager
{
    private DefaultListModel theList = new DefaultListModel();

    public ListManager()
    {
    }

    public ListModel getList() { return theList; }

    public void add(String item)
    {
          theList.add(item);
    }
   
    public void remove(int index)
    {
          theList.remove(index);
    }
   
    public void  set(int index, Object item)
    {
       theList.set(index, item);
    }
 
}
0
 
LVL 92

Expert Comment

by:objects
ID: 10975761
The action listeners for your buttons would then call the appropriate method as required.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10975781
So, the same button can be pressed more than once,
and then you want the action command/button name be added more than once too?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10975789
How will they delete items from the list?
By
1) selecting an item
followed by
2) pressing a <Delete> button?
0
 
LVL 92

Assisted Solution

by:objects
objects earned 400 total points
ID: 10975860
to add to the list when a button was pressed you'd use:

manager.add(button.getActionCommand());

to delete selected item from list you would use:

manager.remove(list.getSelectedIndex());

to replace the selected item in list you would use:

manager.set(list.getSelectedIndex(), button.getActionCommand());
0
 

Author Comment

by:Drop_of_Rain
ID: 10975882
Comment from zzynx

So, the same button can be pressed more than once,
and then you want the action command/button name be added more than once too?

Yes they work in tandom
0
 

Author Comment

by:Drop_of_Rain
ID: 10975950
Here is a template of a JList could this be modified to work with manager, I'm not sure about the buttons and


import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;

public class TrainerMonitor extends JPanel
    implements ActionListener{
 JButton jb1, jb2, jb3;
 JList list;
 

 public TrainerMonitor(){
   
   setLayout(new BorderLayout());
   list = new JList();
   list.setModel(new DefaultListModel());
   add(new JScrollPane(list),"Center");
   add(jb1 = new JButton("Add"), "South");
   add(jb2 = new JButton("Replace"), "South");
   add(jb3 = new JButton("Remove"), "South");
   jb1.addActionListener(this);
   jb2.addActionListener(this);
   jb3.addActionListener(this);

       
 public void actionPerformed(ActionEvent ae) {
  if (ae.getSource() == jb1  {         // add
          manager.add(button.getActionCommand());
     }
   else (ae.getSource() == jb2  {         // add
   manager.set(list.getSelectedIndex(), button.getActionCommand());   // replace
    }
  else { (ae.getSource() == jb3          // remove
    manager.remove(list.getSelectedIndex());
    }
 
  }
 
 
 public static void main(String s[]) {
   JFrame frame = new JFrame("PopUp JList");
   frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
   frame.getContentPane().add(panel,"Center");

   frame.setSize(250,500);
   frame.setVisible(true);
    }
}
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10975986
public TrainerMonitor(){
   
   setLayout(new BorderLayout());
   list = new JList();
   ListManager lm = new ListManager();             // <<<<<<<<<<<<<
   list.setModel(lm.getList());                             // <<<<<<<<<<<<<
   add(new JScrollPane(list),"Center");
   add(jb1 = new JButton("Add"), "South");
   add(jb2 = new JButton("Replace"), "South");
   add(jb3 = new JButton("Remove"), "South");
   jb1.addActionListener(this);
   jb2.addActionListener(this);
   jb3.addActionListener(this);
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10976001
Of course in this example "button" is unknown...
0
 
LVL 92

Expert Comment

by:objects
ID: 10976014
you'd need to have seperate buttons for each different audio.
0
 

Author Comment

by:Drop_of_Rain
ID: 10976022
My syntex is wrong somewhere


import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;

public class TrainerMonitor extends JPanel
    implements ActionListener{
 JButton jb1, jb2, jb3;
 JList list;
 

 public TrainerMonitor(){
   
   setLayout(new BorderLayout());
   list = new JList();
   ListManager lm = new ListManager();             // <<<<<<<<<<<<<
   list.setModel(lm.getList());                             // <<<<<<<<<<<<<
   add(new JScrollPane(list),"Center");
   add(jb1 = new JButton("Add"), "South");
   add(jb2 = new JButton("Replace"), "South");
   add(jb3 = new JButton("Remove"), "South");
   jb1.addActionListener(this);
   jb2.addActionListener(this);
   jb3.addActionListener(this);


       
 public void actionPerformed(ActionEvent ae)
 {
  if (ae.getSource() == jb1  {         // add
          manager.add(button.getActionCommand());
     }
   else (ae.getSource() == jb2  {        
       manager.set(list.getSelectedIndex(), button.getActionCommand());   // replace
    }
  else { (ae.getSource() == jb3          // remove
    manager.remove(list.getSelectedIndex());
    }
 
  }
 
 
 public static void main(String s[]) {
   JFrame frame = new JFrame("PopUp JList");
   frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
   frame.getContentPane().add(panel,"Center");

   frame.setSize(250,500);
   frame.setVisible(true);
    }
}
0
 

Author Comment

by:Drop_of_Rain
ID: 10976034
Comment from objects

you'd need to have seperate buttons for each different audio.


What do you mean by different buttons for each different audio
 
0
 
LVL 92

Expert Comment

by:objects
ID: 10976041
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;

public class TrainerMonitor extends JPanel
    implements ActionListener{
 JButton jb1, jb2, jb3;
   private ListManager manager = new ListManager();
   private JList list = new JList(manager);
 

 public TrainerMonitor(){
   
   setLayout(new BorderLayout());
   add(new JScrollPane(list),"Center");
   add(jb1 = new JButton("Add"), "South");
   add(jb2 = new JButton("Replace"), "West");
   add(jb3 = new JButton("Remove"), "East");
   jb1.addActionListener(this);
   jb2.addActionListener(this);
   jb3.addActionListener(this);
   }

       
 public void actionPerformed(ActionEvent ae)
 {
  if (ae.getSource() == jb1)  {         // add
          manager.add(jb1.getActionCommand());
     }
   else if (ae.getSource() == jb2)  {        
       manager.set(list.getSelectedIndex(), jb2.getActionCommand());   // replace
    }
  else if  (ae.getSource() == jb3) {          // remove
    manager.remove(list.getSelectedIndex());
    }
 
  }
 
 
 public static void main(String s[]) {
   JFrame frame = new JFrame("PopUp JList");
   frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
   frame.getContentPane().add(panel,"Center");

   frame.setSize(250,500);
   frame.setVisible(true);
    }
}
0
 
LVL 92

Expert Comment

by:objects
ID: 10976044
> What do you mean by different buttons for each different audio

I mean for each audio file that the user could add to the list there would need to be a seperate button.
Otherwise how do you know what audio to add.
0
 

Author Comment

by:Drop_of_Rain
ID: 10976051
Here is all the different buttons with different audios

This will have to be modified as well.


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Kempos extends JPanel implements ActionListener
{
     JCheckBox check;
     JLabel label;
     JPanel gridPanel;
     ArrayList kemposArrayList;
     ArrayList arrayList;
     public Kempos()
     {
          kemposArrayList = new ArrayList();
          label = new JLabel();
          //Call it like this . . .
          gridPanel = new JPanel();
          gridPanel.setLayout(new GridLayout(0, 3));
          // Setting MY layout...
          setLayout(new BorderLayout());
          add(label, BorderLayout.NORTH);
          add(gridPanel, BorderLayout.CENTER);
          label.setText("              Kempos");
          label.setForeground(Color.red);
          setBackground(Color.white);
          looprow : for (int row = 0; row < 20; row++)
          {
               for (int col = 0; col < 3; col++)
               {
                    int n = (20 * col + row + 1);
                    if (n > 50)
                    {
                         break looprow;
                    }
                    JButton onOffButton = new JColoredButton("" + n, Color.green, Color.black);
                    onOffButton.addActionListener(this);
                    onOffButton.setActionCommand("kp" + n + ".wav");
                    gridPanel.add(onOffButton);
               }
          }
     }

     public static void main(String[] args)
     {
          JFrame frame = new JFrame();
          frame.getContentPane().add(new Kempos());
          frame.setSize(400, 400);
          frame.setVisible(true);

          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     }

     public void actionPerformed(ActionEvent e)
{
                               
          JColoredButton button = (JColoredButton)e.getSource();
         
          int index = kemposArrayList.indexOf(button) ;

          if (index > -1)
          {
               kemposArrayList.remove(index); // removal of button
               kemposArrayList.remove(index); // removal of timing.wav

               button.setDefaultColor();
          }
          else
          {
               kemposArrayList.add(button);
               kemposArrayList.add("timing.wav");
 
               button.setPressedColor();
          }
         
         }  

}

}          
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10976060
I don't agree.

1) For adding you just press the button in combination with no selection in the list (don't need jb1)
2) For replacing you press the button in combination with a selection in the list (don't need jb2)
3) For removing you press indeed jb3. (but there you don't have the "button" variable)

for 1) & 2) the "button" variable is the button pressed.
0
 

Author Comment

by:Drop_of_Rain
ID: 10976088
I'm missing a class to import

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;
import java.lang.object.*;

public class ListManager
{
    private DefaultListModel theList = new DefaultListModel();

    public ListManager()
    {
    }

    public ListModel getList() { return theList; }

    public void add(String item)
    {
         theList.add(item);
    }
   
    public void remove(int index)
    {
         theList.remove(index);
    }
   
    public void  set(int index, Object item)
    {
       theList.set(index, item);
    }
 
}
0
 
LVL 37

Assisted Solution

by:zzynx
zzynx earned 100 total points
ID: 10976096
Do you have your list (showing the pressed button names) "available" (I mean accessible) in Kempos?

If you have, you can in Kempos.actionPerformed()

if (list.getSelectedIndex==-1) // nothing selected in the list, so just add:
      manager.add(button.getActionCommand());                                       // with manager an instance of ListManager
else
      manager.set(list.getSelectedIndex(), button.getActionCommand());      // idem


But, I must say that in your code I miss the link between Kempos and the panel showing the list of pressed button(name)s.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 92

Expert Comment

by:objects
ID: 10976103
What buttons are used is somewhat irrelevant as already alluded to.
The code posted is simply an example of how things would work and the buttons (posted by chris) are not suitable as already mentioned.
There would not probably be even be an add or a replace button.
0
 

Author Comment

by:Drop_of_Rain
ID: 10976105
<<<<I mean for each audio file that the user could add to the list there would need to be a seperate button.
Otherwise how do you know what audio to add.>>>>

I though that the user would be able to press any button in the advanced custom section to replace it with
0
 
LVL 92

Expert Comment

by:objects
ID: 10976111
>       manager.add(button.getActionCommand());                                       // with manager an instance of ListManager
>      manager.set(list.getSelectedIndex(), button.getActionCommand());      // idem

which is what I posted earlier :)

0
 
LVL 92

Expert Comment

by:objects
ID: 10976117
> I though that the user would be able to press any button in the advanced custom section to replace it with

Thats right, you wouldn't have a single add button, you would have indiviual buttons for each audio file.
0
 

Author Comment

by:Drop_of_Rain
ID: 10976123
That is the way I wanted it to work

1) For adding you just press the button in combination with no selection in the list (don't need jb1)
2) For replacing you press the button in combination with a selection in the list (don't need jb2)
3) For removing you press indeed jb3. (but there you don't have the "button" variable)
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10976158
>> which is what I posted earlier :)
Agree on that. (I just wanted to make clear not to use them with jb1 & jb2 but with the "real" buttons)

>> That is the way I wanted it to work
Indeed. Still questions left?
0
 

Author Comment

by:Drop_of_Rain
ID: 10976159
<<<<But, I must say that in your code I miss the link between Kempos and the panel showing the list of pressed button(name)s.>>>>

That was being taken care of in MyListeners, I just haven't added it in the code yet. What you are looks at is a class for developing predefined workouts. This as to be worked out for this new section including the JList.

public class MyListener implements ActionListener {

    private List theList = new ArrayList();
    private DefaultListModel nameList = new DefaultListModel();

    public MyListener() {
     }

    public void addButton(JButton theButtonToAdd) {
       theButtonToAdd.addActionListener(this);  // Listen for the button to be pressed
    }

    public void actionPerformed(ActionEvent e) {
       JButton button = (JButton)e.getSource();
       String command = button.getActionCommand();
       
       if (theList.contains(command))
       {
          theList.remove(command);
          nameList.remove(button.getText());
       }
       else
       {
          theList.add(command);
          nameList.add(button.getText());
       }
    }

    public List getList() { return theList; }
    public ListModel getNameList() { return nameList; }
}

0
 
LVL 92

Expert Comment

by:objects
ID: 10976165
The ListManager class will allow you to achieve all that, you just need to 'wire' it up to your GUI to make the appropriate call.
eg. when the user clicks one of your audio buttons you would add or replace item in list.
0
 

Author Comment

by:Drop_of_Rain
ID: 10976264
Is this OK what class am I missing for ListManager  Code Below

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;

public class TrainerMonitor extends JPanel
    implements ActionListener{
 JButton jb1;
 JList list;
 

 public TrainerMonitor(){
   
   setLayout(new BorderLayout());
   list = new JList();
   ListManager lm = new ListManager();             // <<<<<<<<<<<<<
   list.setModel(lm.getList());                             // <<<<<<<<<<<<<
   add(new JScrollPane(list),"Center");
   add(jb1 = new JButton("Remove"), "South");
   jb1.addActionListener(this);
         
 public void actionPerformed(ActionEvent ae)
 {
  if (ae.getSource() == jb1  {         // add
      manager.remove(list.getSelectedIndex());
   }
 
 }
 
 
 public static void main(String s[]) {
   JFrame frame = new JFrame("Training Item Monitor");
   frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
   frame.getContentPane().add(panel,"Center");

   frame.setSize(250,500);
   frame.setVisible(true);
    }
}

What class am I missing for DefaultListModel


import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;
import java.lang.object.*;

public class ListManager
{
    private DefaultListModel theList = new DefaultListModel();

    public ListManager()
    {
    }

    public ListModel getList() { return theList; }

    public void add(String item)
    {
         theList.add(item);
    }
   
    public void remove(int index)
    {
         theList.remove(index);
    }
   
    public void  set(int index, Object item)
    {
       theList.set(index, item);
    }
 
}
0
 

Author Comment

by:Drop_of_Rain
ID: 10976272
Thanks for all the support and knowledge you guys are great.
0
 
LVL 92

Expert Comment

by:objects
ID: 10976312
> import java.lang.object.*;

get rid of that
0
 
LVL 92

Expert Comment

by:objects
ID: 10976317
also see the code i posted earlier
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10976397
>> Is this OK what class am I missing for ListManager

Well, you just have to include the code of objects.

>>What class am I missing for DefaultListModel?
None.
               import javax.swing.*;
is OK.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10976400
ListManager is the name of his class
0
 

Author Comment

by:Drop_of_Rain
ID: 10980047
theList.add(item);  At this line this message come up, that is why I asked the question!

add(int.java.lang.Object) in javax.swing.DefaultListModel cannot be applied(java.lang.string)


import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;


public class ListManager
{
    private DefaultListModel theList = new DefaultListModel();

    public ListManager()
    {
    }

    public ListModel getList() { return theList; }

    public void add(String item)
    {
         theList.add(item);
    }
   
    public void remove(int index)
    {
         theList.remove(index);
    }
   
    public void  set(int index, Object item)
    {
       theList.set(index, item);
    }
 
}
0
 
LVL 92

Expert Comment

by:objects
ID: 10982008
by bad, replace it with:

       theList.addElement(item);
0
 

Author Comment

by:Drop_of_Rain
ID: 10982777
I need some more help!!!!!!

What have I done wrog here. I ger an error can't resolve variable manager


import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;

public class TrainerMonitor extends JPanel
    implements ActionListener{
 JButton jb1;
 JList list;
 

 public TrainerMonitor(){
   
   setLayout(new BorderLayout());
   list = new JList();
   ListManager manager = new ListManager();             // <<<<<<<<<<<<<
   list.setModel(manager.getList());                             // <<<<<<<<<<<<<
   add(new JScrollPane(list),"Center");
   add(jb1 = new JButton("Remove"), "South");
   jb1.addActionListener(this);
}        
 public void actionPerformed(ActionEvent ae)
 {
  if (ae.getSource() == jb1)  {         // Delete
      manager.remove(list.getSelectedIndex());

   }
 
 }
 
 
 public static void main(String s[]) {
   JFrame frame = new JFrame("Training Item Monitor");
   frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
   frame.getContentPane().add(panel,"Center");

   frame.setSize(250,500);
   frame.setVisible(true);
    }
}
0
 
LVL 92

Expert Comment

by:objects
ID: 10982796
see the code i posted earlier.
0
 
LVL 92

Expert Comment

by:objects
ID: 10982802
public class TrainerMonitor extends JPanel
    implements ActionListener{
   private ListManager manager = new ListManager();
   private JList list = new JList(manager.getList());
   ...
0
 

Author Comment

by:Drop_of_Rain
ID: 10982845
Get an error cannot resolve panel  

frame.getContentPane().add(panel,"Center");
0
 

Author Comment

by:Drop_of_Rain
ID: 10982857
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;

public class TrainerMonitor extends JPanel implements ActionListener{
   private ListManager manager = new ListManager();
   private JList list = new JList(manager.getList());
  JButton jb1, jb2, jb3;
   

 public TrainerMonitor(){
   
   setLayout(new BorderLayout());
   add(new JScrollPane(list),"Center");
   add(jb1 = new JButton("Add"), "South");
   add(jb2 = new JButton("Replace"), "West");
   add(jb3 = new JButton("Remove"), "East");
   jb1.addActionListener(this);
   jb2.addActionListener(this);
   jb3.addActionListener(this);
   }

       
 public void actionPerformed(ActionEvent ae)
 {
  if (ae.getSource() == jb1)  {         // add
          manager.add(jb1.getActionCommand());
     }
   else if (ae.getSource() == jb2)  {        
       manager.set(list.getSelectedIndex(), jb2.getActionCommand());   // replace
    }
  else if  (ae.getSource() == jb3) {          // remove
    manager.remove(list.getSelectedIndex());
    }
 
  }
 
 
 public static void main(String s[]) {
   JFrame frame = new JFrame("PopUp JList");
   frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
   frame.getContentPane().add(panel,"Center");

   frame.setSize(250,500);
   frame.setVisible(true);
    }
}
0
 
LVL 92

Expert Comment

by:objects
ID: 10982900
>   frame.getContentPane().add(panel,"Center");

that should be:

frame.getContentPane().add(new TrainerMonitor(),"Center");
0
 

Author Comment

by:Drop_of_Rain
ID: 10983098
Thanks you guys for all the support, it's great to have your help.
Christopher
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10984015
You're welcome
Thanks for accepting
0
 

Author Comment

by:Drop_of_Rain
ID: 10984030
I have some more questions up if you want to help
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How Complex Is This Java Course ? 9 63
allStar challenge 1 41
groovy example issue 10 66
Java and GPO 11 47
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now