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:

I've figured it out (eom)

Posted by Hiran on January 26, 2002 at 9:42 PM

> I found it today and am trying it now. It's called JCreator. I forget the URL, and I'm too lazy to search for it, so do it yourself. It doesn't seem too bad, though I haven't used it that much. It was created with C++, so it should be faster than JBuilder and similiar software. The reason I originally asked the question is because I'm fed up with JBuilder. It screws things up for me, so I can't use javac when I have JBuilder installed. Actually, I have a question regarding the code that I posted a few posts down (see Adding action listeners to JButton and all the replies). I can now compile the code fine, and it executes fine (ie, the application starts and displays what it should). The problem is that when I click on one of the buttons that logs the time, the write method doesn't seem to be working, or I'm doing something wrong. There's no error that's being returned. I checked, and the line that calls the write method is being executed. Also, the path and filename of the file I'm writing to exists. I've included the necessary code below. The HoursTrackerGUI is the GUI and the HoursTrackerApp is the logic.
>


> //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)
> {
> System.out.println(e.toString());
> }
> }

> 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 + " "
> + hourStr + colon + minuteStr + colon + secondStr + ampmStr;
> try
> {
> logFile.write(time);
> } catch (IOException e)
> {
> System.out.println(e.toString());
> }
> }

> 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;

> public class HoursTrackerGUI extends HoursTrackerGUICloseableFrame
> {
> private HoursTrackerApp mainApp = new HoursTrackerApp("c:\\personal files\\career\\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(250, 60);
>
> 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();
> app.show();
> }
> }
>


> By the way, thanks Matt for the tip about Jikes.
> Hiran

> > Do you want the graphical forms, like JBuilder has? I actually find that feature not to be that great in comparison to tools like C++ Builder and Delphi. Maybe it is because Layouts just seem more difficult to work with graphically (or maybe I just need more practice with it).

> > Anyhow, another tool that I tried was called IDEA, by IntelliJ. It is a really nice and smart Java development tool. It doesn't do the graphical forms stuff (as far as I know), but it is really smart about Java code and does all kinds of nifty automatic and intuitive things. For instance, if you type in some class from the Java API, it will automatically add the necessary imports above. It also does all the usual nice stuff, like showing parameter names/types as you type in a method, syntax highlighting, different project views, version control integration, etc. You can try it for free for 20 days, I think it was.

> > I tried it and liked it a lot, but didn't buy it yet, because I'm still using my old Vaio notebook which only has 64MB of RAM. That much RAM just doesn't cut it for big Java apps -- IDEA, like JBuilder is a Java app. I do have JBuilder 3, by the way, and it has the same problem. They both hang the machine after a short time. Unfortunately, I like to be mobile and work on the notebook machine, so I am stuck using a text editor and Jikes, for now.

> > I also tried out TogetherSoft's product, but it had a timed trial period, too and I chose a poor time to begin it. I ended up being too busy to try it out much before the trial expired. It seemed a bit complicated, so I think it would take a bit of a learning curve to get comforatable with it, but seemed to have a lot of features, too.

> > By the way, for those still using Javac to compile things, you should know that Jikes (which is free -- I forget the url, search on google to find it) is impossibly fast in comparison.

> > Additionally, you might check sites like JavaWorld or Software Development for reviews of development environments. (And report back any pithy information you glean!)





Replies:

Sponsored Links



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