
-----------------------------------
Krocker
Sat Dec 31, 2011 11:46 am

Need Help With Cleaner
-----------------------------------
Hey guys, ok so im new to this and wanted to create a cleaner for my grandparents. They seem to have a lot of junk files and i dont have the time to always delete them. Therefore i wanted to create a program which does it for them. But i keep getting errors and i dont know whats wrong. Please help me!

[code]
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class Test extends JFrame implements ActionListener
{
    public JFrame f1 = new JFrame ("Frame");
    public JPanel p1 = new JPanel ();
    public JButton b1 = new JButton ("Clean");
    public JButton b2 = new JButton ("Close");
    public Test ()

    {
        b1.addActionListener (this);
        b2.addActionListener (this);
        f1.setContentPane (p1);
        f1.setSize (400, 400);
        p1.add (b1);
        p1.add (b2);
        f1.setVisible (true);

    }


    public void actionPerformed (ActionEvent e)
    {
        if (e.getSource () == b1)
        {

            JOptionPane.showMessageDialog (null, "Button 1 is clicked!");

            public static void main (String[] argv) throws Exception
            {
                deleteDir (new File ("c:\\Nexon/Combat Arms/BlackCipher"));

            }

            public static boolean deleteDir (File dir)
            {
                if (dir.isDirectory ())
                {
                    String[] children = dir.list ();
                    for (int i = 0 ; i < children.length ; i++)
                    {
                        boolean success = deleteDir (new File (dir, children [i]));
                        if (!success)
                        {
                            return false;
                        }
                    }
                }
                return dir.delete ();
            }

        }
        else if (e.getSource() == b2)
        {
            JOptionPane.showMessageDialog (null, "Button 2 is clicked");
        }
    }


    public static void main (String args[])
    {
        new Test ();
    }
}[/code]

-----------------------------------
ProgrammingFun
Sat Dec 31, 2011 12:07 pm

RE:Need Help With Cleaner
-----------------------------------
I'm pretty sure that you're not allowed to have methods within methods in Java. That is the source of your error. You can declare all methods separately and then refer to them within you if statements.

Also, try [url=http://www.piriform.com/ccleaner]CCleaner.

-----------------------------------
Krocker
Sat Dec 31, 2011 12:12 pm

RE:Need Help With Cleaner
-----------------------------------
how would i refer to each method seperatly? also, i wanted to make my own.

-----------------------------------
ProgrammingFun
Sat Dec 31, 2011 12:15 pm

Re: Need Help With Cleaner
-----------------------------------
Quoted from my computer science notes from last year:


Methods


1.0	What is a method?

?	methods are mini programs (sub programs) that perform isolated re-usable tasks eg. Scanner class has many methods: reading a line (nextLine), reading an integer (nextInt), reading a double (nextDouble) etc
?	parameters: parameters are information passed into the class to change the outcome of the task eg. String?s charAt method has 1 piece of information that represent the index of the character to be returned.  
?	return values: methods may return values to the call eg. String?s charAt returns the character at the specified index.

2.0	Method Declaration vs Call

Method Declaration: this is the signature and body of the method; the actual code that performs the task.

Method Call: this is the code to execute (invoke) the method.  Note: methods will never run unless they are called.

Example Method Declaration

public static int mystery (double a, double b) {
  int value = 0;
  if (a < b) {
    value = -1;
  } else if (a > b) {
    value = 1;
  }
  return value;
}

Example Method Calls
int n = mystery (23.43, 23);		//using literal values for parameters

final double SIZE = 4.3;
final float WIDTH = 12;
int j;
j = mystery (SIZE, WIDTH);	//using literals and variables for parameters







3.0	Method Signature (header) Syntax:


-----------------------------------
Krocker
Sat Dec 31, 2011 12:26 pm

RE:Need Help With Cleaner
-----------------------------------
uhm... ok, but can u give me an example off how to call a method from a different class, where i want to call dporcess in my Kcleaner program. I have packaged bothe classes into the same file

-----------------------------------
ProgrammingFun
Sat Dec 31, 2011 12:48 pm

RE:Need Help With Cleaner
-----------------------------------
Since you posted in a new thread (which there is no need for, you can just continue here), I have answered your question there.
