The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
January 2002

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Still experiencing problems

Posted by Hiran on January 25, 2002 at 3:36 PM

Thanks for all your help, but I still seem to be experiencing problems. I have three files and their source codes are listed below. Essentially, HoursTrackerApp is the main logic, HoursTrackerGUI is the main interface and extends HoursTrackerGUICloseableFrame (which allows the the JFrame to close). HoursTrackerGUI contains an HoursTrackerApp object, which it uses to access the logic's methods and such.

//HoursTrackerApp.java
package HoursTracker;

import java.io.*;
import java.util.*;

public class HoursTrackerApp
{
private int day;
private int month;
private int year;
private int ampm;
private int hour;
private int minute;
private int second;
private String dayStr;
private String monthStr;
private String yearStr;
private String ampmStr;
private String hourStr;
private String minuteStr;
private String secondStr;
private String fileName;
private String time;
private FileWriter logFile;
private GregorianCalendar cal;

public HoursTrackerApp(String fileName)
{
this.fileName = fileName;
try
{
logFile = new FileWriter(fileName);
} catch (IOException e)
{
}
}

public void addStartTime()
{
time = "Start ";
addTime();
}

public void addEndTime()
{
time = "End ";
addTime();
}

private void addTime()
{
char backSlash = '/';
char colon = ':';
getTime();
time = dayStr + backSlash + monthStr + backSlash + yearStr + backSlash + " "
+ hourStr + colon + minuteStr + colon + secondStr + colon + ampmStr;
try
{
logFile.write(time);
} catch (IOException e)
{
}
}

private void getTime()
{
getUnFormattedTime();
dayStr = "" + day;
getMonthStr();
yearStr = "" + year;
hourStr = "" + hour;
minuteStr = "" + minute;
secondStr = "" + second;
if (ampm == 0)
{
ampmStr = "AM";
} else
{
ampmStr = "PM";
}
}

private void getUnFormattedTime()
{
cal = new GregorianCalendar();
day = cal.get(cal.DATE);
month = cal.get(cal.MONTH);
year = cal.get(cal.YEAR);
ampm = cal.get(cal.AM_PM);
hour = cal.get(cal.HOUR);
minute = cal.get(cal.MINUTE);
second = cal.get(cal.SECOND);
}

private void getMonthStr()
{
if (month == 0)
{
monthStr = "01";
} else if (month == 1)
{
monthStr = "02";
} else if (month == 2)
{
monthStr = "03";
} else if (month == 3)
{
monthStr = "04";
} else if (month == 4)
{
monthStr = "05";
} else if (month == 5)
{
monthStr = "06";
} else if (month == 6)
{
monthStr = "07";
} else if (month == 7)
{
monthStr = "08";
} else if (month == 8)
{
monthStr = "09";
} else if (month == 9)
{
monthStr = "10";
} else if (month == 10)
{
monthStr = "11";
} else if (month == 11)
{
monthStr = "12";
}
}
}

//HoursTrackerGUI.java
package HoursTracker;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JButton;
import hourstracker.HoursTrackerGUICloseableFrame;
import hourstracker.HoursTrackerApp;

public class HoursTrackerGUI extends HoursTrackerGUICloseableFrame
{
private HoursTrackerApp mainApp = new HoursTrackerApp("c:\\personal file\\programming\\java\\programs\\hourstracker\\log.txt");
private JButton setStartTime = new JButton("Clock in");
private JButton setEndTime = new JButton("Log out");
private JButton quitApp = new JButton("Exit");

public HoursTrackerGUI()
{
super();

this.setSize(400, 300);

Container contents = this.getContentPane();
contents.setLayout(new FlowLayout());
contents.add(setStartTime);
contents.add(setEndTime);
contents.add(quitApp);

setStartTime.addActionListener(new SSTListener());
setEndTime.addActionListener(new ESTListener());
quitApp.addActionListener(new ExitListener());
}

private class SSTListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
mainApp.addStartTime();
}
}

private class ESTListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
mainApp.addEndTime();
}
}

private class ExitListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}

public static void main(String[] args)
{ HoursTrackerGUI app = new HoursTrackerGUI();
}
}

//HoursTrackerGUICloseableFrame.java
package HoursTracker;

import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
import javax.swing.JFrame;

public class HoursTrackerGUICloseableFrame extends JFrame
{
public HoursTrackerGUICloseableFrame()
{
super();
this.addWindowListener(new WindowCloser());
}

private class WindowCloser extends WindowAdapter
{
public void windowClosing(WindowEvent evt)
{
dispose();
System.exit(0);
}
}
}

HoursTrackerApp.java compiles fine, but HoursTrackerAppGUI.java comes back with 7 errors. The four that I can see are:
1) HoursTrackerGUI.java:14: cannot resolve symbol
symbol : class HoursTrackerApp
location: class HoursTracker.HoursTrackerGUI
private HoursTrackerApp mainApp = new HoursTrackerApp("c:\\personal file\\programming\\java\\programs\\hourstracker\\log.txt");
2) Same as 1, except a slight difference (see below).
3) HoursTrackerGUI.java:23: cannot resolve symbol
symbol : method setSize (int,int)
location: class HoursTracker.HoursTrackerGUI
this.setSize(400, 300);
4) HoursTrackerGUI.java:25: cannot resolve symbol
symbol : method getContentPane ()
location: class HoursTracker.HoursTrackerGUI
Container contents = this.getContentPane();
For each of the errors, the ^ symbol (I'm using the inline compiler) is under the H in the first HoursTrackerApp for the first error, under the H in the second HoursTrackerApp for the second error, under the t in this.setSize(400, 300) in the third error, and under the t in this.getContentPane() in the fourth error. Also, if it helps any, I have these three files stored in C:\JavaTemp\HoursTracker\. I know this is a lot, but please help if you can. Thanks in advance.
Hiran



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us