In act 3, scene 2, Hamlet sits beside Ophelia when she comes in with Gertrude, Claudius, and others to watch The Mousetrap. The tone between the two is set by Hamlet. It is full of lighthearted, if somewhat aggressive, sexual banter that he initiates and Ophelia tries to tamp down.
For example, Hamlet calls Ophelia "metal more attractive" than his mother, implying that Ophelia's sexual magnetism draws him in. He then says to Ophelia, "Lady, shall I lie in your lap?" She takes this as a sexual innuendo and says no, so he amends it, saying, "I mean, my head upon your lap?" When she says yes to that, he continues to tease her sexually, asking if she thought he meant "country matters" when he asked to "lie" in her lap. "Country matters" is a euphemism for sex. When Ophelia says she thinks "nothing," Hamlet continues the sexual jokes, using "nothing" as slang for vagina and saying it is "a fair thought to lie between maids' legs."
Hamlet then turns to his obsessive thoughts of his mother marrying so quickly after her husband's death. This could tie his sexual desire for Ophelia to a possible repressed Oedipal desire for Gertrude.
Ophelia and Hamlet's conversation in this scene is significant for several reasons beyond Hamlet's fixation on sexual banter. First, we left the two quarreling and unhappy in act 3, scene 1. Ophelia had returned his gifts, and Hamlet responded in a way Ophelia found unhinged, first saying he loved her and then that he never did, then telling her to get herself to a nunnery. Nunnery in Elizabethan times was a euphemism for whorehouse. Ophelia leaves the scene distraught, thinking Hamlet has gone crazy and saying,
O, what a noble mind is here o'erthrown!
However, by the time of The Mousetrap, the two seem to have made up or at least be getting along. Hamlet is behaving in a way that no longer indicates to Ophelia that he is crazy. At the same time, his sexual talk, partially coming out of his excitement over finally getting to test whether the ghost's story is true, shows where his thoughts are vis-à-vis Ophelia. He perhaps thinks of her as a sex object, is sexually attracted to her, and doesn't mind teasing her with a string of off-color jokes. He is being a jerk, and she is tolerating it.
This scene is significant, too, in that it is the last time we see a sane Ophelia. When we next meet up with her, in act 4, she is flinging flowers around and has lost her senses after Hamlet has killed her father. The beginning of the The Mousetrap is a brief moment of equilibrium in which we see the two getting along and behaving sanely, if bawdily on Hamlet's part.