Need Help With Cleaner
Author |
Message |
Krocker
|
Posted: Sat Dec 31, 2011 11:46 am Post subject: 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 ();
}
} |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
ProgrammingFun
|
Posted: Sat Dec 31, 2011 12:07 pm Post subject: 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 CCleaner. |
|
|
|
|
|
Krocker
|
Posted: Sat Dec 31, 2011 12:12 pm Post subject: RE:Need Help With Cleaner |
|
|
how would i refer to each method seperatly? also, i wanted to make my own. |
|
|
|
|
|
ProgrammingFun
|
Posted: Sat Dec 31, 2011 12:15 pm Post subject: Re: Need Help With Cleaner |
|
|
Quoted from my computer science notes from last year:
VPCI ICS Department wrote:
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:
[access_level] [static] [return type] identifier ([formal parameters])
Example Method Signatures
1) public static void printText(String text)
2) void printText(String text)
3) public int getPoints()
4) public float calcPerimeter(float length, float width)
4.0 Method Call Syntax for void methods
A return value of void means no value is returned.
methodname( [actual parameters]);
5.0 Method Call Syntax for non-void methods
When a method returns a value like int, float, String etc, we most likely want to utilize the returned value (returning that value is usually the purpose of the call). What we do with the value is context dependent eg. we could print it, store it, use it another call.... and so on.
Here?s an example of using a method that returns the points a user has. Notice there are no parameters, but we still need to include brackets when we call it.
Method Signature: public int getPoints( )
Example calls
System.out.println(getPoints( ) ); //printing returned points
int pts = getPoints( ) ; //storing returned points
int pts = 5 * getPoints( ); //using the returned value in an equation
displayPoints(getPoints( ) ); //using the returned value as a //parameter to another call
Example Signatures and Calls (for void and non-void)
Signature Call
public static void printText(String text) printText(?abc?);
void printText(String text) printText(?abc?);
public int getPoints() c.println(getPoints( ));
public float calcPerimeter(float length, float width) int length = 5;
float perimeter = calcPerimeter(length, 10);
6.0 Another Example Method Declaration and Call
//declaration
public static boolean checkPrime (int n)
{
double sqrtr = Math.sqrt(n);
int factor = 2;
while (factor <= sqrtr && n % factor !=0)
{
factor++;
}
return factor > sqrtr;
}
//////////////////////////////////////////////////////////////////////////////////
//example call 1
checkPrime(5); /* useless, but won?t complain even if you do nothing with the return type */
// example call 2
c.println(checkPrime(9)); // will print out the returned result... false
// example call 3
int num = c.readInt();
if (checkPrime(num))
c.println(num + ?is a prime number?);
else
c.println(num + ?is not a prime number?);
7.0 Parameters
Parameters are either formal or actual.
Formal Parameters: those in the signature
Actual Parameters: those in the call; the actual values
8.0 Pass-by-value vs Pass-by-reference Parameters
Actual Parameters are either pass-by-value or pass-by-reference.
Pass-by-Value: the value of the actual parameter is given to the method. Used as input only. Partner formal and actual parameters have separate locations in memory
Pass-by-Reference (Pass-by-variable): the memory address of the actual variable is given to the method. These are used as both input and output. Partner formal and actual parameters share the same location in memory ie. reference the same location
In Java methods, primitive arguments are passed by value. When invoked, the method receives the value of the variable passed in. When the argument is of primitive type, pass-by-value means that the method cannot change its value. When the argument is of reference type, pass-by-value means that the method cannot change the object reference, but can invoke the object's methods and modify the accessible variables within the object. Huh??? For now, this means that for all primitive types, if you change it in the method, it doesn?t have an effect on the ?actual parameter?. But for non-primitive types like arrays, if you change it in the method, it will also change the value of the actual parameter.
|
|
|
|
|
|
Krocker
|
Posted: Sat Dec 31, 2011 12:26 pm Post subject: 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
|
Posted: Sat Dec 31, 2011 12:48 pm Post subject: 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. |
|
|
|
|
|
|
|