Results 1 to 2 of 2
  1. #1
    alphablitzer is offline Member
    Join Date
    May 2013
    Posts
    3
    Rep Power
    0

    Unhappy JOptionPane to JApplet

    I'm having a hard time converting my codes to applet. Can someone help me?
    Java Code:
    package stressstrain;
    import javax.swing.JOptionPane;
    public class Stress {
    
    
    public static void main(String[] args) {
    double c11[],c12[],c44[];
    int n=0;
    Object y = JOptionPane.showInputDialog(null, "Select Material", "Selection",
    JOptionPane.QUESTION_MESSAGE, null, new Object[] { "Tungsten","Silicon","Gold","Aluminum","Copper"},"");
    double x[] = new double[3];
    double z[] = new double [3];
    for (int counter = 1;counter <= 3;counter++){
    String sigma = JOptionPane.showInputDialog("Enter stress");
    x[counter -1] = Double.parseDouble (sigma);
    String tau = JOptionPane.showInputDialog("Enter shear stress");
    z[counter -1] = Double.parseDouble (tau);
    }
    
    if (y == "Tungsten")
    { n =1;
    }
    
    if (y == "Silicon")
    { n =2;
    }
    
    if (y == "Gold")
    {n =3;
    }
    
    if (y == "Aluminum")
    { n =4;
    }
    
    if (y == "Copper")
    { n =5;
    }
    
    c11 = new double[6];
    c12 = new double[6];
    c44 = new double[6];
    
    c11[1]=50.1;
    c11[2]=16.6;
    c11[3]=18.6;
    c11[4]=10.8;
    c11[5]=16.8;
    c12[1]=19.8;
    c12[2]=6.4;
    c12[3]=15.7;
    c12[4]=6.1;
    c12[5]=12.1;
    c44[1]=15.1;
    c44[2]=8.0;
    c44[3]=4.2;
    c44[4]=2.9;
    c44[5]=7.5;
    
    double a = (x[0]*c11[n]*c11[n]+c12[n]*c12[n]*x[2]+c12[n]*c12[n]*x[1]-c12[n]*c11[n]*c12[n]-c12[n]*c12[n]*x[0]-c11[n]*c12[n]*x[1])/(c11[n]*c11[n]*c11[n]+c12[n]*c12[n]*c12[n]+c12[n]*c12[n]*c12[n]-c12[n]*c11[n]*c12[n]-c12[n]*c12[n]*c11[n]-c11[n]*c12[n]*c12[n]);
    
    JOptionPane.showMessageDialog (null,"Epsilon 11 is = " +a, "Strain " ,JOptionPane.INFORMATION_MESSAGE);
    
    double b = (c11[n]*x[1]*c11[n]+x[0]*c12[n]*c12[n]+c12[n]*c12[n]*x[2]-c12[n]*x[1]*c12[n]-x[2]*c12[n]*c11[n]-c11[n]*x[0]*c12[n])/(c11[n]*c11[n]*x[2]+c12[n]*c12[n]*c12[n]+c12[n]*c12[n]*c12[n]-c12[n]*c11[n]*c12[n]-c12[n]*c12[n]*c11[n]-c11[n]*c12[n]*c12[n]);
    
    JOptionPane.showMessageDialog (null,"Epsilon 12 is = " +b, "Strain " ,JOptionPane.INFORMATION_MESSAGE);
    
    double c = (c11[n]*c11[n]*x[2]+c12[n]*x[1]*c12[n]+x[0]*c12[n]*c12[n]-c12[n]*c11[n]*x[0]-c12[n]*x[1]*c11[n]-x[2]*c12[n]*c12[n])/(c11[n]*c11[n]*c11[n]+c12[n]*c12[n]*c12[n]+c12[n]*c12[n]*c12[n]-c12[n]*c11[n]*c12[n]-c12[n]*c12[n]*c11[n]-c11[n]*c12[n]*c12[n]);
    
    
    JOptionPane.showMessageDialog (null,"Epsilon 13 is = " +c, "Strain " ,JOptionPane.INFORMATION_MESSAGE);
    
    double gamma[] = new double[3];
    for (int counter1 = 1;counter1 <=3;counter1++ ){
    gamma[counter1-1] = z[counter1-1]/c44[n];
    JOptionPane.showMessageDialog (null,"Gamma = " +gamma[counter1-1], "Shear Strain " ,JOptionPane.INFORMATION_MESSAGE);
    }
    
    double r = (c11[n]-c12[n])/(2*c44[n]);
    JOptionPane.showMessageDialog (null,"R = " +r, "Anisotropy Ratio " ,JOptionPane.INFORMATION_MESSAGE);
    
    }
    
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,560
    Blog Entries
    7
    Rep Power
    21

    Default Re: JOptionPane to JApplet

    As your (incorrect) code is now, it isn't an applet( applets don't have a main( ... ) method, they have an init() method) and the class must extend from the (J)Applet class; as for the corectness of your code: don't compare two Strings for equality with the == operator, use the equals( ... ) method instead.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. JApplet in AJAX?
    By chyrl in forum Advanced Java
    Replies: 0
    Last Post: 09-19-2010, 12:35 AM
  2. JApplet on MAC
    By ld_pvl in forum Java Applets
    Replies: 0
    Last Post: 08-23-2009, 01:40 PM
  3. JFrame to JApplet or JApplet to JApplet
    By ramesh.8189 in forum AWT / Swing
    Replies: 13
    Last Post: 02-08-2009, 06:14 AM
  4. Database to JApplet
    By Preethi in forum New To Java
    Replies: 0
    Last Post: 03-26-2008, 05:18 AM
  5. Another problem in JApplet :S
    By juju in forum Java Applets
    Replies: 2
    Last Post: 12-30-2007, 07:46 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •