Results 1 to 4 of 4

Thread: Calendar Help

  1. #1
    loopsnhoops is offline Member
    Join Date
    Feb 2011
    Posts
    83
    Rep Power
    0

    Wink Calendar Help

    Hi,

    I am making an attendance sheet for a hockey program. I need help on the reading out of a file to see whats on a particular date and then writing into the file when I want to save some info. I also need help making the reading index or the date be exact. Take a look at my code please.
    Java Code:
    package HouseHockey;
    
    import java.awt.BorderLayout;
    import java.awt.Point;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.util.Date;
    import java.util.GregorianCalendar;
    import java.util.Hashtable;
    import java.util.Vector;
    
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.AbstractTableModel;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableModel;
    
    public class Scores {
    
    	GregorianCalendar cal = new GregorianCalendar();
    	int a = cal.get(GregorianCalendar.DAY_OF_MONTH);
    	int b = cal.get(GregorianCalendar.MONTH);
    	int c = cal.get(GregorianCalendar.YEAR);
    	int monthdays = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
    	
    	JPanel pane1 = new JPanel();
    	JPanel pane2 = new JPanel();
    	JButton nxt = new JButton("Forward");
    	JButton bck = new JButton("Backward");
    
    	JTable scoresheet = new JTable();
    	JScrollPane spane = new JScrollPane(scoresheet);
    	
    	
    	
    
    	public Scores(final JPanel paneM) {
    
    		// for (int i = 0;i < 4;i ++){
    		//
    		//
    		// model.addRow(headers[i]);
    		//
    		// }
    		String[] headers = { "Points", "Fouls", "Players" };
    
    		TableModel model = new SparseTableModel(2, headers) {
    			public boolean isCellEditable(int rowIndex, int mColIndex) {
    				return false;
    
    			}
    		};
    
    		scoresheet.setModel(model);
    
    		String thedate = a + "/" + b + "/" + c + "/";
    		pane1.add(new JLabel(thedate), BorderLayout.NORTH);
    		pane1.add(spane, BorderLayout.CENTER);
    		pane2.add(nxt, BorderLayout.EAST);
    		pane2.add(bck, BorderLayout.EAST);
    
    		paneM.add(pane1, BorderLayout.EAST);
    		paneM.add(pane2, BorderLayout.WEST);
    
    		paneM.setSize(600, 600);
    		paneM.setVisible(true);
    
    		try {
    			BufferedReader in = new BufferedReader(new FileReader(
    					"/Users/eric.manget/Desktop/Scores.rtf"));
    			// Create file
    			FileWriter fstream = new FileWriter(
    					"/Users/eric.manget/Desktop/Scores.rtf");
    			BufferedWriter out = new BufferedWriter(fstream);
    
    			out.write(a + "//" + b + "//" + c + "//");
    
    			// Close the output stream
    
    			out.close();
    
    		} catch (Exception e) {// Catch exception if any
    
    			System.err.println("Error: " + e.getMessage());
    
    		}
    
    		nxt.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent actionEvent) {
    
    				a = a + 1;
    
    				if (a == monthdays) {
    					a = 0;
    					b = b + 1;
    					cal.set(cal.MONTH,b);
    				}
    				if (b == 12) {
    					c = c + 1;
    				}
    
    				System.out.println(a);
    				System.out.println(b);
    				System.out.println(c);
    				//paneM.removeAll();
    
    				//new Scores(paneM);
    
    			}
    
    		});
    
    		bck.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent actionEvent) {
    
    			}
    
    		});
    
    	}
    
    	class SparseTableModel extends AbstractTableModel {
    
    		private Hashtable lookup;
    
    		private final int rows;
    
    		private final int columns;
    
    		private final String headers[];
    
    		public SparseTableModel(int rows, String columnHeaders[]) {
    
    			if ((rows < 0) || (columnHeaders == null)) {
    				throw new IllegalArgumentException(
    						"Invalid row count/columnHeaders");
    			}
    			this.rows = rows;
    			this.columns = columnHeaders.length;
    			headers = columnHeaders;
    			lookup = new Hashtable();
    		}
    
    		public int getColumnCount() {
    			return columns;
    		}
    
    		public int getRowCount() {
    			return rows;
    		}
    
    		public String getColumnName(int column) {
    			return headers[column];
    		}
    
    		public Object getValueAt(int row, int column) {
    			return lookup.get(new Point(row, column));
    		}
    
    		public void setValueAt(Object value, int row, int column) {
    			if ((rows < 0) || (columns < 0)) {
    				throw new IllegalArgumentException("Invalid row/column setting");
    			}
    			if ((row < rows) && (column < columns)) {
    				lookup.put(new Point(row, column), value);
    			}
    		}
    	}

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,412
    Rep Power
    25

    Default

    You list several problems. I'll start with the first one I see:
    I need help on the reading out of a file
    What is the problems you are having reading from a file?

    The next one looks like some kind of parsing problem with the data from the file:
    to see whats on a particular date
    The next is:
    writing into the file when I want to save some info
    Can you explain what the problem is here?

    The first problem I have with your posted code is compiling it. I get 41 errors. Mostly from missing import statements.
    Last edited by Norm; 05-23-2011 at 10:46 PM.

  3. #3
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Calendar Help Please
    ^Posted ~4 hours before this topic was made by the same user.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,239
    Rep Power
    19

    Default

    loopsnhoops, please go through the forum rules linked from the sidebar.
    Please do not start more than one topic (in the same OR different forums) with the same question or message.
    I'm closing this thread.

    db

Similar Threads

  1. Calendar Help Please
    By loopsnhoops in forum New To Java
    Replies: 4
    Last Post: 05-24-2011, 10:35 AM
  2. How to add a calendar????
    By zifis in forum New To Java
    Replies: 5
    Last Post: 04-07-2009, 04:04 PM
  3. Calendar bug?
    By Stigvig in forum Advanced Java
    Replies: 14
    Last Post: 02-08-2009, 09:56 AM
  4. calendar
    By John in forum SWT / JFace
    Replies: 12
    Last Post: 08-07-2008, 10:54 PM
  5. Web calendar
    By Daniel in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 06-27-2007, 05:36 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •