Results 1 to 4 of 4
Thread: Calendar Help
- 05-23-2011, 10:05 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 83
- Rep Power
- 0
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); } } }
- 05-23-2011, 10:41 PM #2
You list several problems. I'll start with the first one I see:
What is the problems you are having reading from a file?I need help on the reading out of a file
The next one looks like some kind of parsing problem with the data from the file:
The next is:to see whats on a particular date
Can you explain what the problem is here?writing into the file when I want to save some info
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.
- 05-24-2011, 09:07 AM #3
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.
- 05-24-2011, 10:35 AM #4
loopsnhoops, please go through the forum rules linked from the sidebar.
I'm closing this thread.Please do not start more than one topic (in the same OR different forums) with the same question or message.
db
Similar Threads
-
Calendar Help Please
By loopsnhoops in forum New To JavaReplies: 4Last Post: 05-24-2011, 10:35 AM -
How to add a calendar????
By zifis in forum New To JavaReplies: 5Last Post: 04-07-2009, 04:04 PM -
Calendar bug?
By Stigvig in forum Advanced JavaReplies: 14Last Post: 02-08-2009, 09:56 AM -
calendar
By John in forum SWT / JFaceReplies: 12Last Post: 08-07-2008, 10:54 PM -
Web calendar
By Daniel in forum Enterprise JavaBeans (EJB)Replies: 1Last Post: 06-27-2007, 05:36 PM


LinkBack URL
About LinkBacks

Bookmarks