Forum Stats

  • 3,855,178 Users
  • 2,264,465 Discussions
  • 7,905,912 Comments

Discussions

Applet refresh with MS-VM in IE fails

843807
843807 Member Posts: 46,582
edited Nov 3, 2002 2:59PM in Java Applet Development
Hi,

sorry, but I'm a real NEWBIE in java...

My problem is:
I use a simple freeware barchart applet on our website
and when first opened it works fine with IE5.5 or 6 (Microsoft VM!).
After a reload just a small part of the applet will
be rebuilt. No error is printed out in the Java Debug Console. With the jre 1.4 used in the IE theres no
problem!

Has anybody an idea how to make my applet "compatible" with the MS-VM??

Thanks in advance,

Dirk

Comments

  • 843807
    843807 Member Posts: 46,582
    Get the source code and show us!
  • 843807
    843807 Member Posts: 46,582
    Hi,

    thanks for your answer!
    Here's the code of the bar chart applet.

    I've also written a little html-testpage and SURPRISE, after running the html-File locally the Applet works in IE (with MS VM) after Refresh!

    No, I'm really confused :-(

    Any idea?

    Dirk

    the java-source:
    *********************************************************************************************************

    import java.applet.Applet;
    import java.applet.AppletContext;
    import java.awt.*;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.net.MalformedURLException;
    import java.net.URL;

    public class BarChartDK extends Applet
    implements MouseListener {
    private int i;
    private int AnzSaeulen;
    private int Breite;
    private int Hoehe;
    private int Hoehe_diagramm;
    private int Breite_diagramm;
    private int AktKomPos1;
    private int AktKomPos2;
    private int j;
    private int KomPos1;
    private int KomPos2;
    private int P_Rand;
    private int P_Breite;
    private int P_Hoehe;
    private int P_X;
    private int P_Y;
    private int AbsS�ulenBreite;
    private int Max_Farbe;
    private int y_VersatzBeschr;
    private int MaxWert;
    private int AktWert;
    private int MaxSaeulenHoehe;
    private int AktFarbIndex;
    private int Bod1x;
    private int Bod2x;
    private int Bod3x;
    private int Bod4x;
    private int Bod5x;
    private int Bod6x;
    private int Bod7x;
    private int Bod1y;
    private int Bod2y;
    private int Bod3y;
    private int Bod4y;
    private int Bod5y;
    private int Bod6y;
    private int Bod7y;
    private Color SaeulenFarbe;
    private Color Akt_Farbe;
    private Color Farbe[];
    private Color HGFarbe[];
    private Color BeschrFarbe;
    private int Rand[];
    //private int Horny[];
    private String Numbers;
    private String Legend;
    private String myLink;
    private String AktWertStr1;
    private String AktWertStr2;
    private URL myURL;
    private boolean BeschrJN;
    private boolean Mouse;

    public void start() {
    Farbe = new Color[13];
    Farbe[1] = str2col("CCFFFF");
    Farbe[2] = str2col("66FFFF");
    Farbe[3] = str2col("00FFFF");
    Farbe[4] = str2col("CCFF00");
    Farbe[5] = str2col("66FF00");
    Farbe[6] = str2col("00FF00");
    Farbe[7] = str2col("CCFFCC");
    Farbe[8] = str2col("FFFF66");
    Farbe[9] = str2col("FFFF00");
    Farbe[10] = str2col("FFCC00");
    Farbe[11] = str2col("FF6600");
    Farbe[12] = str2col("FF0000");
    HGFarbe = new Color[4];
    HGFarbe[1] = Color.white;
    HGFarbe[2] = Color.gray;
    HGFarbe[3] = Color.black;
    Max_Farbe = DF("BGCOLOR", HGFarbe);
    Max_Farbe = 12;
    Max_Farbe = DF("COLOR", Farbe);
    Mouse = false;
    myLink = getParameter("LINK");
    if(myLink != null) {
    Mouse = true;
    }
    BeschrJN = true;
    Legend = getParameter("HIDENUMBERS");
    if(Legend != null) {
    BeschrJN = false;
    }
    Breite = getSize().width;
    Hoehe = getSize().height;
    Hoehe_diagramm = Hoehe - 50;
    Numbers = getParameter("NUMBERS");
    Legend = getParameter("LEGEND");
    if(Legend == null) {
    Legend = Numbers;
    }
    AnzSaeulen = 0;
    MaxWert = 0;
    AktKomPos1 = 0;
    if(Numbers != null) {
    do
    {
    KomPos1 = Numbers.indexOf(",", AktKomPos1);
    if(KomPos1 < 0) {
    break;
    }
    AnzSaeulen = AnzSaeulen + 1;
    AktWertStr1 = Numbers.substring(AktKomPos1, KomPos1);
    try {
    AktWert = Integer.parseInt(AktWertStr1);
    }
    catch(NumberFormatException numberformatexception) {
    AktWert = 0;
    }
    if(AktWert > MaxWert) {
    MaxWert = AktWert;
    }
    AktKomPos1 = KomPos1 + 1;
    }
    while(KomPos1 > 0); {
    Rand = new int[AnzSaeulen + 1];
    }
    //Horny = new int[AnzSaeulen + 1];
    }
    }

    private Color str2col(String s)
    {
    int k = Integer.decode("0x" + s.substring(0, 2)).intValue();
    int l = Integer.decode("0x" + s.substring(2, 4)).intValue();
    int i1 = Integer.decode("0x" + s.substring(4, 6)).intValue();
    return new Color(k, l, i1);
    }

    private int DF(String s, Color acolor[])
    {
    Numbers = getParameter(s);
    if(Numbers != null)
    {
    AktKomPos1 = 0;
    Max_Farbe = 0;
    do
    {
    KomPos1 = Numbers.indexOf(",", AktKomPos1);
    if(KomPos1 < 0) {
    break;
    }
    Max_Farbe = Max_Farbe + 1;
    if(Max_Farbe == acolor.length) {
    break;
    }
    AktWertStr1 = Numbers.substring(AktKomPos1, KomPos1 + 1);
    acolor[Max_Farbe] = str2col(AktWertStr1);
    AktKomPos1 = KomPos1 + 1;
    }
    while(KomPos1 > 0);
    }
    return Max_Farbe;
    }


    public void mousePressed(MouseEvent mouseevent)
    {
    }

    public void mouseReleased(MouseEvent mouseevent)
    {
    }

    public void mouseEntered(MouseEvent mouseevent)
    {
    }

    public void mouseExited(MouseEvent mouseevent)
    {
    }

    public void mouseClicked(MouseEvent mouseevent)
    {
    int i1 = mouseevent.getX();
    int j1 = mouseevent.getY();
    if(Mouse)
    {
    int l = 0;
    for(int k = 1; k <= AnzSaeulen; k++)
    if(i1 >= Rand[k] && i1 <= Rand[k] + AbsS�ulenBreite && Mouse){
    l = k;
    }
    if(l > 0){
    NewURL(FrontFarbe(l));
    }
    stop();
    start();
    }
    }

    public String FrontFarbe(int SaeulenNr)
    {
    int index1=0;
    int index2;
    String AktuellFarbe = "";
    for(i=1;i<=SaeulenNr;i++) {
    index2=Legend.indexOf(",",index1);
    AktuellFarbe=Legend.substring(index1,index2);
    index1=index2+1;
    }
    return AktuellFarbe;
    }



    public void NewURL(String k)
    {
    boolean flag = true;
    int l = myLink.indexOf("*");
    int i1 = myLink.length();
    if(l > -1){
    myLink = myLink.substring(0, l) + k + myLink.substring(l + 1, i1);
    }
    try {
    myURL = new URL(getDocumentBase(), myLink);
    }
    catch(MalformedURLException malformedurlexception) {
    showStatus("Malformed URL : " + malformedurlexception);
    flag = false;
    }
    if(flag) {
    getAppletContext().showDocument(myURL, "_self");
    }
    }


    public void paint(Graphics g)
    {
    setBackground(HGFarbe[1]);
    P_Rand = 50;
    Breite_diagramm = Breite - P_Rand - 20;
    AbsS�ulenBreite = Breite_diagramm / AnzSaeulen;
    MaxSaeulenHoehe = Hoehe_diagramm - 20;
    y_VersatzBeschr = 1;
    P_Breite = AbsS�ulenBreite - 10;
    P_Hoehe = 100;
    P_X = 10;
    P_Y = 10;
    if(P_Breite < P_X) {
    P_X = P_Breite;
    P_Y = P_Breite;
    }
    g.setColor(HGFarbe[2]);
    for(i = 1; i < Hoehe_diagramm / 20; i++) {
    g.drawLine(40, i * 20, Breite_diagramm + 40, i * 20);
    g.drawLine(40, i * 20, 40 - P_X * 3, i * 20 + P_Y * 3);
    }
    AktFarbIndex = 1;
    AktKomPos1 = 0;
    AktKomPos2 = 0;
    for(i = 1; i <= AnzSaeulen; i++) {
    KomPos1 = Numbers.indexOf(",", AktKomPos1);
    AktWertStr1 = Numbers.substring(AktKomPos1, KomPos1);
    try {
    P_Hoehe = Integer.parseInt(AktWertStr1, 10);
    }
    catch(NumberFormatException numberformatexception) {
    P_Hoehe = 0;
    }
    AktKomPos1 = KomPos1 + 1;
    P_Hoehe = (P_Hoehe * MaxSaeulenHoehe) / MaxWert;
    KomPos2 = Legend.indexOf(",", AktKomPos2);
    AktWertStr2 = Legend.substring(AktKomPos2, KomPos2);
    AktKomPos2 = KomPos2 + 1;
    SaeulenFarbe = Farbe[AktFarbIndex];
    g.setColor(SaeulenFarbe);
    Bod2x = P_Rand;
    Bod2y = Hoehe_diagramm - P_Hoehe;
    Bod3x = Bod2x + P_X;
    Bod3y = Bod2y - P_Y;
    Bod4x = Bod3x + P_Breite;
    Bod4y = Bod3y;
    Bod5x = Bod2x + P_Breite;
    Bod5y = Bod2y;
    Bod6x = Bod5x;
    Bod6y = Hoehe_diagramm;
    Bod7x = Bod4x;
    Bod7y = Hoehe_diagramm - P_Y;
    Rand[i] = P_Rand;
    //Horny[i] = Bod2y + P_Hoehe;
    g.fillRect(Bod2x, Bod2y, P_Breite, P_Hoehe);
    for(j = Bod2x; j <= Bod5x; j = j + 2){
    g.drawLine(j, Bod2y, j + P_X, Bod3y);
    }
    g.setColor(SaeulenFarbe);
    Akt_Farbe = SaeulenFarbe.darker();
    g.setColor(Akt_Farbe);
    for(j = Bod5y; j < Bod6y; j++){
    g.drawLine(Bod5x, j, Bod4x, j - P_Y);
    }
    g.drawLine(Bod7x, Bod7y, Bod6x, Bod6y);
    Akt_Farbe = SaeulenFarbe.darker();
    //g.setColor(Akt_Farbe);
    g.setColor(HGFarbe[3]);
    if(BeschrJN) {
    g.drawString(AktWertStr1, Bod2x+20, Bod2y - 10);
    }
    g.drawString(AktWertStr2, Bod2x+15, Hoehe_diagramm + 10 + 10 * y_VersatzBeschr);
    P_Rand = P_Rand + AbsS�ulenBreite;
    AktFarbIndex = AktFarbIndex + 1;
    if(AktFarbIndex > Max_Farbe){
    AktFarbIndex = 1;
    }
    //y_VersatzBeschr = y_VersatzBeschr + 1;
    //if(y_VersatzBeschr > 3) {
    // y_VersatzBeschr = 1;
    //}
    }
    addMouseListener(this);
    }
    }

    and the html testpage:
    *************************************************************************************************************************
    <HTML>
    <HEAD>
    <TITLE>
    BarChartDK - Java applet for bar chart
    </TITLE>
    </HEAD>
    <BODY TEXT="white" BGCOLOR="navy" LINK="#FFFF00" ALINK="#FFFF00" VLINK="#FFFF00">
    <H1>
    HTML-Page for bar chart Demo&nbsp;
    </H1>
    &nbsp;&nbsp;
    <P>
    <CENTER>
    <applet code=BarChartDK.class name=BarChartDK width=700 height=350 VIEWASTEXT>
    <param name=numbers value="26,9,9,8,7,6,5,4,4,3,">
    <param name=legend value="L11,V10,S60,C54,R11,L13,G11,C17,1,D51,">
    <param name=color value="EEEEEE,FFFFCC,">
    <param name=bgcolor value="FFFFFF,FFFFFF,">
    <param name=link value="test.htm?F=*">
    </applet>

    <P>
    <TABLE BORDER=0 CELLSPACING="5">
    <TR><TD>
    param name=numbers value="26,9,9,8,7,6,5,4,4,3,"
    </TD></TR>
    <TR><TD>
    param name=legend value="L11,V10,S60,C54,R11,L13,G11,C17,1,D51,"
    </TD></TR>
    <TR><TD>
    param name=color value="EEEEEE,FFFFCC,"
    </TD></TR>
    <TR><TD>
    param name=bgcolor value="FFFFFF,FFFFFF,"
    </TD></TR>
    <TR><TD>
    param name=link value="test.htm?F=*"
    </TD></TR>
    </TABLE>
    <HR>
    </center>
    </BODY>
    </HTML>
  • 843807
    843807 Member Posts: 46,582
    The bug has nothing to do with your code, it is a bug in the MS VM, and that is it. MS has been known to have bugs in everything, anyway. Sometimes the error will occur, and sometimes it will not. It's just like Windows- sometimes it works and sometimes it doesn't.
  • 843807
    843807 Member Posts: 46,582
    Thanks Woogley,

    could this be true??
    Is there no chance to let my applet work with MS-VM?

    Dirk
  • 843807
    843807 Member Posts: 46,582
    On top of what MSIE could have failed, various bugs are there in the applet. Basically, a public void init() is needed. After I added init() and corrected some of the critical bugs in the code, various other exception errors occured, especially the number of columns AnzSaeulen went zero! I really wonder whether the applet runs on any other VM or the native environment.

    More people can help you if you add some comments to German (I suppose it is) variables.
This discussion has been closed.