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.
Us the Amazon Elastic IP service to get a static IP address for your EC2 instance. Then have your domain registrar point your domain to the static IP. If you don't use the Elastic IP service you have no guarantee of keeping the same IP address when you reboot your server for maintenance.