I just am not sure how to take field1 and field2 and make them into int to do the exponent code. I have some of the code commented out as it just wont work with the code I have.
import java.awt.GridLayout;
import java.util.*;
import javax.swing.*;
/*
*Create a public class named Exponent. X
*Inside the main method of this class, obtain a double input using a dialog box.X
*Pass the input value to a non-static method that returns the square value of the parameter.
*Display the return value of the method using an output dialog.
*Next pass the input value to a non-static method that returns the cube of the parameter.
*Display the return value of the method using an output dialog.
*Save the class as Exponent.java.
*/
public class Exponent {
public static void main(String[] args)
{
JTextField field1 = new JTextField("00");
JTextField field2 = new JTextField("00");
JPanel myPanel = new JPanel(new GridLayout());
myPanel.add(new JLabel("Field1:"));
myPanel.add(field1);
myPanel.add(Box.createHorizontalStrut(15)); // a spacer
myPanel.add(new JLabel("Field2:"));
myPanel.add(field2);
int result = JOptionPane.showConfirmDialog(null, myPanel,
"Please Enter X and Y Values", JOptionPane.OK_CANCEL_OPTION);
if (result == JOptionPane.OK_OPTION) {
System.out.println("field 1 is : " + field1.getText());
System.out.println("field 2 is: " + field2.getText());
}
}
public void methodsquare()
{
Exponent E = new Exponent();
int field1;
int field2;
System.out.println(" square of " + field1 + " number is " + E.sqr(field1));
}
public double sqr(int field1)
{
return field1*field1;
}
/* Scanner in = new Scanner(System.in);
Exponent E = new Exponent();
System.out.println(" enter input number");
int k= in.nextInt();
System.out.println(" square of " + k + " number is " + E.sqr(k));
System.out.println(" square of " + k + " number is " + E.cube(k));
}
public double sqr(int k)
{
return k*k;
}
public double cube(int k)
{
return k*k*k;
}
}
*/

New Topic/Question
Reply


MultiQuote


|