FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

java applet refresh problem

 


tekanubis
I made a java applet using java2d that graphs points out of the params onto the applet. It's nothing special, but when you scroll it trails and anything that goes in front the the applet will stay there. It will repaint, however the old things on the applet will stay there and it will repaint over them. I figure this is a pretty common problem, but I can't find an answer.


This is what I want

This is what happens
frih
just check your code. put the repaint() tag in some function.or must be some problem in your code. send me the code. i wil check it






regards
abhi Laughing
tekanubis
hey, thanks for the quick reply, sorry I didn't get back to you sooner. I was on a business trip last week. That's the init() and paint() methods. I have other methods, but they're only for date conversions and calculations. I tried throwing in the repaint() call, but it doesn't do anything. I've also tried setting the background color to various things, and that also doesn't seem to work.
Code:

public class HelloWorld extends JApplet
   {
       public int sYear;
       public int eYear;
       public String sMonth;
       public String eMonth;
       public int sDay;
       public int eDay;
       
       public void init()
       {
          setBackground(Color.white);
       }
       
       //
       public void paint(Graphics g)
      {
          Graphics2D g2 = (Graphics2D) g;
       
          Dimension d = getSize();
           
          String volume = getParameter("Volume");
           String time_key = getParameter("time_key");
           
           this.sDay = Integer.parseInt(getParameter("sDay"));
           this.eDay = Integer.parseInt(getParameter("eDay"));
           this.sYear = Integer.parseInt(getParameter("sYear"));
           this.eYear = Integer.parseInt(getParameter("eYear"));
           this.sMonth = getParameter("sMonth");
           this.eMonth = getParameter("eMonth");
           
           short[] thing = dataParser(volume, 1);
          
           Calendar start = Calendar.getInstance();
           Calendar end = Calendar.getInstance();
           
           start.set(sYear, monthToNum(sMonth), sDay);
           end.set(eYear, monthToNum(eMonth), eDay);
     
          // int difference = calculateDifference(start,end);           
                     
                     
           g2.setPaint(Color.LIGHT_GRAY);
           g2.draw3DRect(0, 0, d.width - 1, d.height - 1, true);
           g2.draw3DRect(3, 3, d.width - 7, d.height - 7, false);
           g2.setPaint(Color.BLACK);
           
           final int GRID_WIDTH = d.width-7;
           final int GRID_HEIGHT = 20;
           final int ORIGIN_X = 50;
           final int ORIGIN_Y = d.height-40;
           
           //x-axis
           g2.draw(new Line2D.Double(ORIGIN_X-2, ORIGIN_Y+3, GRID_WIDTH, ORIGIN_Y+2));
           //y-axis
           g2.draw(new Line2D.Double(ORIGIN_X-2, ORIGIN_Y+3, ORIGIN_X-2, GRID_HEIGHT));
           
           g2.setPaint(Color.ORANGE);
           
           int pixelSetter=ORIGIN_X;
           
           for (int ii=0; ii<96; ii++)
           {
              if(thing[ii] != -1)
                 g.drawOval(pixelSetter, ORIGIN_Y - thing[ii], 3, 3);
            
              pixelSetter+=8;
           }
           g2.setPaint(Color.BLACK);
                  
           AffineTransform at = new AffineTransform();
           
           AffineTransform fontAT = new AffineTransform();
           at.setToTranslation(0, 0);
           fontAT.rotate(-Math.PI/2);

           FontRenderContext frc = g2.getFontRenderContext();
           Font theFont = new Font("Times", Font.BOLD, 10);
           Font theDerivedFont = theFont.deriveFont(fontAT);
           
           
           
           StringTokenizer st = new StringTokenizer(time_key, ",");

          pixelSetter=0;
           for (int ii=0; ii<48 && st.hasMoreTokens(); ii++)
           {
              TextLayout tstring2 = new TextLayout(st.nextToken(), theDerivedFont, frc);
               g2.transform(at);
               tstring2.draw(g2, ORIGIN_X + 4+ (ii*16), ORIGIN_Y+28);
           }
       }
tekanubis
Sorry, just figured it out. Apparently JApplet and Applet are more different than I thought. Once I changed to extends from Applet the background painted correctly and the repaint worked fine because of that.
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.