Solved

Java Schedule Table

Posted on 2004-04-29
18
548 Views
Last Modified: 2012-08-14
please refer to question

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20968958.html

please the question is urgent and having a calandar similat to the  outlook calandar will be best
0
Comment
Question by:razo
  • 10
  • 8
18 Comments
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
I have made my base idea clear with this little (extended) demo:

Click on a cell, keep the mouse pressed and move to other cells.
Release the mouse and see what the printing says.
With this info you can adapt you time window easily I think.

Focus on the mouseDragged() and mouseReleased() functions.
The new things are marked:  // <<<<<<<<<<<<<<<<<<<<<<


/*
 * TableDemo.java
 *
 */

import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
import java.util.List;
import java.awt.*;
import java.awt.event.*;
/**
 *
 */
public class TableDemo extends javax.swing.JFrame
                       implements MouseListener, MouseMotionListener {             // <<<<<<<<<<<<<<<<<
                           
    private int startRow = -1;                                    // <<<<<<<<<<<<<<<<<<<<<<
    private int startCol = -1;                                     / <<<<<<<<<<<<<<<<<<<<<<
   
    /** Creates new form TableDemo */
    public TableDemo() {
        initComponents();
        initTable();
    }
   
    private void initTable() {
        theTable.setModel(new MyOwnTableModel());
        theTable.setCellSelectionEnabled(true);
        theTable.setDefaultRenderer(String.class, new MyTableCellRenderer());
        theTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        ListSelectionModel rowSM = theTable.getSelectionModel();
        rowSM.addListSelectionListener(new ListSelectionListener() {
                public void valueChanged(ListSelectionEvent e) {
                    //Ignore extra messages.
                    if (e.getValueIsAdjusting()) return;
                    ListSelectionModel lsm = (ListSelectionModel)e.getSource();
                    if (lsm.isSelectionEmpty()) {
                        System.out.println("No rows are selected.");
                    } else {
                        int selectedRowFrom = lsm.getMinSelectionIndex();
                        int selectedRowTo = lsm.getMaxSelectionIndex();
                        if (selectedRowTo==selectedRowFrom)
                            System.out.println("Row " + selectedRowFrom
                                           + " is now selected.");
                        else
                            System.out.println("Rows " + selectedRowFrom
                                               + " to " + selectedRowTo + " are now selected.");
                    }
                }
            });
        ListSelectionModel colSM = theTable.getColumnModel().getSelectionModel();
        colSM.addListSelectionListener(new ListSelectionListener() {
                public void valueChanged(ListSelectionEvent e) {
                    //Ignore extra messages.
                    if (e.getValueIsAdjusting()) return;

                    ListSelectionModel lsm = (ListSelectionModel)e.getSource();
                    if (lsm.isSelectionEmpty()) {
                        System.out.println("No columns are selected.");
                    } else {
                        int selectedColFrom = lsm.getMinSelectionIndex();
                        int selectedColTo = lsm.getMaxSelectionIndex();
                        if (selectedColFrom==selectedColTo)
                            System.out.println("Column " + selectedColFrom
                                               + " is now selected.");
                        else
                            System.out.println("Columns " + selectedColFrom
                                               + " to " + selectedColTo + " are now selected.");
                    }
                }
        });
        theTable.addMouseListener(this);                     // <<<<<<<<<<<<<<<<<<<<<<
        theTable.addMouseMotionListener(this);           // <<<<<<<<<<<<<<<<<<<<<<

    }
   
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {
        jScrollPane1 = new javax.swing.JScrollPane();
        theTable = new javax.swing.JTable();

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });

        theTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(theTable);

        getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);

        pack();
    }
   
    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {
        System.exit(0);
    }
   
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch (Exception e) {
            System.exit(0);
        }
       
        new TableDemo().show();
    }
   
    // Variables declaration - do not modify
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable theTable;
    // End of variables declaration
   
     public class MyOwnTableModel extends DefaultTableModel {
   
        final String[] columnNames = { "Day",
                                       "08:00-08:15", "08:15-08:30",
                                       "08:30-08:45", "08:45-09:00" };
                                       
        List data = new ArrayList();
       
        public MyOwnTableModel() {
            data.add( new MyRowData("Monday", " ", " ", " ", " "));
            data.add( new MyRowData("Tuesday", " ", " ", " ", " "));
            data.add( new MyRowData("Wednesday", " ", " ", " ", " "));
            data.add( new MyRowData("Thursday", " ", " ", " ", " "));
            data.add( new MyRowData("Friday", " ", " ", " ", " "));
            data.add( new MyRowData("Saturday", " ", " ", " ", " "));
            data.add( new MyRowData("Sunday", " ", " ", " ", " "));
        }
        public boolean isCellEditable(int row, int col) { return false; }
        public Class getColumnClass(int col) {
            return super.getColumnClass(col);
        }        
        public int getRowCount() { return data==null ? 0 : data.size(); }
        public int getColumnCount() { return 5; }
        public String getColumnName(int col) {
            return columnNames[col];
        }
        public Object getValueAt(int row, int col) {
            MyRowData rowData = (MyRowData) data.get(row);
            if (col==0)
                return rowData.getDay();
            else
                return rowData.getField(col);
        }
        public void setValueAt(Object value, int row, int col) {
            MyRowData rowData = (MyRowData) data.get(row);
            if (col==0)
                rowData.setDay((String)value);
            else
                rowData.setField(col, (String)value);
        }
        public void remove(int index) {
           
        }
     }
     
     public class MyRowData {
         private String day;
         private String field1;
         private String field2;
         private String field3;
         private String field4;
         
         public MyRowData(String d, String f1, String f2, String f3, String f4) {
             day = d;
             field1 =f1;
             field2 =f2;
             field3 =f3;
             field4 =f4;
         }
         public String getDay() { return day; }
         public void setDay(String d) {
             day=d;
         }
         public String getField(int index) {
             switch(index) {
                 case 1: return field1;
                 case 2: return field2;
                 case 3: return field3;
                 case 4: return field4;
                 default: return " ";
            }
        }
         public void setField(int index, String f) {
             switch(index) {
                 case 1: field1=f; break;
                 case 2: field2=f; break;
                 case 3: field3=f; break;
                 case 4: field4=f; break;
            }
        }
     }
     
    public class MyTableCellRenderer extends JLabel
                                     implements TableCellRenderer {
   
        /** Creates a new instance of BusinessObjectTypeTableCellRenderer */
        public MyTableCellRenderer() {
            setOpaque(true);
        }

        public Component getTableCellRendererComponent(JTable table,
                                                       Object value,
                                                       boolean isSelected,
                                                       boolean hasFocus,
                                                       int row,
                                                       int column)
        {
            if (value!=null)
                setText( value.toString() );
            setBorder( BorderFactory.createMatteBorder(1,1,0,1, Color.BLACK) );
            setBackground(isSelected ?
                          table.getSelectionBackground() : table.getBackground());
            setForeground(isSelected ?
                          table.getSelectionForeground() : table.getForeground());
            return this;
        }
    }

    // MouseListener                                                // <<<<<<<<<<<<<<<<<<<<<< till the end
    public void mouseClicked(MouseEvent e) {
       
    }
    public void mouseEntered(MouseEvent e) {
       
    }
    public void mouseExited(MouseEvent e) {
       
    }
    public void mousePressed(MouseEvent e) {
       
    }
    public void mouseReleased(MouseEvent e) {
        System.out.println("Started dragging at r="+startRow+" c="+startCol);
        int stopCol = theTable.columnAtPoint(e.getPoint());
        int stopRow = theTable.rowAtPoint(e.getPoint());
        System.out.println("Stopped dragging at r="+stopRow+" c="+stopCol);
        // process here
        startCol = -1;
        startRow = -1;
    }
    // MouseMotionListener
    public void mouseDragged(MouseEvent e) {
        if (startCol==-1)
            startCol = theTable.columnAtPoint(e.getPoint());
        if (startRow==-1)
        startRow = theTable.rowAtPoint(e.getPoint());
    }
    public void mouseMoved(MouseEvent e) {
    }
}
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
Apparently you get the selection of the table cells for free when dragging.
Don't know if you want that.
I guess, yes, because it gives the user a visual indication of what he's doing.
0
 
LVL 8

Author Comment

by:razo
Comment Utility
ok that is good for inserting an appointment but the user can't change his mind can he?
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
Sure you can.
You know the (1) cell he started dragging and you know (2) the cell where he stopped dragging.
So you can change the time window of the appointment lying in cell (1) to correspond (extend or decrement) with cell (2).
You can do that "dynamically" (= during dragging) in the mouseMoved() function.
0
 
LVL 8

Author Comment

by:razo
Comment Utility
ok let me check the whole matter throughly if everything ok ill give u the points
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
OK.
I stay stand-by.
0
 
LVL 8

Author Comment

by:razo
Comment Utility
look the new additions dont provide a lot with respect what i could do with multiple selection
i mean i still can't consider selected cells as one cell and i can't even put a label or a text box on these cells whose length is equal to the length of the selected cells.
the way it is even if i select multiple cells if i want to write something it is written in the first selected cell which is what i don't want.
i really need one of these 2 options ...i already put 1000 points on this question...
can u help?

0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
>> even if i select multiple cells if i want to write something it is written in the first selected cell which is what i don't want.
If the text is in the first cell (having another color) and all other cells have that same color,
then isn't that a good indication that the appointment exists for the whole (especially colored) time window?
(I guess repeating the text in all cells isn't an option?)

>> i really need one of these 2 options ...i already put 1000 points on this question...
That's OK.
Let me assure you that it's not the # points that holds me from helping you.
Look at my history and you can see that I also answered 20 or 50 points Q's.
I really *try* to help you.
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
btw.
also Outlook has *only one line* to describe the appointment.
The time window is indicated via colors.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 8

Author Comment

by:razo
Comment Utility
no outlook has a text form that can be extended over the cells. u could still see the cells in the background
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
>> no outlook has a text form that can be extended over the cells
But you can only enter one line of text.
With one line I mean you can't enter newlines (by pressing ctrl-enter as in text areas).

But OK, yes you do have a text form. And that's what you want.
Let's see...
0
 
LVL 8

Author Comment

by:razo
Comment Utility
thanks for understanding
the people i am doing the project for are more intrested in the user interface than the functionality
0
 
LVL 37

Accepted Solution

by:
zzynx earned 500 total points
Comment Utility
Hi razo,

My time is really spended for today, but this may give you an indication on what is possible.
Double click a cell and see what you get.

Of course, the code is one big mess, but that's not important for now.
It's easier to copy/paste for you wihtout worrying about where to place files.

/*
 * TableDemo.java
 *
 */

import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
import java.util.List;
import java.awt.*;
import java.awt.event.*;
/**
 *
 */
public class TableDemo extends javax.swing.JFrame
                       implements MouseListener, MouseMotionListener {
                           
    private int startRow = -1;
    private int startCol = -1;
   
    /** Creates new form TableDemo */
    public TableDemo() {
        initComponents();
        initTable();
    }
   
    private void initTable() {
        theTable.setModel(new MyOwnTableModel());
        theTable.setCellSelectionEnabled(true);
        theTable.setDefaultRenderer(String.class, new MyTableCellRenderer());
       
        theTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        ListSelectionModel rowSM = theTable.getSelectionModel();
        rowSM.addListSelectionListener(new ListSelectionListener() {
                public void valueChanged(ListSelectionEvent e) {
                    //Ignore extra messages.
                    if (e.getValueIsAdjusting()) return;
                    ListSelectionModel lsm = (ListSelectionModel)e.getSource();
                    if (lsm.isSelectionEmpty()) {
                        System.out.println("No rows are selected.");
                    } else {
                        int selectedRowFrom = lsm.getMinSelectionIndex();
                        int selectedRowTo = lsm.getMaxSelectionIndex();
                        if (selectedRowTo==selectedRowFrom)
                            System.out.println("Row " + selectedRowFrom
                                           + " is now selected.");
                        else
                            System.out.println("Rows " + selectedRowFrom
                                               + " to " + selectedRowTo + " are now selected.");
                    }
                }
            });
        ListSelectionModel colSM = theTable.getColumnModel().getSelectionModel();
        colSM.addListSelectionListener(new ListSelectionListener() {
                public void valueChanged(ListSelectionEvent e) {
                    //Ignore extra messages.
                    if (e.getValueIsAdjusting()) return;

                    ListSelectionModel lsm = (ListSelectionModel)e.getSource();
                    if (lsm.isSelectionEmpty()) {
                        System.out.println("No columns are selected.");
                    } else {
                        int selectedColFrom = lsm.getMinSelectionIndex();
                        int selectedColTo = lsm.getMaxSelectionIndex();
                        if (selectedColFrom==selectedColTo)
                            System.out.println("Column " + selectedColFrom
                                               + " is now selected.");
                        else
                            System.out.println("Columns " + selectedColFrom
                                               + " to " + selectedColTo + " are now selected.");
                    }
                }
        });
        theTable.addMouseListener(this);
        theTable.addMouseMotionListener(this);
       
        MyCellEditor ce = new MyCellEditor();
        theTable.getColumnModel().getColumn(1).setCellEditor(ce);
        theTable.getColumnModel().getColumn(2).setCellEditor(ce);
        theTable.getColumnModel().getColumn(3).setCellEditor(ce);
    }
   
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {
        jScrollPane1 = new javax.swing.JScrollPane();
        theTable = new javax.swing.JTable();

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });

        theTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(theTable);

        getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);

        pack();
    }
   
    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {
        System.exit(0);
    }
   
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch (Exception e) {
            System.exit(0);
        }
       
        new TableDemo().show();
    }
   
    // Variables declaration - do not modify
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable theTable;
    // End of variables declaration
   
     public class MyOwnTableModel extends DefaultTableModel {
   
        final String[] columnNames = { "Day",
                                       "08:00-08:15", "08:15-08:30",
                                       "08:30-08:45", "08:45-09:00" };
                                       
        List data = new ArrayList();
       
        public MyOwnTableModel() {
            data.add( new MyRowData("Monday", " ", " ", " ", " "));
            data.add( new MyRowData("Tuesday", " ", " ", " ", " "));
            data.add( new MyRowData("Wednesday", " ", " ", " ", " "));
            data.add( new MyRowData("Thursday", " ", " ", " ", " "));
            data.add( new MyRowData("Friday", " ", " ", " ", " "));
            data.add( new MyRowData("Saturday", " ", " ", " ", " "));
            data.add( new MyRowData("Sunday", " ", " ", " ", " "));
        }
        public boolean isCellEditable(int row, int col) { return true; }
        public Class getColumnClass(int col) {
            return super.getColumnClass(col);
        }        
        public int getRowCount() { return data==null ? 0 : data.size(); }
        public int getColumnCount() { return 5; }
        public String getColumnName(int col) {
            return columnNames[col];
        }
        public Object getValueAt(int row, int col) {
            MyRowData rowData = (MyRowData) data.get(row);
            if (col==0)
                return rowData.getDay();
            else
                return rowData.getField(col);
        }
        public void setValueAt(Object value, int row, int col) {
            MyRowData rowData = (MyRowData) data.get(row);
            if (col==0)
                rowData.setDay((String)value);
            else
                rowData.setField(col, (String)value);
        }
        public void remove(int index) {
           
        }
     }
     
     public class MyRowData {
         private String day;
         private String field1;
         private String field2;
         private String field3;
         private String field4;
         
         public MyRowData(String d, String f1, String f2, String f3, String f4) {
             day = d;
             field1 =f1;
             field2 =f2;
             field3 =f3;
             field4 =f4;
         }
         public String getDay() { return day; }
         public void setDay(String d) {
             day=d;
         }
         public String getField(int index) {
             switch(index) {
                 case 1: return field1;
                 case 2: return field2;
                 case 3: return field3;
                 case 4: return field4;
                 default: return " ";
            }
        }
         public void setField(int index, String f) {
             switch(index) {
                 case 1: field1=f; break;
                 case 2: field2=f; break;
                 case 3: field3=f; break;
                 case 4: field4=f; break;
            }
        }
     }
     
    public class MyTableCellRenderer extends JLabel
                                     implements TableCellRenderer {
   
        /** Creates a new instance of BusinessObjectTypeTableCellRenderer */
        public MyTableCellRenderer() {
            setOpaque(true);
        }

        public Component getTableCellRendererComponent(JTable table,
                                                       Object value,
                                                       boolean isSelected,
                                                       boolean hasFocus,
                                                       int row,
                                                       int column)
        {
            if (value!=null)
                setText( value.toString() );
            setBorder( BorderFactory.createMatteBorder(1,1,0,1, Color.BLACK) );
            setBackground(isSelected ?
                          table.getSelectionBackground() : table.getBackground());
            setForeground(isSelected ?
                          table.getSelectionForeground() : table.getForeground());
            return this;
        }
    }

    // MouseListener
    public void mouseClicked(MouseEvent e) {
       
    }
    public void mouseEntered(MouseEvent e) {
       
    }
    public void mouseExited(MouseEvent e) {
       
    }
    public void mousePressed(MouseEvent e) {
       
    }
    public void mouseReleased(MouseEvent e) {
        System.out.println("Started dragging at r="+startRow+" c="+startCol);
        int stopCol = theTable.columnAtPoint(e.getPoint());
        int stopRow = theTable.rowAtPoint(e.getPoint());
        System.out.println("Stopped dragging at r="+stopRow+" c="+stopCol);
        // process here
        startCol = -1;
        startRow = -1;
    }
    // MouseMotionListener
    public void mouseDragged(MouseEvent e) {
        if (startCol==-1)
            startCol = theTable.columnAtPoint(e.getPoint());
        if (startRow==-1)
        startRow = theTable.rowAtPoint(e.getPoint());
    }
    public void mouseMoved(MouseEvent e) {
    }
   
    class MyCellEditor extends DefaultCellEditor
                       implements ActionListener {
       
        private JButton theButton;
        private JComponent component;
       
        private class LocalEscDialog extends EscDialog {
            private boolean bEscPressed = false;
            public LocalEscDialog(Frame frame, boolean modal) {
                super(frame, modal);
            }
            public void keyPressed(KeyEvent e)
            {
                if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                    bEscPressed = true;
                    setVisible(false);
                }
                else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                    setVisible(false); // pressing Enter is like pressing 'Set'
                }
            }
            public boolean isEscapePressed() {
                return bEscPressed;
            }
            public void setEscapePressed(boolean value) {
                bEscPressed = value;
            }
        };
       
        private class MyActionListener implements ActionListener {
            LocalEscDialog dlg = null;
            public MyActionListener(LocalEscDialog dlg) {
                this.dlg = dlg;
            }
            public void actionPerformed(ActionEvent e) {
                dlg.setVisible(false);
            }
        };
       
        public MyCellEditor() {
            super(new JTextField());
           
            // -----------------------------
            // Here's what you want to see when editing
            // -----------------------------
            component = new JPanel();
            component.setLayout(new BorderLayout());
            JTextField textField = new JTextField();
            component.add(textField);
            component.setBorder(BorderFactory.createLineBorder(Color.BLACK, 4));
            component.setPreferredSize(new Dimension(100,20));
           
            setClickCountToStart(2);
           
            theButton = new JButton();
            theButton.addActionListener(this);
        }

        public Component getTableCellEditorComponent(JTable table, Object value,
                                                     boolean isSelected,
                                                     int row, int column) {
           return theButton;
        }
       
        public void actionPerformed(ActionEvent e) {
            LocalEscDialog dialog = new LocalEscDialog(JOptionPane.getFrameForComponent(theButton), true);
            MyActionListener listener = new MyActionListener(dialog);
            dialog.setUndecorated(true);
            dialog.setContentPane(component);
            dialog.pack();
            dialog.setLocationRelativeTo(theButton);
            dialog.show();
            if ( dialog.isEscapePressed() )
                fireEditingCanceled();
            else
                fireEditingStopped();
        }
    }
}
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
I forgot one other file.

/*
 * EscDialog.java
 *
 */

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
/**
 * a JDialog that appears when ESC is pressed
 */
public class EscDialog extends JDialog implements ContainerListener, KeyListener {
   
    public EscDialog(Frame frame, boolean modal)
    {
        super(frame, modal);
        addListenersRecursively(this);
    }

    //The following function is recursive and is intended for internal use only.
    //It is private to prevent anyone calling it from other classes
    //The function takes a Component as an argument and adds this JDialog
    //as a KeyListener to it.
    //Besides it checks if the component is actually a Container and if it is,
    //there  are 2 additional things to be done to this Container :
    // 1 - add this Dialog as a ContainerListener to the Container
    // 2 - call this function recursively for every child of the Container.

    private void addListenersRecursively(Component c)
    {
        //To be on the safe side, try to remove KeyListener first
        //just in case it has been added before.
        //If not, it won't do any harm
        c.removeKeyListener(this);
        //Add KeyListener to the Component passed as an argument
        c.addKeyListener(this);

        if (c instanceof Container) {
            //Component c is a Container. The following cast is safe.
            Container cont = (Container)c;
            //To be on the safe side, try to remove ContainerListener first
            //just in case it has been added before.
            //If not, it won't do any harm
            cont.removeContainerListener(this);
            //Add ContainerListener to the Container.
            cont.addContainerListener(this);

            //Get the Container's array of children Components.
            Component[] children = cont.getComponents();

            //For every child repeat the above operation.
            for (int i = 0; i < children.length; i++) {
                addListenersRecursively(children[i]);
            }
        }
    }

    //The following function is the same as the function above with the exception that it does exactly the opposite - removes this Dialog
    //from the listener lists of Components.
    private void removeListenersRecursively(Component c)
    {
        c.removeKeyListener(this);
        if (c instanceof Container) {
            Container cont = (Container)c;
            cont.removeContainerListener(this);
            Component[] children = cont.getComponents();
            for (int i = 0; i < children.length; i++) {
                removeListenersRecursively(children[i]);
            }
        }
    }

    //ContainerListener interface
    //---------------------------------------------------------

    //This function is called whenever a Component or a Container is added
    //to another Container belonging to this Dialog
    public void componentAdded(ContainerEvent e) {
        addListenersRecursively(e.getChild());
    }

    //This function is called whenever a Component or a Container is removed from another Container belonging to this Dialog
    public void componentRemoved(ContainerEvent e) {
        removeListenersRecursively(e.getChild());
    }

    //KeyListener interface
    //---------------------------------------------------------

    //This function is called whenever a Component belonging to this Dialog
    //(or the Dialog itself) gets the KEY_PRESSED event
    public void keyPressed(KeyEvent e)
    {
        if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
            //Key pressed is the ESCAPE key.
            performEscapeAction(e);
        }
    }
    //We need the following 2 functions to complete imlementation of KeyListener
    public void keyReleased(KeyEvent e) {
    }

    public void keyTyped(KeyEvent e) {
    }
    //Default response to ESCAPE key pressed goes here
    //Redefine this function in subclasses to respond to ENTER key
    //differently
    public void performEscapeAction(KeyEvent evt) {
        setVisible(false);
    }
}
0
 
LVL 8

Author Comment

by:razo
Comment Utility
thanks for helping
i meant a textbox on the cell
anyways i did some work myself and completed it
0
 
LVL 8

Author Comment

by:razo
Comment Utility
can i ask u a new question about this program
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
Sure, but not in this closed one.
Post another question (and possibly refer to this one).
0
 
LVL 8

Author Comment

by:razo
Comment Utility
ya sure
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

772 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

14 Experts available now in Live!

Get 1:1 Help Now