Solved

Create a schedule

Posted on 2004-04-27
28
906 Views
Last Modified: 2008-02-01
i need to create a schedule  of appointments using java
the rows heading of the table signify the day while the columns heading are used for time
the user can also have the option of merging multiple rows for a given day to create an appointment that extend for multiple hours

i need this urgently
0
Comment
Question by:razo
  • 14
  • 12
  • +1
28 Comments
 
LVL 35

Expert Comment

by:TimYates
Comment Utility
you want us to write the whole thing?

We can't do your homework for you...

Do you have a specific problem?
0
 
LVL 8

Author Comment

by:razo
Comment Utility
first it is not a homework
second i only need an outline like to use for the schedule; does JTable works for that?
 and how i can i merge cells
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
>> does JTable works for that?
Yeah, why not.

>> how i can i merge cells
You can't. But why should you?
You can change the background color to indicate an appointment that extends for multiple hours.
0
 
LVL 4

Expert Comment

by:Oliver_Dornauf
Comment Utility
Hello zzny, the java JTable has only a basic functinality. There are several other grid controls (see www.dundas.com or http://www.quest.com/jclass/index.asp) wich provide an enhance functionality. (Sorry they are not free)
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
>> Hello zzny
Are you talking to me?

>>the java JTable has only a basic functinality
Which is enough for what the user asks.
Look to Outlook's Calender: No merging of cells when indicating appointements of more than one hour.
0
 
LVL 8

Author Comment

by:razo
Comment Utility
i examined JTable yesterday and i couldn't find a way to put row headings
as for merging cells it is not necessary to merge but i want to give the user to be able to add an appointments thru the grid to extend for multiple hours...it is not only for view
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
>> i want to give the user to be able to add an appointments thru the grid to extend for multiple hours
That can be done by selecting multiple cells (for one row/day)

>>i examined JTable yesterday and i couldn't find a way to put row headings
Did you put your table in a JScrollPane?
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
>> That can be done by selecting multiple cells.
Play around with this *very simple* example. Hopefully it gives you ideas.

/*
 * TableDemo.java
 *
 */

import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
/**
 *
 */
public class TableDemo extends javax.swing.JFrame {

    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable theTable;
   
    /** Creates new form TableDemo */
    public TableDemo() {
        initComponents();
        initTable();
    }
   
    private void initTable() {
        theTable.setModel(new MyOwnTableModel());
        theTable.setCellSelectionEnabled(true);
    }
   
    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);
            }
        });

        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);
    }
   
    public static void main(String args[]) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch (Exception e) {
            System.exit(0);
        }
       
        new TableDemo().show();
    }
   
    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" };
                                       
        private Object data[][] = {
                {"Monday", " ", " ", " ", " "},
                {"Tuesday", " ", " ", " ", " "},
                {"Wednesday", " ", " ", " ", " "},
                {"Thursday", " ", " ", " ", " "},
                {"Friday", " ", " ", " ", " "},
                {"Saturday", " ", " ", " ", " "},
                {"Sunday", " ", " ", " ", " "},
        };
       
        public MyOwnTableModel() {
        }
        public boolean isCellEditable(int row, int col) { return false; }
        public Class getColumnClass(int col) {
            return super.getColumnClass(col);
        }        
        public int getRowCount() { return 7; }
        public int getColumnCount() { return 5; }
        public String getColumnName(int col) {
            return columnNames[col];
        }
        public Object getValueAt(int row, int col) {
            return data[row][col];
        }
     }
}
0
 
LVL 8

Author Comment

by:razo
Comment Utility
ok that is exactly what i need but please i dont have time to research mutiple selection
please can u explain how can i do multiple selection and how can i allow the user to do that at run-time when adding data
thanks
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
Replace initTable() by this extended version.
And see the tracing when selecting multiple rows/columns.


    private void initTable() {
        theTable.setModel(new MyOwnTableModel());
        theTable.setCellSelectionEnabled(true);
        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.");
                    }
                }
        });
    }
0
 
LVL 8

Author Comment

by:razo
Comment Utility
it is givin a syntax error on ListSelectionListener
do i have to import anything other what i imported at the beginning?
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
Sorry. Add:

     import javax.swing.event.*;
0
 
LVL 8

Author Comment

by:razo
Comment Utility
ok one last thing there is a bug when i edit a cell i am not being able to select another cell
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
So, you mean:
When editing one cell, you're not able to select another cell.
What happens? Do you get an error?
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 37

Accepted Solution

by:
zzynx earned 500 total points
Comment Utility
At least that's no problem with the demo app I gave you.

Change in MyOwnTableModel:
 
         public boolean isCellEditable(int row, int col) { return false; }
into
         public boolean isCellEditable(int row, int col) { return true; }

and add a function:

        public void setValueAt(Object value, int row, int col) {
            data[row][col] = value;
        }

Then you will be able to edit cells
0
 
LVL 8

Author Comment

by:razo
Comment Utility
ok thanks look ill give u 100 more points if u could get me a way that when selecting 2 rows of the same column the lines between the two rows is removed
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
First of all, thanks for accepting. That keeps us answering your future questions too.

About your extra Q:
Do you mean this:
you select row 4 and row 7 (of say column 3),
then - I suppose - you press a button <delete>
then you want row 5 and 6 to be removed?
Is it something like that?
0
 
LVL 8

Author Comment

by:razo
Comment Utility
hi
just wanted if u can do it or not???
i appreciate ur answer either way
thanks
0
 
LVL 8

Author Comment

by:razo
Comment Utility
no what i mean if the user selects rows 3 to 7 of a certain colum and he adds an appointment
then he sees the three columns having the same background color but with out having the dividing lines between them, the small line that distinguish a row from another row in the same column
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
Mmmm.
I know the JTable functions:

 void setShowGrid(boolean showGrid)
          Sets whether the table draws grid lines around cells.
 void setShowHorizontalLines(boolean showHorizontalLines)
          Sets whether the table draws horizontal lines between cells.
 void setShowVerticalLines(boolean showVerticalLines)
          Sets whether the table draws vertical lines between cells.

but that's for the whole table, not for individual cells.
In coding everything is possible ;°)
So, there must be some way...
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
... but I can't find one. :(
Sorry.
0
 
LVL 8

Author Comment

by:razo
Comment Utility
thanks for trying
look can u try to put in an editable cell a textbox that holds the data and whose height could be changed???
something like outlook calander
i really would appreciate it and dont worry about points if it hard and doable i can put more than 100 points
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
Don't know if I understand...

>> a textbox that holds the data and whose height could be changed
Of no use. The cell height won't change because of containing a higher object.

If you want to change the height of a table row you can use JTable's setRowHeight() function:

public void setRowHeight(int row, int rowHeight)

Sets the height for row to rowHeight, revalidates, and repaints. The height of the cells in this row will be equal to the row height minus the row margin.

Parameters:
row - the row whose height is being changed
rowHeight - new row height, in pixels
Throws:
IllegalArgumentException - if rowHeight is less than 1

>>something like outlook calander
I don't see variable row heights in Outlook's calendar
???

>> i really would appreciate it and dont worry about points if it hard and doable i can put more than 100 points
That's OK. (I guess you mean you'll post another Q than?)
But first I have to know what exactly you want.
0
 
LVL 8

Author Comment

by:razo
Comment Utility
ok if u see outlook calandar when u add an appointment it shown as a text box in the the cell. this textbox can then be modified by increasing its length so that it extends over multiple cells....if we can do this than i don't need to change the cells at all

as for the points do i have to post another question? can i give you the extra points from here?
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
I see what you mean.
But that's not so easy.
First, you have to change the cursor when on a limit of an appointment (<> every horizontal line)
Secondly you have to change the background of the cells you move to while dragging.

I saw it quite easier:
1) Defining an appointment:
   - Select a range of cells
   - right-click and choose new appointment
   - new appointment dialog comes up (with the from/to times according to the selected cells; can be changed of course)
   - When closed possibly update the cells according to the changed time window

2) Changing the time window of an existing appointment (only not graphically)
   - right-click the appointment and choose edit (or somehting)
   - appointment dialog comes up again
   - When closed possibly update the cells according to the changed time window

I admit: being able to change the time window graphically is cool, but is it really a must for you?

>>can i give you the extra points from here?
No you can't. Once a Q is closed the points can't be incremented. (btw. more than 500 points is also impossible)
So posting another Q is the only option.
0
 
LVL 8

Author Comment

by:razo
Comment Utility
ok i need it graphically it is important
i am ready to give u another 500 points if u can do it
but i have an idea if we add a textbox to the cell and then the user extends this textbox...not the cell, is that possible?
ok if u could do anything graphically can u let me know so that i post the new question
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
>> if we add a textbox to the cell and then the user extends this textbox...not the cell, is that possible?
I'm afraid not. :(
You can define some text box as cell editor. But what then?
You can't update your table until you're done editing.
And in this case we want the table (cells) to follow the "editing". So... impossible I think.

If we want to do something like this, I think we will need to use a MouseListener and a MouseMotionListener on the table.
And then reacting (= adapting the selections of table cells) on mouse(drag)movements.
I'll see if I can (and find the time to) adapt the demo app with something like that.

I think it won't hurt to post a new Q.
Two or more experts always know more than one ;°)
(And if your Q isn't answered in your opinion, you can always make a request to delete it and refund the points)
0
 
LVL 8

Author Comment

by:razo
Comment Utility
ok ill post a new question
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

771 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

9 Experts available now in Live!

Get 1:1 Help Now