How do I make java code work on both MacOS and Windows?

Viewed 41

I add a mouse wheel event listener to a panel, whenever I scroll, it goes through my arraylist of strings of 100 people. My code currently works on windows, preventing an index out of bounds error.

But if I go on MacOS, it returns an out of bounds error because e.getWheelRotation() returns values from -1->99, whereas e.getWheelRotation() on Windows returns values -1 or 1.

How do I make it so my code runs the same on both MacOS and Windows? Thanks in advance.

 view.getMyFrame().addMouseWheelListener(new MouseWheelListener(){
    int holder = 0;
    int linesToDisplay = 20;
    @Override
    public void mouseWheelMoved(MouseWheelEvent e)
    {

                if((holder == 0 && e.getWheelRotation()!=-1) || (holder > 0 && holder<(100-linesToDisplay) || ((holder ==(100 - linesToDisplay) && e.getWheelRotation()!=1 )))){
                        holder+=e.getWheelRotation();
                        view.updatePanel(holder, linesToDisplay+holder);
                }

    }
}
0 Answers
Related