public int compare(Object d1, Object d2) {
         
         //put non display modes at bottom
         if(!(d1 instanceof DisplayMode)) {
            return 1;
         }
         
         if(!(d2 instanceof DisplayMode)) {
            return 1;
         }
         
         //now compare bit depth and resolution
         DisplayMode mode1 = (DisplayMode)d1;
         DisplayMode mode2 = (DisplayMode)d2;
         
         int w1 = mode1.getWidth();
         int w2 = mode2.getWidth();
         
         if(w1<w2) return -1;
         if(w1>w2) return 1;
         
         int h1 = mode1.getHeight();
         int h2 = mode2.getHeight();
         
         if(h1<h2) return -1;
         if(h1>h2) return 1;
         
         int bitd1 = mode1.getBitDepth();
         int bitd2 = mode2.getBitDepth();
         
         if(bitd1<bitd2) return -1;
         if(bitd1>bitd2) return 1;
         
         return 0;
      }