Help with Java
"Eric Krupnik" <[email protected]> Wed, 10 Dec 2008 15:00:15 -0500
| Newsgroups | gmane.comp.java.sisc.user |
|---|---|
| Message-ID | <[email protected]> |
This is a multipart message in MIME format.
------=_NextPart_000_0028_01C95AD8.02B08B50
Content-Type: multipart/alternative;
boundary="----=_NextPart_001_0029_01C95AD8.02B08B50"
------=_NextPart_001_0029_01C95AD8.02B08B50
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Hi Group,
I am having an issue with getting Scheme to do simple things in a working
Java project/application.
I have attached the files to this email (the Java ones) - to run it simply
load all them into IDE and run Money.java.
I want to have scheme do some simple things in this program, maybe do the
buttons or just some simple math functions.
I was barely able to get SISC to be importable, and now am not having any
luck with this.
Please send some advice, with examples would be great - I am not that great
with Scheme yetL
Thanks!
Eric
------=_NextPart_001_0029_01C95AD8.02B08B50
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
<html xmlns:v=3D"urn:schemas-microsoft-com:vml" =
xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" =
xmlns=3D"http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dus-ascii">
<meta name=3DGenerator content=3D"Microsoft Word 12 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
{page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=3DEN-US link=3Dblue vlink=3Dpurple>
<div class=3DSection1>
<p class=3DMsoNormal><span style=3D'font-size:12.0pt'>Hi Group, =
<o:p></o:p></span></p>
<p class=3DMsoNormal><span style=3D'font-size:12.0pt'>I am having an =
issue with getting
Scheme to do simple things in a working Java =
project/application.<o:p></o:p></span></p>
<p class=3DMsoNormal><span style=3D'font-size:12.0pt'>I have attached =
the files to
this email (the Java ones) – to run it simply load all them into =
IDE and
run Money.java.<o:p></o:p></span></p>
<p class=3DMsoNormal><span =
style=3D'font-size:12.0pt'><o:p> </o:p></span></p>
<p class=3DMsoNormal><span style=3D'font-size:12.0pt'>I want to have =
scheme do some
simple things in this program, maybe do the buttons or just some simple =
math
functions.<o:p></o:p></span></p>
<p class=3DMsoNormal><span style=3D'font-size:12.0pt'><br>
I was barely able to get SISC to be importable, and now am not having =
any luck
with this.<o:p></o:p></span></p>
<p class=3DMsoNormal><span =
style=3D'font-size:12.0pt'><o:p> </o:p></span></p>
<p class=3DMsoNormal><span style=3D'font-size:12.0pt'>Please send some =
advice, with
examples would be great – I am not that great with Scheme =
yet</span><span
style=3D'font-size:12.0pt;font-family:Wingdings'>L</span><span =
style=3D'font-size:
12.0pt'><o:p></o:p></span></p>
<p class=3DMsoNormal><span =
style=3D'font-size:12.0pt'><o:p> </o:p></span></p>
<p class=3DMsoNormal><span =
style=3D'font-size:12.0pt'>Thanks!<o:p></o:p></span></p>
<p class=3DMsoNormal><span =
style=3D'font-size:12.0pt'><o:p> </o:p></span></p>
<p class=3DMsoNormal><span style=3D'font-size:12.0pt'>Eric =
<o:p></o:p></span></p>
</div>
</body>
</html>
------=_NextPart_001_0029_01C95AD8.02B08B50--
------=_NextPart_000_0028_01C95AD8.02B08B50
Content-Type: application/octet-stream;
name="Administrative.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="Administrative.java"
/**
Class to represent an Administrative transaction.
@author Eric Krupnik
@date December 2008
*/
public class Administrative extends Transaction {
/**
Constructs a new Administrative transaction and increments numAdmins.
*/
public Administrative(String name, double amount, String date){
super(name, amount, date, "Admin");
numAdmins++;
}
public void finalize(){
numAdmins--;
}
}
------=_NextPart_000_0028_01C95AD8.02B08B50
Content-Type: application/octet-stream;
name="Check.java"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="Check.java"
/**
Class to represent a Check.
@author Eric Krupnik
@date December 2008
*/
public class Check extends Transaction{
/**
Constructs a new check and increments the variable numChecks.
*/
public Check(String name, double amount, String date){
super(name, amount, date, "Check");
numChecks++;
}
/**
The amount of a check is stored as a positive double. However, =
the reason it is returned as
a negative is to show the check amount must be subtracted from =
the balance.
*/
public double getAmount(){
return -super.getAmount();
}
public void finalize(){ =20
numChecks--;
}
}
------=_NextPart_000_0028_01C95AD8.02B08B50
Content-Type: application/octet-stream;
name="Checkbook.java"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="Checkbook.java"
import java.util.Vector;
/**
Class to represent a CheckBook, which is used to store and manage =
transaction=20
objects and totals for the check, deposit, and administrative =
totals, as well as
the total balance of the account.=20
@author Eric Krupnik
@date December 2008
*/
public class Checkbook {
private String bankName;
private double checkAmount;
private double depositAmount;
private double adminAmount;
private Vector transactions;
public Checkbook(String bankName){
this.bankName =3D bankName;
checkAmount =3D 0.0;
depositAmount =3D 0.0;
adminAmount =3D 0.0;
transactions =3D new Vector();
}
public double getCheckAmount(){
return checkAmount;
}
=20
public double getDepositAmount(){
return depositAmount;
}
=20
public double getAdminAmount(){
return adminAmount;
}
=20
public double getAmount(){
return checkAmount + depositAmount + adminAmount;
} =20
public void addTransaction(Check check){
checkAmount +=3D check.getAmount();
transactions.addElement(check);
}
=20
public void addTransaction(Deposit deposit){
depositAmount +=3D deposit.getAmount();
transactions.addElement(deposit);
}
=20
public void addTransaction(Administrative admin){
adminAmount +=3D admin.getAmount();
transactions.addElement(admin);
}
=20
public Transaction getTransaction(int i){
return (Transaction)transactions.get(i);
}
=20
public void deleteTransaction(int i){
Transaction t =3D getTransaction(i);
if (t instanceof Check)
checkAmount -=3D t.getAmount();
else if (t instanceof Deposit)
depositAmount -=3D t.getAmount();
else if (t instanceof Administrative)
adminAmount -=3D t.getAmount();
transactions.remove(i);
}
=20
public int getSize(){
return transactions.size();
}
=20
public String getBankName(){
return bankName;
}
=20
/**
Returns a string representation of a checkbook object.
*/
public String toString(){
StringBuffer stringbuffer =3D new StringBuffer();
stringbuffer.append("Number of transactions: " + getSize() + =
"\n");
stringbuffer.append("\tAmount of checks:\t$" + checkAmount + =
"\n");
stringbuffer.append("\tAmount of deposits:\t$" + depositAmount + =
"\n");
stringbuffer.append("\tAmount of admins:\t$" + adminAmount + =
"\n");
stringbuffer.append("\tTOTAL AMOUNT:\t$" + getAmount() + "\n");
return stringbuffer.toString();
}
}
------=_NextPart_000_0028_01C95AD8.02B08B50
Content-Type: application/octet-stream;
name="Deposit.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="Deposit.java"
/**
Class to represent a Deposit.
@author Eric Krupnik
@date December 2008
*/
public class Deposit extends Transaction{
/**
Constructs a new deposit and increments the variable numDeposits.
*/
public Deposit(String name, double amount, String date){
super(name, amount, date, "Deposit");
numDeposits++;
}
public void finalize(){
numDeposits--;
}
}
------=_NextPart_000_0028_01C95AD8.02B08B50
Content-Type: application/octet-stream;
name="Money.java"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="Money.java"
import java.util.Date;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.FlowLayout;
import javax.swing.*;
import java.awt.event.*;
/**
Main program with GUI to add and delete transactions.=20
@author Eric Krupnik
@date December 2008
*/
public class Money extends JFrame implements ActionListener, =
ItemListener {
private JCheckBox checkOption =3D new JCheckBox("Check", true);
private JCheckBox depositOption =3D new JCheckBox("Deposit", false);
private JCheckBox adminOption =3D new JCheckBox("Administrative", =
false);
private JButton add =3D new JButton("Add", new =
ImageIcon("money.gif"));
private JButton del =3D new JButton("Remove", new =
ImageIcon("remove.gif"));
private JButton quit =3D new JButton("Quit");
private JTextField name =3D new JTextField(40);
private JTextField amount =3D new JTextField(10);
private JTextField date =3D new JTextField(25);
private JLabel checkAmount =3D new JLabel("Checks: $0.0");
private JLabel depositAmount =3D new JLabel("Deposits: $0.0");
private JLabel adminAmount =3D new JLabel("Admins: $0.0");
private JLabel totalAmount =3D new JLabel("Total: $0.0");
private DefaultListModel listData =3D new DefaultListModel();
private JList transactionList =3D new JList(listData);
private Checkbook checkbook =3D new Checkbook("Computing IV Bank");
/**
The constructor creates the JFrame and adds all the GUI =
components using several layout managers.
*/
public Money(){
super("Computing IV Checkbook Balancer");
JPanel panel =3D new JPanel();
panel.setLayout(new BorderLayout());
panel.add("North", getStatusPanel());
panel.add("Center", getInputPanel());
panel.add("East", getButtonPanel());
panel.add("South", getOptionsPanel());
getContentPane().setLayout(new BorderLayout());
getContentPane().add("South", panel);
getContentPane().add("Center", getListPanel());
// activating the buttons so they can generate action events, =
which are intercepted by the 'actionPerformed' method.
del.addActionListener(this);
add.addActionListener(this);
quit.addActionListener(this);
// activating the checkboxes so that they can generate 'item =
events', which are intercepted
// by the 'itemStateChanged' method. This allows the program to =
disallow editing of the
// 'name' field when an 'administrative' transaction is chosen.
checkOption.addItemListener(this);
depositOption.addItemListener(this);
adminOption.addItemListener(this);
validate();=20
pack();
show();
// adding today's date as default entry to the 'date' text field
date.setText(Transaction.toDate(new Date()));
updateStatus();
name.requestFocus();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
/**
Method to layout the list together with its title.
*/
private JPanel getListPanel(){
JPanel panel =3D new JPanel();
panel.setLayout(new BorderLayout());
panel.add("North", new JLabel("<html><h1>Transaction =
List</h1></html>")); //uses the HTML for font editing - used Heading 1.
panel.add("Center", new JScrollPane(transactionList));
=20
return panel;
}
/**
Method to display the add/withdraw options and add them as =
mutually exclusive selections (only one can be selected at a time).
*/
private JPanel getOptionsPanel(){
JPanel panel =3D new JPanel();
panel.setLayout(new FlowLayout());
panel.add(checkOption);
panel.add(depositOption);
panel.add(adminOption);
ButtonGroup radioGroup =3D new ButtonGroup();
radioGroup.add(checkOption);
radioGroup.add(depositOption);
radioGroup.add(adminOption);
return panel;
}
/**
Method to layout the status line (fields for check, deposit, =
etc. amounts).
*/
private JPanel getStatusPanel(){
JPanel status =3D new JPanel();
status.setLayout(new GridLayout(1, 4));
status.add(checkAmount);
status.add(depositAmount);
status.add(adminAmount);
status.add(totalAmount);
return status;
}
/**
Method to layout the buttons in a grid and to add button tips - =
hold mouse over the button for help.
*/
private JPanel getButtonPanel(){
JPanel buttons =3D new JPanel();
buttons.setLayout(new GridLayout(3, 1));
buttons.add(add); =20
add.setToolTipText("Add new transaction");
buttons.add(del); =20
del.setToolTipText("Delete selected transaction");
buttons.add(quit); =20
quit.setToolTipText("Quit program");=20
=20
return buttons;
}
/**
Method to layout the input text fields and their labels.
*/
private JPanel getInputPanel(){
JPanel labels =3D new JPanel();
labels.setLayout(new GridLayout(3, 1));
labels.add(new JLabel("Name"));
labels.add(new JLabel("Amount"));
labels.add(new JLabel("Date"));
=20
JPanel fields =3D new JPanel();
fields.setLayout(new GridLayout(3, 1));
fields.add(name);
fields.add(amount);=20
fields.add(date);
name.setToolTipText("Enter recipient of transaction here");
amount.setToolTipText("Enter dollar amount of your transaction =
here");
date.setToolTipText("Enter date: (MM/DD/YY)");
JPanel input =3D new JPanel();
input.setLayout(new BorderLayout());
input.add("West", labels);
input.add("Center", fields);
return input;
}
/**
Method to update the status fields for new deposit, check, etc. =
amounts.
*/
private void updateStatus(){
checkAmount.setText("Checks: " + =
Transaction.toMoney(checkbook.getCheckAmount()));
depositAmount.setText("Deposits: " + =
Transaction.toMoney(checkbook.getDepositAmount()));
adminAmount.setText(" Admins: " + =
Transaction.toMoney(checkbook.getAdminAmount()));
totalAmount.setText(checkbook.getSize() + " Total: " + =
Transaction.toMoney(checkbook.getAmount()));
}
/**
Method for adding a new transaction depending on which of the =
checkboxes is currently selected.
*/
private void addTransaction(){
String name_s =3D name.getText().trim();
String amount_s =3D amount.getText().trim();
String date_s =3D date.getText().trim();
double amount_d =3D Double.parseDouble(amount_s);
Transaction t =3D null;
=20
if (checkOption.isSelected()){
t =3D new Check(name_s, amount_d, date_s);
listData.addElement(t.toString());
checkbook.addTransaction((Check)t);
}
else if (depositOption.isSelected()){
t =3D new Deposit(name_s, amount_d, date_s);
checkbook.addTransaction((Deposit)t);
listData.addElement(t.toString());
}
else{
t =3D new Administrative(name_s, amount_d, date_s);
checkbook.addTransaction((Administrative)t);
listData.addElement(t.toString());
}
=20
updateStatus();
name.setText("");
amount.setText("0.0");
name.requestFocus();
}
/**
Removing a selected transaction from the account.
*/
private void delTransaction(){
int pos =3D transactionList.getSelectedIndex();
if (pos >=3D 0){
transactionList.remove(pos);
checkbook.deleteTransaction(pos);
System.gc();
updateStatus();
}
}
/**
Standard method to intercept action events and react =
accordingly.
*/
public void actionPerformed(ActionEvent actionevent){
if (actionevent.getSource() =3D=3D quit)
System.exit(0);
else if (actionevent.getSource() =3D=3D add)
addTransaction();
else if (actionevent.getSource() =3D=3D del)
delTransaction();
}
/**
Standard method to intercept item events and react accordingly.
*/
public void itemStateChanged(ItemEvent ie)
{
if (adminOption.isSelected()){
name.setText(checkbook.getBankName());
name.setEditable(false);
}
else
name.setEditable(true);
}
/**
Standard method to make this class executable.=20
*/
public static void main(String args[]){
Money m =3D new Money();
}
}
------=_NextPart_000_0028_01C95AD8.02B08B50
Content-Type: application/octet-stream;
name="Transaction.java"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="Transaction.java"
import java.util.Date;
import java.text.ParseException;
import java.text.DecimalFormat;
import java.text.DateFormat;
/**
Superclass for all checkbook transactions, which are 'data storage' =
classes.
@author Eric Krupnik
@date December 2008
*/
public class Transaction{
/**
The MONEY_FORMAT object is used to format a decimal number as a =
string representing
US dollars.
*/
private static final DecimalFormat MONEY_FORMAT =3D new =
DecimalFormat("$#,##0.00");
/**
The DATE_FORMAT object is used to format a Date object.
*/
private static final DateFormat DATE_FORMAT =3D =
DateFormat.getDateInstance(DateFormat.SHORT);
private String name;
private double amount;
private String date;
private String type;
protected static int numDeposits =3D 0;
protected static int numChecks =3D 0;
protected static int numAdmins =3D 0;
/**
Create a transaction with the given name, amount, date, and =
type.=20
*/
public Transaction(String name, double amount, String date, String =
type){
super();
DATE_FORMAT.setLenient(false);
this.name =3D name;
this.amount =3D amount;
try{
this.date =3D toDate(DATE_FORMAT.parse(date));
}
catch(ParseException pe){
this.date =3D "invalid";
}
=20
this.type =3D type;
}
public double getAmount(){
return amount;
}
public String getName(){
return name;
}
public String getDate(){
return date;
}
/**
Method to format a double as a string representing US dollars.
*/
public static String toMoney(double d){
return MONEY_FORMAT.format(d);
}
/**
Method to format a date.
*/
public static String toDate(Date d){
return DATE_FORMAT.format(d);
}
/**
Returns a string representation of a transaction.
*/
public String toString(){
return toMoney(amount) + " - " + name + " on " + date + " (" + =
type +")";
}
}
------=_NextPart_000_0028_01C95AD8.02B08B50
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you. Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
------=_NextPart_000_0028_01C95AD8.02B08B50
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Sisc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sisc-users
------=_NextPart_000_0028_01C95AD8.02B08B50--