James wasn't jealous, not at all.
He was just really annoyed that you were spending so much time with Barty.
Yeah, it was expected - you're a Slytherin, and so is Barty. And even though James had taken the step of accepting you as a Slytherin - and his attraction to another boy - he'd obviously forgotten to tell you about it, because somewhere in the back of his mind he thought it was mutual, while he'd forgotten to even start talking to you properly.
And while you weren't even friends with James, his friends already knew all the facts about you. And knew that James's jealousy was slowly eating him up inside.
One of the - not - lovely days in Potions class was not doing so good. So bad that one of the ingredients flew off from under James's knife straight, accidentally of course, to Barty and hit him in the back of the head: and you, who were there at the time, laughed so loudly that the two of you were put on detention.
So it was that you and James were sitting up late at night, going over the first year homework that Slughorn had left for you.
Except it wasn't laughing anymore, for James could directly feel the disgruntled look directed to his face
"You know what? I don't care," he blurted, sighing, "I’m sorry, alright? Oi, you can go ahead and marry that Crouch for all i care. What's it to me? And stop looking at me like that!"