I've bought a domainname and pointed it to my amazon EC2 instance (example: ec2-XXX-XXX-XXX-XXX.us-west-1.compute.amazonaws.com), and it works, but when I go to www.example.com, the long amazon public dns adress shows upp in the url field. Is there a way to make it stay www.example.com?
When you say "pointed it to", it sounds like you have used a URL forwarding mechanism rather than proper DNS hosting.
To do this right, you will need to have somebody do DNS hosting for you, probably the same company that you registered your domain through. You will configure the name servers on your domain to point to them, then using their DNS configuration settings, configure the address of your EC2 instance as the registered host for service on that domain.
Lastly, you should change the host name in apache or whatever web server software you are using so that it understands what domain name it is supposed to be accepting traffic for.