nschessnerd 0 Posting Whiz in Training

Hey, Im having a problem getting my applet to repaint after it is resized. + and - buttons resize it but sometimes it wont get bigger or repaint.
here is the src for the applet

private ArrayList<CompareColor> myColors;
    private ArrayList<CompareColor> fixedColors;
    private int w=0;
    private int h=0;
    private int csize = 10;
    int dots = 10;

    public void init() {
        myColors = new ArrayList<CompareColor>();
        fixedColors = new ArrayList<CompareColor>();
        //initialize ArrayList
        int r = 0;
        int g = 0;
        int b = 0;
        for (int i = 0; i < dots; i++) {
            // use the Math.random() methos to generate a random int [0, 256);
            r = Math.round((float) Math.random() * 255);
            g = Math.round((float) Math.random() * 255);
            b = Math.round((float) Math.random() * 255);
            //add CompareColor object to ArrayList
            myColors.add(new CompareColor(r, g, b));
            fixedColors.add(new CompareColor(r, g, b));
        }

        Collections.sort(fixedColors);
    }

    public void changeSize(int c) {
      csize += c;
      if(csize<0)csize=0;
      w=dots * (csize * 4) + 15;
      h=csize * 8;
        this.setSize(w,h );
       this.repaint();
    }

    public int getDefaultWidth() {
        return w;
    }

    public int getDefaultHeight() {
        return h;
    }

    public void paint(Graphics g) {
        super.paint(g);
        Graphics2D g2 = (Graphics2D) g;
        this.setSize(dots * (csize * 4) + 15, csize * 8);
        for (int i = 0; i < 10; i++) {
            g2.setColor(myColors.get(i));
            g2.fillOval(csize + (i * csize * 4), csize, csize * 2, csize * 2);
            g2.drawString(myColors.get(i).getBlue() + " ", csize + (i * csize * 4) + csize, csize);
        }
        for (int i = 0; i < 10; i++) {
            g2.setColor(fixedColors.get(i));
            g2.fillOval(csize + (i * csize * 4), csize * 4 + 10, csize * 2, csize * 2);
            g2.drawString(fixedColors.get(i).getBlue() + " ", csize + (i * csize * 4) + csize, csize * 4 + 10);
        }
    }

and here is the html

<HTML>
<HEAD>
   <TITLE>Sort Colors</TITLE>
</HEAD>
<BODY >

<APPLET codebase="classes" code="sortcolors/SortColorsTest.class" width=415 height=80  mayscript="true" name="appl"></APPLET><br />
<input type="button" onClick="cs(1)" value="+"> <input type="button" onClick="cs(-1)" value="-">
</P>
</BODY>
</HTML>
<script type="text/javascript">
function fixWidth(){
document.appl.width=document.appl.getDefaultWidth();
document.appl.height=document.appl.getDefaultHeight();
}
function cs(x){
document.appl.changeSize(x);
fixWidth();
}
</script>

ive tried repainting it at different places but nothing seems to work. It doesnt always happen, only sometimes when resizing.
Attached the build
Thanks
M

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.