If you do something because you're a dick, but then it works out okay anyway, you're still a dick.

And that's pretty much it. Kantian morality is based around two ideas. First, the principal of universalization ("Act only according to maxims which you can will also to be universal laws", according to Kant). What this means is "only do things that work out well if everybody did them". Being honest works well if everyone does it, so according to Kant, being honest is moral. On the contrary, stealing doesn't work well if everyone does it, nor does lying. So according to Kant, these are not moral things to do.

Secondly, Kant believes that you should not use people as a means to achieve an end. In other words, if you do something immoral, even if the end result is something good, then it was still an immoral act.

If you'd like to learn more about Kant's views on ethics, I suggest picking up The Great Philosophers, by Stephen Law. It does a good job at exploring Kantian ethics in some detail, without getting too technical (as well as explain the philosophies of 49 other great thinkers). Highly recommended book!