A really good friend of mine was telling me about a Bible study for men that he attended, where they looked at King David's adultery with Bathsheba, the wife of Uriah, as a cautionary tale. David was the only man that Scripture ever refers to as "a man after God's own heart" (1 Sam. 13:14; Acts 13:22) and yet, he later succumbed to the sin of adultery. His lust burned to the point that he had her husband placed in a dangerous situation in battle, an act that brought about his death. David was punished for his sin; God removed his protective hand and let David experience what a life apart from Him was like. (It got pretty ugly - for David, his family, and his kingdom.) The lesson of course is not to presume on your own strength. Do not place yourself in tempting situations, and when you feel a twinge of lust don't allow it to take root and grow. Call out to God at that very instant to untangle the knots starting to work their way through your soul. Ask for the grace to look at that beautiful woman the same way that God does.
There is another lesson as well, and this is the kind of thing that can only be seen in hindsight ... how God weaves even our sins into His plan to bring about salvation, our ultimate good. David and Bathsheba, you see, became the parents of Solomon and one of Solomon's descendants was ... that's right, Jesus! David and Bathsheba came together in the darkest way imaginable and yet, their son Solomon had always been in God's mind, always intended as a blessing to Israel (within his own lifetime), and then the entire world (through his descendant, Jesus).
What am I trying to say - that God willed the sin of David and Bathsheba to bring about some greater good? Of course not! What David did was evil, the exact opposite of what God desired. It was horrible and even though David repented and God forgave him, David was still required to pay a temporal price for his sin. (You and I are for our sins as well. See here and here, for more.)
What I am saying is that we have a God Who is bigger than our sin, Who is not limited by it. He sees our sins, our free choices to go against His will; and then in His own utterly incredible way He weaves even those sinful choices into His plans. He is never the author of the evils we perpetrate; but He is the author of the good He is able to create out of our atrocities - the child conceived through adultery, fornication, or even a sin as despicable as rape - that child that, no matter how he or she was conceived, has been woven into God's plan to bless the world. Only God, only God, can do this. He stands outside of space and time and meets our freedom to sin with His own freedom to bless.
So whatever you are dealing with, whatever frustration or injustice - a cheating spouse, an act of violence, an illness, whatever it is - remember that Your Father loves You and that beyond all of our understanding, He is able to weave even this into His eternal plan to save you and this world. That is our Faith. It's written right there in Jesus' family tree (Mt. 1:6-7).
"O the depth of the riches and wisdom and knowledge of God! How unsearchable are His judgments and how inscrutable His ways! ...We know that in everything God works for good with those who love him, who are called according to his purpose." (Rom. 11:33; 8:28)