Results 1 to 2 of 2
Thread: JOptionPane to JApplet
 05312013, 06:30 AM #1Member
 Join Date
 May 2013
 Posts
 3
 Rep Power
 0
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[counter11] = z[counter11]/c44[n]; JOptionPane.showMessageDialog (null,"Gamma = " +gamma[counter11], "Shear Strain " ,JOptionPane.INFORMATION_MESSAGE); } double r = (c11[n]c12[n])/(2*c44[n]); JOptionPane.showMessageDialog (null,"R = " +r, "Anisotropy Ratio " ,JOptionPane.INFORMATION_MESSAGE); } }
 05312013, 10:26 AM #2
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,394
 Blog Entries
 7
 Rep Power
 25
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,
JosBuild a wall around Donald Trump; I'll pay for it.
Similar Threads

JApplet in AJAX?
By chyrl in forum Advanced JavaReplies: 0Last Post: 09192010, 12:35 AM 
JApplet on MAC
By ld_pvl in forum Java AppletsReplies: 0Last Post: 08232009, 01:40 PM 
JFrame to JApplet or JApplet to JApplet
By ramesh.8189 in forum AWT / SwingReplies: 13Last Post: 02082009, 07:14 AM 
Database to JApplet
By Preethi in forum New To JavaReplies: 0Last Post: 03262008, 06:18 AM 
Another problem in JApplet :S
By juju in forum Java AppletsReplies: 2Last Post: 12302007, 08:46 PM
Bookmarks