#1
  1. Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    North Crater
    Posts
    16
    Rep Power
    0

    return outside method


    hey,

    im a total n00b when it comes to java, so here goes..

    i've got this simple applet, it's just an exercise. i'm using jbuilder9, and i can't get this thing to run, because of a "return outside method" error -- although i made a similar applet where it worked perfectly.

    Main Applet:
    Code:
    package w4_wisselgeld;
    
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    
    public class WisselgeldMain extends Applet {
      private boolean isStandalone = false;
      //Get a parameter value
      public String getParameter(String key, String def) {
        return isStandalone ? System.getProperty(key, def) :
          (getParameter(key) != null ? getParameter(key) : def);
      }
      Button go;
      TextField input1,input2,output;
      Math count;
    
      //Construct the applet
      public WisselgeldMain() {
      }
      //Initialize the applet
      public void init() {
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
        super.init();
        setLayout(null);
        setBackground(Color.white);
        setForeground(Color.black);
    
        go = new Button ("Bereken!");
        go.setBounds(10,40,210,20);
        go.setBackground(Color.black);
        go.setForeground(Color.white);
        go.addActionListener(new goAL());
        add(go);
    
        input1 = new TextField("Inworp");
        input1.setBounds(10,10,100,20);
        input1.setBackground(Color.black);
        input1.setForeground(Color.white);
        add(input1);
    
        input2 = new TextField("Prijs");
        input2.setBounds(120,10,100,20);
        input2.setBackground(Color.black);
        input2.setForeground(Color.white);
        add(input2);
    
        output = new TextField("Teruggave...");
        output.setBounds(10,70,210,20);
        output.setBackground(Color.black);
        output.setForeground(Color.white);
        add(output);
      }
    
      class goAL implements ActionListener
      {
        public void actionPerformed(ActionEvent e)
        {
          String inworpS = input1.getText();
          Integer inworpI = Integer.valueOf(inworpS);
          int inworp = inworpI.intValue();
    
          String prijsS = input2.getText();
          Integer prijsI = Integer.valueOf(prijsS);
          int prijs = prijsI.intValue();
    
          count = Math(inworp,prijs);
          int aantal50 = count.aantal();
          String aantal50S = String.valueOf(aantal50);
          output.setText(aantal50S);
        }
    
        private Math Math(int inworp, int prijs) {
          return null;
        }
      } (etc...)
    }
    Math Class:
    Code:
    package w4_wisselgeld;
    
    public class Math {
      public Math() {
      }
      public static void main(String[] args) {
        Math math1 = new Math();
      }
    
      int inworp;
      int prijs;
    
       public Math(int inworp, int prijs)
      {
        this.inworp = inworp;
        this.prijs = prijs;
      }
    
      public int aantal();
      {
        int verschil = (inworp - prijs);
        int e50 = (verschil / 50);
        return e50; // Return outside method Error 
      }
    }
    can anyone tell me what im doing wrong? thanks!
  2. #2
  3. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    121
    You have a semi-colon behind this method
    public int aantal();

    That is likely causing your problem
    ~Nemi

    Before posting did you try:
    [ Javadocs | Google ]
  4. #3
  5. Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    North Crater
    Posts
    16
    Rep Power
    0
    thanks, i knew it was something stupid
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2009
    Posts
    1
    Rep Power
    0
    import javax.swing.JOptionPane;
    public class pig
    {private int totaljugador;

    public int aleatorio(int max, int min);
    {
    return (int)(Math.random()*(max-min))+min + 1;
    }
    public void usuario();
    {int r=1;
    int tiro;
    int puntos =0;
    tiro= this.aleatorio(1,6);
    while((tiro!=1) && ((100 - puntos) < 100) && (r > 0))
    { puntos= puntos + tiro;
    r = JOptionPane.showConfirmDialog(null, "Desea Continuar/* Su puntaje es: " + puntos,"PIG", JOptionPane.YES_NO_OPTION);
    if (r == JOptionPane.YES_OPTION)
    {tiro= this.aleatorio(1,6);
    if (tiro == 1)
    {puntos = 0;}
    }
    }
    return puntos; // Return outside method Error
    JOptionPane.showMessageDialog(null, puntos,
    "Puntos",JOptionPane.PLAIN_MESSAGE);
    }

    /* public int maquina();
    {int puntaje1=0;
    int tiro1;
    int puntos2;
    while (tiro1!=1) ||(i < = 4)
    {tiro1= this.aleatorio(1,6);
    puntos2= puntos2 + tiro;
    i= i + 1;
    } return puntos2;
    puntaje2= Integer.parseInt(puntos2);
    JOptionPane.showConfirmDialog(null, "El puntaje de la maquina es: ", puntaje2, "PIG", JOptionPane.SI_NO_OPTION);
    } */
    public static void main(String[] args) {

    pig p1;
    p1 = new pig();
    p1.aleatorio(1,6);
    //p1.usuario();
    //p1.maquina();
    System.exit(0);


    }
    }

IMN logo majestic logo threadwatch logo seochat tools logo