Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: HELP PLEASE! How to save and call back user data input.

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default HELP PLEASE! How to save and call back user data input.

    Hi everyone! My project is creating a timetable and the user can input the data his/herself to the timetable which best fits their own schedule. However currently im hardcoding the data in the code. I would like to know how do i get the data input and then be able to save and be able to call back the data whenever i run the program? THANK YOU VERY MUCH!

     
    import javax.swing.JTable;
    import javax.swing.event.TableModelEvent;
    import javax.swing.event.TableModelListener;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JPanel;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.table.TableModel;
     
     
    public class TimeTable extends JFrame implements TableModelListener {
     
     
     
     
     
    public TimeTable(){
    super("TimeTable");
     
    Object[][] data = {
    {"Monday", "", 
    "", "TCP/IP LECTURE", "TCP/IP LECTURE","TCP/IP Tutorial","Break","OOP","OOP","OOP"},//1
     
    {"Tuesday", "","", "Network Management Lecture","Network Management Lecture","Break","OOP Lecture","OOP Lecture","WNet Lecture","WNet Lecture"},//2
     
    {"Wednesday", "TCP/IP Practical",
    "TCP/IP Practical", "Wnet Tutorial", "","","","","",""},//3
     
    {"Thursday", "",
    "", "Network Management Prac", "Network Management Prac","Break","WNet Prac","WNet Prac","Network Management Tutorial",""},//4
     
    {"Friday", "FYP",
    "FYP", "FYP", "FYP","","","","",""},//5
     
    {"Saturday", "Wake Up",
    "Prepare Bag and Things for outing", "", "Meet at Jurong East","","","","",""},//6
     
    {"Sunday", "Lih",
    "Teaching high school", "", "","","","","",""},//7
     
     
     
    };
     
    String[] columnNames = {"Day", 
    "8am-9am",
    "9am-10am",
    "10am-11am",
    "11am-12pm",
    "12pm-1pm",
    "1pm-2pm",
    "2pm-3pm",
    "3pm-4pm",
    "4pm-5pm",
     
    };
     
     
     
    final JTable table = new JTable(data, columnNames);
    table.getModel().addTableModelListener(this);
    table.setPreferredScrollableViewportSize(new Dimension(900, 500));
    //Set Cell Heigh and Width//
    table.setRowHeight(0,90); 
    table.getColumnModel().getColumn(0).setWidth(90); //1
     
    table.setRowHeight(1,90); 
    table.getColumnModel().getColumn(1).setWidth(90); //2
     
    table.setRowHeight(2,90); 
    table.getColumnModel().getColumn(2).setWidth(90); //3
     
    table.setRowHeight(3,90); 
    table.getColumnModel().getColumn(3).setWidth(90); //4 
     
    table.setRowHeight(4,90); 
    table.getColumnModel().getColumn(4).setWidth(90); //5
     
    table.setRowHeight(5,90); 
    table.getColumnModel().getColumn(5).setWidth(90); //6
     
    table.setRowHeight(6,90); 
    table.getColumnModel().getColumn(6).setWidth(90); //7
     
    table.setRowHeight(7,90); 
    table.getColumnModel().getColumn(7).setWidth(90); //8
     
    table.setRowHeight(8,90); 
    table.getColumnModel().getColumn(8).setWidth(90); //9
     
    table.setRowHeight(10,90); 
    table.getColumnModel().getColumn(9).setWidth(90); //10
    /////////////////////////////////////
     
     
     
    //Create the scroll pane and add the table to it. 
    JScrollPane scrollPane = new JScrollPane(table);
     
    //Add the scroll pane to this window.
    getContentPane().add(scrollPane, BorderLayout.CENTER);
     
     
     
    }	
     
     
     
    public static void main(String[] args) {
    TimeTable frame = new TimeTable();
    frame.pack();
    frame.setVisible(true);
    }
     
     
     
     
     
     
    @Override
    public void tableChanged(TableModelEvent e) {
    int row = e.getFirstRow();
    int column = e.getColumn();
    TableModel model = (TableModel)e.getSource();
    String columnName = model.getColumnName(column);
    Object data = model.getValueAt(row, column);
     
     
    }
    }


  2. #2
    Junior Member
    Join Date
    Aug 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: HELP PLEASE! How to save and call back user data input.

    Well, I've always saved user input and data by having the program create a text file and then read from the text file the next time the program is run. Check out the File class in the API, as well as Scanner, BufferedReader, and PrintWriter.

  3. #3
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: HELP PLEASE! How to save and call back user data input.

    You can also use database to manage the whole schedule. File handling is also a solution.

  4. #4
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: HELP PLEASE! How to save and call back user data input.

    Duplicate of this thread: http://www.javaprogrammingforums.com...ata-input.html

Similar Threads

  1. HELP PLEASE! How to save and call back user data input.
    By boi_boi in forum What's Wrong With My Code?
    Replies: 4
    Last Post: August 12th, 2011, 02:21 PM
  2. Save data entered upon reopening
    By SHStudent21 in forum Java Theory & Questions
    Replies: 1
    Last Post: February 12th, 2011, 10:24 PM
  3. How and where do you save user settings?
    By snytkine in forum AWT / Java Swing
    Replies: 3
    Last Post: October 12th, 2010, 05:46 AM
  4. Replies: 8
    Last Post: January 6th, 2010, 09:59 AM
  5. How to detect audio input from a telephone call?
    By ces_31 in forum Java Theory & Questions
    Replies: 0
    Last Post: August 12th, 2009, 12:45 AM