Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Designing RLC Circuit using Java Applet

  1. #1
    Junior Member
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Designing RLC Circuit using Java Applet

    The applet i am creating is a RLC circuit that have adjustable inputs with a graph as the output. When i am compiling the code i get the following errors: "cannot find symbol - class metrix" and "cannot find symbol - class curseurv." I am using BlueJ to write my code...i used some code i found online to construct the applet. Here is the link to what it is "suppose to look like:" Bouchon

    Here is my code, I hope someone can help...THANKS!

    import java.applet.Applet; 
    import java.awt.*;   
    public class rlc extends Applet 
    {     
     String format(double r, int n, int d)     
    {         
    d++;      
    String s = Double.toString(r);      
    if((s.indexOf(".") != -1) & (s.length() > d + 2))            
    s = s.substring(0, s.indexOf(".") + d);       
    else      
    if(s.length() > n)           
    s = s.substring(0, n);      
    return s;     
    }     
    void cadre3D(int x, int y, int f, int h)    
     {       
    Color blanc = new Color(230, 230, 230);        
    Color gris = new Color(130, 130, 130);         
    g.setColor(gris);      
    g.drawLine(x, y, f, y);    
    g.drawLine(x, y + 1, f - 1, y + 1);         
    g.drawLine(x, y, x, h);         
    g.drawLine(x + 1, y, x + 1, h - 1);         
    g.setColor(blanc);         
    g.drawLine(x, h, f, h);        
    g.drawLine(f, y + 1, f, h);        
    g.drawLine(x + 1, h - 1, f, h - 1);        
    g.drawLine(f - 1, y + 2, f - 1, h);     
    }      
    void separe(int y)     
    {         
    g.setColor(Color.white);         
    g.drawLine(1, y + 1, 580, y + 1);         g.setColor(Color.gray);         
    g.drawLine(1, y, 580, y);    
    }      
    public void paint(Graphics h)     
    {         
    double yi = 0.0D;         
    double t = 0.0D;         
    double t1 = 0.0D;         
    double phi = 0.0D;         
    double A = 1.0D;         
    double ui = 0.0D;         
    int k = 1;         
    g.setColor(Color.lightGray);         
    g.fillRect(0, 0, size().width, size().height);         separe(34);         
    schema();         
    generateur();         
    scope();         
    double w = 6.2831853071795862D * f;        
    double T = 1.0D / (2D * f);        
    double pas = tmax / 200D;         
    double ec = 10D / tmax;        
    if(mode == 1)         
    {             
    double a = R - L * R * C * w * w;             
    double b = r * R * C * w;             
    n = new comp(a, b);             
    a += r;             
    b += L * w;             
    d = new comp(a, b);         
    } else         
    {             
    double a = 0.0D;             
    double b = R * C * w;             
    n = new comp(a, b);             
    a = 1.0D - L * C * w * w;             
    b = (R + r) * C * w;             
    d = new comp(a, b);         
    }         
    H = comp.quotient(n, d);         
    A = comp.norme(H);         
    phi = comp.phase(H);         
    g.setColor(Color.green);         
    double zi = A * (E * Math.sin(phi)) * G[indez];         
    if(zi > 5D)             
    zi = 5D;         
    if(zi < -5D)             
    zi = -5D;         
    while(t < tmax)          
    {             
    t += pas;             
    double yf = E * Math.sin(w * t) * G[indey];             
    if(yf > 5D)                 
    yf = 5D;             
    if(yf < -5D)                 
    yf = -5D;             
    double zf = A * (E * Math.sin(w * t + phi)) * G[indez];             if(zf > 5D)                 
    zf = 5D;             
    if(zf < -5D)                 
    zf = -5D;             
    droite(ec * (t - pas), yi, ec * t, yf);             
    droite(ec * (t - pas), zi, ec * t, zf);             
    yi = yf;            
    zi = zf;         
    }         
    g.setColor(Color.black);         
    g.drawRect(260, 50, 290, 290);         
    h.drawImage(imag, 0, 0, Color.white, this);         showStatus("Vishal Patel 5-2009");     
    }      
    public boolean mouseUp(Event evt, int x, int y)     
    {         
    if(actifa && y >= curV.inf && y <= curV.sup)         
    {             
    curV.ybou = y;             
    actifa = false;             
    repaint();         
    }         
    if(actifb && y >= curF.inf && y <= curF.sup)         
    {             
    curF.ybou = y;             
    actifb = false;             
    repaint();         
    }         
    if(!f1)         
    {             
    f1 = true;             
    repaint();         
    }         
    if(!f2)         
    {             
    f2 = true;             
    repaint();         
    }         
    if(!f3)         
    {             
    f3 = true;             
    repaint();         
    }         
    if(!f4)         
    {             
    f4 = true;             
    repaint();         
    }         
    return true;     
    }      
    public void destroy()     
    {         
    imag.flush();     
    }      
    void droite(double xi, double yi, double xf, double yf)     
    {         
    xei = 260 + (int)((288D * xi) / 10D);         
    yei = 50 + (int)((290D * (5D - yi)) / 10D);         
    xef = 260 + (int)((288D * xf) / 10D);         
    yef = 50 + (int)((290D * (5D - yf)) / 10D);         
    g.drawLine(xei, yei, xef, yef);     
    }      
    public void update(Graphics h)     
    {         
    paint(h);     
    }      
    void schema()     
    {         
    int X[] = new int[45];         
    int Y[] = new int[45];         
    if(mode == 1)         
    {             
    int i = 0;             
    do             
    {                 
    X[i] = Xl[i] + 50;                 
    Y[i] = Yl[i] + 60;             
    } while(++i < 41);             
    g.setColor(Color.black);             
    g.drawPolygon(Y, X, 41);             g.setColor(Color.lightGray);             
    g.drawLine(60, 66, 118, 66);             g.setColor(Color.black);             
    g.drawLine(25, 160, 210, 160);             
    g.drawLine(60, 65, 60, 105);             
    g.drawLine(118, 65, 118, 105);             
    g.drawLine(60, 105, 118, 105);             
    g.fillRect(82, 90, 16, 30);             
    g.drawLine(25, 80, 60, 80);             
    g.drawLine(118, 80, 210, 80);             
    g.drawLine(170, 80, 170, 160);             
    g.drawString("R = 1 k" + s1, 190, 125);             g.setColor(Color.lightGray);             
    g.fillRect(87, 90, 6, 30);             g.setColor(Color.yellow);             
    g.fillRect(160, 95, 20, 50);             g.setColor(Color.black);             
    g.drawRect(160, 95, 20, 50);             
    g.drawString("r = " + format(r, 4, 1) + " " + s1, 130, 55);         
    } else         
    {             
    int i = 0;             
    do             
    {                 
    X[i] = Xl[i] + 50;                 
    Y[i] = Yl[i] + 40;            
    } while(++i < 41);             
    g.setColor(Color.black);             
    g.drawPolygon(Y, X, 41);             g.setColor(Color.lightGray);             
    g.drawLine(40, 66, 98, 66);             g.setColor(Color.black);             
    g.drawLine(25, 160, 210, 160);             
    g.drawLine(25, 65, 40, 65);             
    g.drawLine(98, 65, 215, 65);             
    g.fillRect(110, 50, 16, 30);             
    g.drawLine(160, 65, 160, 160);             g.setColor(Color.lightGray);             
    g.fillRect(115, 50, 6, 30);             g.setColor(Color.yellow);             
    g.fillRect(150, 90, 20, 50);             g.setColor(Color.black);             
    g.drawRect(150, 90, 20, 50);             
    g.drawString("R = 1 k" + s1, 180, 115);             
    g.drawString("r = " + format(r, 4, 1) + " " + s1, 35, 100);         }     
    }      
    void generateur()     
    {         
    curV.dessine();         
    curF.dessine();         
    E = curV.val;         
    f = curF.val;         
    bal = (int)Math.round(2D * f) - 1;         
    f = Math.pow(10D, f);         
    double fre;         
    if(f > 10000D)         
    {             
    fre = f / 1000D;             
    freq.lab = "kHz";         
    } else         
    {             
    fre = f;             
    freq.lab = "Hz";         
    }         
    volt1.draw(E);         
    freq.draw(fre);         
    cadre3D(20, 180, 230, 390);     
    }      
    public boolean action(Event event, Object obj)     
    {         
    if(event.target == chx1)         
    {             
    L = Li[chx1.getSelectedIndex()];            
    r = ri[chx1.getSelectedIndex()];         
    } else         
    if(event.target == chx2)             
    C = Ci[chx2.getSelectedIndex()];         
    else         
    if(event.target == cb1)             
    mode = 1;         
    else         
    if(event.target == cb2)             
    mode = 2;         else             
    return super.action(event, obj);         
    repaint();         
    return true;     
    }      
    void scope()     
    {        
     g.setFont(font);         
    g.setColor(vert);         
    g.fillRect(260, 50, 290, 290);         g.setColor(Color.lightGray);         
    droite(0.0D, 0.0D, 10D, 0.0D);         
    int i = 0;         
    do             
    droite(i, -0.20000000000000001D,  i,0.20000000000000001D);         
    while(++i < 10);         
    droite(5D, -5D, 5D, 5D);         
    i = -5;         
    do             
    droite(4.9000000000000004D, i, 5.0999999999999996D, i);         while(++i < 6);         
    g.setColor(Color.gray);         
    g.fill3DRect(370, 350, 15, 15, f1);         
    g.fill3DRect(370, 370, 15, 15, f2);         
    g.fill3DRect(260, 350, 15, 15, f3);         
    g.fill3DRect(260, 370, 15, 15, f4);         g.setColor(Color.white);         
    if(f1)             
    g.drawString("+", 374, 362);         
    else             
    g.drawString("+", 373, 361);         
    if(f2)            
    g.drawString("-", 374, 382);         
    else             
    g.drawString("-", 373, 381);         
    if(f3)             
    g.drawString("+", 264, 362);         
    else             
    g.drawString("+", 263, 361);         
    if(f4)             
    g.drawString("-", 264, 382);         
    else             
    g.drawString("-", 263, 381);         
    g.setColor(Color.blue);         
    g.drawString("Gain Out", 390, 360);         
    g.drawString("Gain Inp", 280, 360);         
    g.drawString(sg[indez] + " V/cm", 390, 380);         g.drawString(sg[indey] + " V/cm", 280, 380);         switch(bal)         
    {         
    case 2: // '\002'         
    case 3: // '\003'             
    tmax = 0.050000000000000003D;             
    s = "5 ms/cm";             
    break;          
    case 4: // '\004'             
    tmax = 0.01D;             
    s = "1 ms/cm";             
    break;          
    case 5: // '\005'             
    tmax = 0.0050000000000000001D;             
    s = "0.5 ms/cm";             
    break;          
    case 6: // '\006'             
    tmax = 0.001D;             
    s = "100 \265s/cm";             
    break;          
    case 7: // '\007'             
    tmax = 0.00050000000000000001D;             
    s = "50 \265s/cm";             
    break;          
    case 8: // '\b'             
    tmax = 0.0001D;             
    s = "10 \265s/cm";             
    break;          
    case 9: // '\t'             
    tmax = 5.0000000000000002E-005D;             
    s = "5 \265s/cm";             
    break;          
    case 10: // '\n'             
    tmax = 1.0000000000000001E-005D;             
    s = "1 \265s/cm";             
    break;          
    case 11: // '\013'             
    tmax = 5.0000000000000004E-006D;             
    s = "0.5 \265s/cm";             
    break;         
    }         
    g.drawString("Time Division :", 470, 360);         
    g.drawString(s, 470, 380);         
    g.setColor(Color.black);         
    g.drawRect(260, 50, 290, 290);     
    }      
    public boolean mouseDown(Event evt, int x, int y)     
    {         
    Rectangle test = new Rectangle(curV.X[2], curV.Y[0], 18, 6);         
    if(test.inside(x, y))         
    {             
    actifa = true;             
    actifb = false;         
    }         
    test = new Rectangle(curF.X[2], curF.Y[0], 18, 6);         if(test.inside(x, y))         
    {             
    actifb = true;             
    actifa = false;         
    }         
    if(r1.inside(x, y))         
    {             
    f1 = false;             
    actifb = false;             
    actifa = false;             
    indez++;             
    if(indez > 6)                 
    indez = 6;         
    }         
    if(r2.inside(x, y))         
    {             
    f2 = false;             
    actifb = false;             
    actifa = false;             
    indez--;             
    if(indez < 0)                 
    indez = 0;         
    }         
    if(r3.inside(x, y))         
    {             
    f3 = false;             
    actifb = false;             
    actifa = false;             
    indey++;             
    if(indey > 8)                 
    indey = 8;        
     }         
    if(r4.inside(x, y))         
    {             
    f4 = false;             
    actifb = false;             
    actifa = false;             
    indey--;             
    if(indey < 0)                 
    indey = 0;         
    }         
    repaint();         
    return true;     
    }      
    public void init()     
    {         
    setFont(font);         
    imag = createImage(size().width, size().height);         
    g = imag.getGraphics();         setBackground(Color.lightGray);         
    setLayout(fl);         
    add(cb1);         
    add(cb2);         
    chx1.addItem("100 mH");         
    chx1.addItem("1 H");         
    chx1.addItem("10 mH");         
    chx1.addItem("1 mH");         
    chx2.addItem("10 nF");         
    chx2.addItem("1 nF");         
    chx2.addItem("100 nF");         
    chx2.addItem("1 \265F");         
    add(lb1);         
    add(chx1);         
    add(lb2);         
    add(chx2);         
    volt1 = new metrix(g, 35, 190, 5, "V", Color.green, 5D, 0.0D);         
    freq = new metrix(g, 135, 190, 5, "Hz", Color.red, 0.0D);         curV = new curseurv(g, 70, 230, 370, 0.0D, 5D, 2.5D, Color.green);         
    curF = new curseurv(g, 170, 230, 370, 1.6499999999999999D, 5.8499999999999996D, 3D, Color.red);         
    Xo[0] = 150;         
    Xo[1] = 210;         
    Xo[2] = Xo[0];         
    Yo[0] = 125;         
    Yo[1] = 155;         
    Yo[2] = 185;     
    }      
    public boolean mouseDrag(Event evt, int x, int y)     
    {         
    if(actifa && y >= curV.inf && y <= curV.sup)         
    {             
    curV.ybou = y;             
    repaint();         
    }         
    if(actifb && y >= curF.inf && y <= curF.sup)         
    {             
    curF.ybou = y;             
    repaint();         
    }         
    return true;     
    }      
    public rlc()     
    {         
    fl = new FlowLayout(1, 10, 3);         
    chx1 = new Choice();         
    chx2 = new Choice();         
    lb1 = new Label("L=", 2);         
    lb2 = new Label("C=", 2);         
    bg1 = new CheckboxGroup();         
    cb1 = new Checkbox("Parallel Circuit", bg1, true);         
    cb2 = new Checkbox("Series Circuit", bg1, false);         
    r1 = new Rectangle(370, 350, 15, 15);         
    r2 = new Rectangle(370, 370, 15, 15);         
    r3 = new Rectangle(260, 350, 15, 15);         
    r4 = new Rectangle(260, 370, 15, 15);         
    vert = new Color(0, 128, 0);         
    fontp = new Font("TimesRoman", 0, 11);         
    font = new Font("Courier", 0, 11);         
    s1 = "" + '\u03A9';         
    f1 = true;         
    f2 = true;         
    f3 = true;         
    f4 = true;         
    L = 0.10000000000000001D;         
    r = 10D;         
    C = 1E-008D;         
    R = 1000D;         
    Xo = new int[5];         
    Yo = new int[5];         
    mode = 1;         
    indez = 3;         
    indey = 3;     
    }      
    FlowLayout fl;     
    Choice chx1;     
    Choice chx2;     
    Label lb1;     
    Label lb2;     
    CheckboxGroup bg1;     
    Checkbox cb1;     
    Checkbox cb2;     
    Rectangle r1;     
    Rectangle r2;     
    Rectangle r3;     
    Rectangle r4;     
    metrix volt1;     
    metrix freq;     
    curseurv curV;     
    curseurv curF;     
    Color vert;     
    Image imag;     
    Graphics g;     
    Font fontp;     
    Font font;     
    String s;     
    String s1;     
    boolean actifa;     
    boolean actifb;     
    boolean f1;     
    boolean f2;     
    boolean f3;     
    boolean f4;     
    final double PI = 3.1415926535897931D;     
    double L;     
    double Li[] = {         
    0.10000000000000001D, 1.0D, 0.01D, 0.001D     
    };     
    double r;     
    double ri[] = {         
    10D, 80D, 3D, 0.5D     
    };     
    double C;     
    double Ci[] = {         
    1E-008D, 1.0000000000000001E-009D, 9.9999999999999995E-008D, 9.9999999999999995E-007D     };     
    double E;     
    double v;     
    double vs;     
    double f;     
    double tmax;     
    double R;     
    double G[] = {         
    0.10000000000000001D, 0.20000000000000001D, 0.5D, 1.0D, 2D, 5D, 10D, 20D, 50D     
    };     
    String sg[] = {         
    "10", "5.0", "2.0", "1.0", "0.5", "0.2", "0.1", "0.05", "0.02"     
    };     
    int Yl[] = {         
    0, 1, 4, 7, 12, 15, 19, 20, 19, 16,          
    12, 12, 13, 15, 19, 24, 28, 31, 33, 32,          
    29, 25, 25, 26, 28, 33, 37, 41, 44, 45,          
    44, 41, 38, 37, 38, 41, 45, 49, 53, 56,          
    58     
    };     
    int Xl[] = {         
    16, 10, 4, 0, 0, 4, 10, 16, 22, 29,          
    22, 16, 10, 4, 0, 0, 4, 10, 16, 22,          
    29, 22, 16, 10, 4, 0, 0, 4, 10, 16,          
    22, 29, 22, 16, 10, 4, 0, 0, 4, 8,          
    16     
    };     
    int Xo[];     
    int Yo[];     
    int xei;     
    int yei;     
    int xef;     
    int yef;     
    int mode;     
    int indez;     
    int indey;     
    int bal;     
    int forme;     
    comp H;     
    comp n;     
    comp d;     
    int Xs;     
    int Ys;     
    FontMetrics fm; 
    }


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: RLC Circuit Java Applet

    Hello syxxpac316, welcome to the Java Programming Forums

    I have attempted to compile this code and I cannot compile it.

    The reason it will not compile is because you are missing 2 classes, metrix & curseur.

    You cannot move forward without them...
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  3. #3
    Junior Member
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: RLC Circuit Java Applet

    First of all wanted to say thanks for the help...i kind of figured that was it...i was trying to use the source from an online applet and just modify it, but when i compiled i got those errors. Is there anyway you can help...i believe i decompiled the source from the first link in my original post...if anyone can help it would be great. I need an applet similar to the links above.

    Thank You!

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: RLC Circuit Java Applet

    There is no way I can help with the above applet without those other class files. It's impossible for me to guess what these classed contained.

    Where did you get this applet from?

    Do you have a Java .class decompiler? You could downloaded the class file from the Bouchon link you supplied above. See if you can decompile it.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  5. #5
    Junior Member
    Join Date
    May 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: RLC Circuit Java Applet

    Hi syxxpac316.

    You can't compile without the classes that's missing. Its better to search again in the net from where you got this code for the missing class.
    All the best.

  6. #6
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: RLC Circuit Java Applet

    I decompiled bouchon.class from that website you gave us. It's a different class to the one you posted but still has very similar problems.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  7. #7
    Junior Member
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: RLC Circuit Java Applet

    thats exactly where i got the .class file from...its the first time i have ever decompiled a class...can i get the other classes from the site with bouchon.class? Or do i use the decompiler to obtain that?...i was trying to use that applet and modify it but could not get it work because of the missing classes.

Similar Threads

  1. servlet applet communication
    By prashanthi_asn in forum Java Servlet
    Replies: 0
    Last Post: May 21st, 2009, 01:50 AM
  2. Add Jmol applet dynimically in JSF(java server faces)
    By megha in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: May 15th, 2009, 07:16 AM
  3. Replies: 1
    Last Post: March 11th, 2009, 05:41 PM
  4. Problem of implementing mathematic logic in Java applet
    By AnithaBabu1 in forum Java Applets
    Replies: 0
    Last Post: August 16th, 2008, 12:42 AM