Showing posts with label WindowListener. Show all posts
Showing posts with label WindowListener. Show all posts

Wednesday, 6 November 2013

Java Application for tracking monthly income and balance pt3


Ok, ok I said I'd post the next chapter of the Arduino Starter Kit, but I can't leave this project in half with horrible layout and various fix to do, so here we are.

I fix the layout, improve the readability and add the message box when closing.
For fixing the layout I choose to separate the components into 3 JPanel, adding all three into a GroupLayout set as layoutmanager of the JFrame

The first and the third JPanel are themeselves managed with a GroupLayout, otherwise the second JPanel has a simple FlowLayout because in it there is only the JTable.

The graphical result is the screen down here:



The only fix I need now is to align the third JPanel to center, or move the JCheckBox and the save JButton near the extreme left, aligned with the left edge of the JTable.



To add the message in the closing action when have unsaved modification, I inherit the WindowListener and in his windowClosing() method I managed the Exit. For doing this you must set the default closing action of the JFrame to DO_NOTHING_ON_CLOSE , and change when it need.
I don't have really implemented the others methods because I don't need them in this project. But I must put their implementation in my code or there is a compiler error caused by the not fully implementation of the methods present in the WindowListener interface.

If you want to see the full code is still on my GitHub repository . Now, as you can see up here, I need to align the JPanel3 to center, and change the JLabel jlabError with a JOptionPane message, and maybe improve readability and shortening the code, but these are minor improvement so next evening I can work on next chapter of Arduino for real.

Ygy Freezone

Thursday, 31 October 2013

Java Application for tracking monthly income and balance


As I say in the very first post, I use this blog as worklog for my personal project, and since with my Arduino Starter Kit explanation I'm blocked (I don't have a 9V battery, and neither the time to go out and buy it, shame on me), I'm now working on a little project that I have in mind from long time.

For tracking my personal bank balance, inasmuch as I found the movement list in my home banking not useful, I usually use an Excel file that do simple calculation and return how much money I can spent over the month. So why not write this in java using Swing?

So here a simple analysis:
Monthly Income (shortened in MonIn), is a simple java application which read a file with some hashtag inside, each tag define a value.
Using Swing GUI, display this data to video, then let you modify the data and calculate some total predetermined.

In the future I change the file I/O with a DataBase and relative query.



As you can see I'm a real artist when using MSPaint. 

The source file contains some tag in this form:
#tag1 = value1;
#tag2= value2;
...
#tagN=valueN;
The java.io package is needed to read and write to the file.

The Swing GUI contains the form with all the text field, a table, a button to make the calculation, a checkbox to enable advance setting.

in the future I change the form adding a tabbed pane




The first four text fields are JTextFields, tfAccrual is not editable (setEnabled(false)) and by default set to 200. Constant loss is a JTable, and contains only standard monthly expenses. By default is not editable.
CalcBtn is a JButton, which at click calc the total. Advanced Setting is a JCheckBox, if selected enable editing to tfAccrual and Constant Loss. Totals are three JTextField, not editable, when start application they contains the previous month total.
SaveBtn is a JButton, when pressed write the new value to the file (or in the DB).
This project use the GroupLayout as Layout Manager.
JFrame cannot be resizable in this application (setResizable(false));

On exit, using a WindowListener to check the exit before the closing action of the frame, if there are no unsaved modification then exit, else popup a message that ask if want to save before exit, the popup message is a JOptionPane.

On line documentation about these component and listener on Oracle Doc and Oracle Tutorial.
JTable: Oracle Doc  Oracle Tutorial
GroupLayout: Oracle Tutorial
JFrame: Oracle Doc
WindowListener: Oracle Tutorial
JOptionPane: Oracle Doc
Swing Tutorial: The GuideBook

I the next days I'll post, alternating with Arduino, all the code and some image of this project.
Ygy Freezone