1 Replies - 1498 Views - Last Post: 01 July 2015 - 08:12 PM Rate Topic: -----

#1 Faye2424   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-July 15

Dialog input to non static method

Posted 01 July 2015 - 07:28 PM

I am confused with my homework assignment. I managed the double input but can't figure out how to pass it to a non-static method. A point in the right direction would be much appreciated, or even a website that explains it.

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;
}
}


     */



Is This A Good Question/Topic? 0
  • +

Replies To: Dialog input to non static method

#2 Faye2424   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-July 15

Re: Dialog input to non static method

Posted 01 July 2015 - 08:12 PM

Disregard, i don't know how to delete this and I was being dumb ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1