Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

Java Euro Converter

Thread view: 
r.demandt@gmail.com - 03 Oct 2007 19:38 GMT
Hi,

I'm trying to write a Java Applet that converts euro's to dollars (+
dollars to euro's). I never wrote a Java Applet before so I don''t
know where to start. Is there anyone that would like to write me a
basic applet to perform the specified task?

Any help would be very welcome!

Thanks for any response,
R.Demandt
edgar - 03 Oct 2007 20:53 GMT
On Oct 3, 11:38 am, r.dema...@gmail.com wrote:
> Hi,
>
[quoted text clipped - 7 lines]
> Thanks for any response,
> R.Demandt

Try this http://java.sun.com/docs/books/tutorial/deployment/applet/getStarted.html
Roedy Green - 04 Oct 2007 02:22 GMT
>I'm trying to write a Java Applet that converts euro's to dollars (+
>dollars to euro's). I never wrote a Java Applet before so I don''t
>know where to start. Is there anyone that would like to write me a
>basic applet to perform the specified task?

You might look at http://mindprod.com/products1.html#CURRCON

However is quite a bit more elaborate than what you need.

You could write a very simple versions that had two fields:
1. where you enter the money.
2.where you get the equivalent.

You press a Convert button.

Thes is the basic structure of nearly every Applet. You can use any
Applet as a model. The only tricky thing is editing the dollar value.

You might look at http://mindprod.com/products1.html#CANADIANTAX
for my JSpinner than also lets you write in with validation.  This too
is probably more elaborate than you want to tackle right off.

So read up on DecimalFormat. See
http://mindprod.com/jgloss/decimalformat.html
to validate and format the value.

You first of all need to examine the code for some simple Applets till
you understand such things as Buttons, ActionListeners, TextFields (or
their Swing equilavents)

you might visit my site to look at Applets.  
http://mindprod.com/applet/applets.html

All come with well-commented source.

Look at the simplest ones.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

R.Demandt - 04 Oct 2007 21:45 GMT
Hi,

I am trying to get this top work, but I really don't get it!
Is there really no one that would like to write me a little piece of
code, so that I have a start?

Any help would be o so very welcome!
Hunter Gratzner - 04 Oct 2007 22:33 GMT
> Hi,
>
> I am trying to get this top work, but I really don't get it!
> Is there really no one that would like to write me a little piece of
> code, so that I have a start?

This is a discussion group, not a homework forum. Most people here
strongly believe that students should do their own homework.
Roedy Green - 05 Oct 2007 02:42 GMT
>I am trying to get this top work, but I really don't get it!
>Is there really no one that would like to write me a little piece of
>code, so that I have a start?

I have written dozen of hunks of code with posted source.

For each component e.g. JButton there is a program. See
http://mindprod.com/jgloss/jbutton.html
see http://mindprod.com/jgloss/decimalformat.html
for how to use that.
I gave you a list of the components you will need.

then to see them work together in various combination see the link I
gave you before
http://mindprod.com/applet/applets.html

Source is posted for all of those Applets.

Your calculations are trivial.  Just  multiply the amount by the ratio
of the values of the euro to the dollar.

Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

R.Demandt - 05 Oct 2007 20:33 GMT
On the moment this is what I have:

//Applet 01 - Euro Converter - Build_001

import java.applet.*;
import java.awt.*;

public class Euro extends Applet
{
    TextField invoerbedrag;
    TextField koers;

    Button eurogulden;
    Button guldeneuro;

    Label uitvoer;

    public void paint (Graphics pen)
    {
        invoerbedrag.setBounds(100,30,100,25);
        koers.setBounds(250,30,100,25);

        eurogulden.setBounds(125,100,100,25);
        guldeneuro.setBounds(225,100,100,25);

        uitvoer.setBounds(150,150,100,25);

        pen.drawString("Invoer:",100,20);
        pen.drawString("Koers:",250,20);
        pen.setColor(Color.black);
    }

    public void init()
    {
        uitvoer=new Label("");
        add(uitvoer);

        invoerbedrag=new TextField("");
        add(invoerbedrag);

        koers=new TextField("2,20371");
        add(koers);

        eurogulden=new Button("Euro > Gulden");
        add(eurogulden);

        guldeneuro= new Button("Gulden > Euro");
        add(guldeneuro);
    }

}

It's all in Dutch, but it only is the layout. Now I have to make the
number in the "invoer" textbox be dived by the number in the "koers"
textbox when I click on button "guldeneuro" and I have to make to
number in the "invoer" textbox be multiplied by the number in the
"koers" textbox when I click on the button "eurogulden". Could someone
tell me what to do?

Thanks for any help.
R.Demandt - 06 Oct 2007 10:18 GMT
Hi,

This is what I have so far:

//Applet 01 - Euro Converter - Build_001

import java.applet.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Euro extends Applet
{
  TextField invoer;
  TextField koers;

  Button eurogulden;
  Button guldeneuro;

  Label uitvoer;

  public void paint (Graphics pen)
  {
     invoer.setBounds(100,30,100,25);
     koers.setBounds(250,30,100,25);

     eurogulden.setBounds(125,100,100,25);
     guldeneuro.setBounds(225,100,100,25);

     uitvoer.setBounds(150,150,100,25);

     pen.drawString("Invoer:",100,20);
     pen.drawString("Koers:",250,20);
     pen.setColor(Color.black);
  }

  public void init()
  {
     guldeneuro.addActionListener(this);
     eurogulden.addActionListener(this);

     uitvoer=new Label("");
     add(uitvoer);

     invoer=new TextField("");
     add(invoer);

     koers=new TextField("2.20371");
     add(koers);

     eurogulden=new Button("Euro > Gulden");
     add(eurogulden);

     guldeneuro=new Button("Gulden > Euro");
     add(guldeneuro);
   }

  public void actionPerformed(ActionEvent actionevent)
  {
     actionevent.getSource();
          String s = actionevent.getActionCommand();

           if(s.equals("Euro > Gulden"))
           {
               if(invoer.getText() != "")
               {
                   Double double1 = new Double(invoer.getText());
                   double d = double1.doubleValue() /
koers.getText();
                   Double double3 = new Double(d);
                   uitvoer.setText(double3.toString());
                   return;
               }
           } else
           if(s.equals("Gulden > Euro") && invoer.getText() != "")
           {
               Double double2 = new Double(invoer.getText());
               double d1 = double2.doubleValue() * koers.getText();
               Double double4 = new Double(d1);
               uitvoer.setText(double4.toString());
           }
  }

}

But when compiling I get the following error's:
C:\Program Files\Java\Java Development Kit\bin\Euro.java:35:
addActionListener(java.awt.event.ActionListener) in java.awt.Button
cannot be applied to (Euro)
guldeneuro.addActionListener(this);
^
C:\Program Files\Java\Java Development Kit\bin\Euro.java:36:
addActionListener(java.awt.event.ActionListener) in java.awt.Button
cannot be applied to (Euro)
eurogulden.addActionListener(this);
^
C:\Program Files\Java\Java Development Kit\bin\Euro.java:64:
operator / cannot be applied to double,java.lang.String
double d = double1.doubleValue() / koers.getText();
^
C:\Program Files\Java\Java Development Kit\bin\Euro.java:70: cannot
find symbol
symbol : variable Invoer
location: class Euro
if(s.equals("Gulden > Euro") && Invoer.getText() != "")
^
C:\Program Files\Java\Java Development Kit\bin\Euro.java:73: operator
* cannot be applied to double,java.lang.String
double d1 = double2.doubleValue() * koers.getText();
^
5 errors

If anyone knows what I have to change, please let me know!

Thanks for any response,
R.Demandt
Lew - 06 Oct 2007 15:04 GMT
> But when compiling I get the following error's [sic]:
> C:\Program Files\Java\Java Development Kit\bin\Euro.java:35:
> addActionListener(java.awt.event.ActionListener) in java.awt.Button
> cannot be applied to (Euro)
> guldeneuro.addActionListener(this);
> ^

The class of 'this' is 'Euro', which is not an ActionListener.  It's all in
the compiler message.

> C:\Program Files\Java\Java Development Kit\bin\Euro.java:36:
> addActionListener(java.awt.event.ActionListener) in java.awt.Button
> cannot be applied to (Euro)
> eurogulden.addActionListener(this);
> ^

The class of 'this' is 'Euro', which is not an ActionListener.  It's all in
the compiler message.

> C:\Program Files\Java\Java Development Kit\bin\Euro.java:64:
> operator / cannot be applied to double,java.lang.String
> double d = double1.doubleValue() / koers.getText();
> ^

You cannot divide by a String, which is what getText() returns.  It's all in
the compiler message.

> C:\Program Files\Java\Java Development Kit\bin\Euro.java:70: cannot
> find symbol
[quoted text clipped - 6 lines]
> double d1 = double2.doubleValue() * koers.getText();
> ^

You cannot multiply by a String, which is what getText() returns.  It's all in
the compiler message.

> If anyone knows what I have to change, please let me know!

Study and learn from:
<http://java.sun.com/docs/books/tutorial/index.html>

You need to master certain basics.

Signature

Lew



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.