Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

review this source code

Status
Not open for further replies.

uck

Newbie level 2
Joined
Jun 16, 2010
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
hyderabad
Activity points
1,335
Its actually anti virus source code and am unable to debug the code.
so please anyone help me out?

this is antivirus code :
import java.awt.*;
import java.awt.event.*;
import java.awt.AWTError;
class AntiVirus extends Frame implements ActionListener
{
Label select;
TextField file;
Button browse;
Button browsefile;
Button cancel;
Button scan;
Panel panel,panel1;
Dimension dimension;
Label l;
AntiVirus()
{
dimension = new Dimension(120,22);
panel = new Panel();
select=new Label("Select");
select.setPreferredSize(dimension);
file=new TextField();
file.setPreferredSize(dimension);
browse=new Button("Browse Folder");
browse.setPreferredSize(dimension);
browsefile=new Button("Browse File");
browsefile.setPreferredSize(dimension);
scan=new Button("Scan");
scan.setPreferredSize(dimension);
scan.addActionListener(this);
cancel=new Button("Exit");
cancel.setPreferredSize(dimension);
panel.add(file);
panel.add(browse);
panel.add(browsefile);
browse.addActionListener(this);
browsefile.addActionListener(this);
panel.add(cancel);
l=new Label();
panel1 = new Panel();
panel.add(scan);


Panel panel2 = new Panel();
l.setPreferredSize(new Dimension(120,100));
panel2.add(l);
Frame frame = new Frame("Container Frame");
frame.add(panel, BorderLayout.NORTH);
frame.add(panel2, BorderLayout.LINE_START);
frame.add(panel1, BorderLayout.CENTER);

frame.setSize(400,400);
frame.setVisible(true);


}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == browse) {
FileDialog fd=new FileDialog(this);
fd.show();
String filename=fd.getDirectory();
//filename=filename+"\\"+fd.getFile();
file.setText(filename);
}
if (e.getSource() == browsefile) {
FileDialog fd=new FileDialog(this);
fd.show();
String filename=fd.getDirectory();
filename=filename+"\\"+fd.getFile();
file.setText(filename);
}
if (e.getSource() == cancel) {
//dispose();
System.exit(0);
}
if (e.getSource() == scan) {
if(file.getText().equals(""))
{

l.setText("Please Browse The File OR Folder");

}
else
{
l.setText("");
String filetoscan=file.getText();
Window d=new Window(this);
d.show();
Scan sc=new Scan(filetoscan);
}
}
}
public static void main(String a[])
{
AntiVirus av=new AntiVirus();
}

};


this is scan code:

import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

import java.io.*;
import java.net.*;
public class Scan extends JFrame
{
String filename;
int count=0;
JTable table;
Label result;
DefaultTableModel tableModel;
JScrollPane scrollPane;
Dimension dimension;
JProgressBar jpb;
HashSet hashSet;
Vector dataVector = new Vector();
Vector columnVector= new Vector();
Vector folders=new Vector();
Vector files=new Vector();
Vector filesize=new Vector();

Scan(String filename)
{
System.out.println("Entered");
this.filename=filename;
filename=filename.replace("\\","\\\\");
setLayout(new FlowLayout());
dimension = new Dimension(120,22);
hashSet = new HashSet();
jpb=new JProgressBar();
columnVector.add("S.No.");
columnVector.add("File Name");

//columnVector.add("Size");
columnVector.add("Action");
tableModel =new DefaultTableModel(dataVector,columnVector);
table = new JTable(tableModel);
scrollPane = new JScrollPane(table,ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setPreferredSize(new Dimension(600,200));
add(scrollPane);
add(jpb);
//setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(550,300);
setVisible(true);



folderList(filename);
nextList();
display();
int rowcount=tableModel.getRowCount();
if(rowcount==0)
{
result=new Label("No Threats Have Been Detected");
add(result);
}
else
{
result=new Label(count+" Threats Have Been Deleted successfully");
add(result);
}

}



public void folderList(String ff)
{
System.out.println("Hello World! "+ff);

File file=new File(ff);
System.out.println("Folder Size "+file.length());
File filelist[]=file.listFiles();
for(int i=0;i<filelist.length;i++)
{


if(filelist.isDirectory())
{
String path=filelist.getAbsolutePath().replace("\\","/");
folders.add(path);
}
if(filelist.isFile())
{
String fileextention=filelist.getAbsolutePath();
if(fileextention.substring(fileextention.length()-4,fileextention.length()).equals((".exe")))
{
if(filelist.length()==0)
{
Vector list=new Vector();
list.add(count++);
list.add(fileextention);
//list.add(filelist.length());
list.add(" Deleted ");
files.add(fileextention);
filesize.add(filelist.length());
filelist.delete();
tableModel.addRow(list);
jpb.setValue(count);

}
}

}

}


}
public void nextList()
{
Enumeration e=folders.elements();
while(e.hasMoreElements())
{
String name=(String)e.nextElement();
System.out.println("FFFFF "+name);
//File subfile=new File(name);
if(name.contains("RECYLER")||name.contains("System Volume Information"))
{
File file5=new File(name);
file5.delete();
}
else
{

folderList(name);
}
}


}
public void display()
{
Enumeration ee=files.elements();
while(ee.hasMoreElements())
{
System.out.println("Total FIles"+ee.nextElement());
}
}


}
 

It's not clear what you want to do.

When you say "I am unable to debug" does that mean that
you have got this code from somewhere and are not able to understand
OR
that you developed this but don't know how to use a tool (IDE) to debug this.

In the later case, you may want to use eclipse to compile and debug the code.
 

I have got this code from a website and not able to understand.
Could you please help me.
thank you for your reply.
-uck
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top