Eddie Eddie - 1 year ago 65
Java Question

Made a "virus", need tips

First of all, it's not really a virus that is used to spy, or steal bank accounts. I don't even know if it's a virus at all. I only made it to troll friends/people I know, and practice my programming skills. I will show you the code, then I will try to explain it a bit;

package pracatice;

import java.awt.event.*;

import javax.swing.*;

public class practice extends JFrame
public static boolean bool = true;
public static int x = 0;
public static int y = 0;
public static int num = 0;
public static TimerClass tc = new TimerClass();
public static Timer timer = new Timer(30, tc);
public JPanel panel = new JPanel();
public JButton btn = new JButton("press");

public practice()
public void setPanel()
btn.addActionListener(new listener());


public class listener implements ActionListener
public void actionPerformed(ActionEvent e)
num = 0;

public static class TimerClass implements ActionListener
public void actionPerformed(ActionEvent e)

JOptionPane optionPane = new JOptionPane("PC afected by virus");
JDialog dialog = optionPane.createDialog(null, "Virus");
dialog.setLocation(x, y);
}while(bool == true);

public static void updateCordinates()
if(x != 1100)
x += 100;
else if(x == 1100)
x = 0;
y += 50;
if(y == 650)
y =0;

public static void main(String[] args)
new practice();

So, at first it obviously builds a window, 100 X 100 px big. It adds a button that says "press". When you press, it starts a new loop, every 30 milliseconds.
every iteration of the loop, it puts in a new
in a slightly different location.

At first, when I just made it, I didn't know it would be unstoppable. I ran it, and had to restart my laptop. When I pressed ok, it would put in another box, in the exact same spot. When I tried to open task manager, it would automatically minimize it, and go back into the "virus" window. So, the laptop was unusable. I had to restart it, closing some of my dads tabs...

Here are a few things I would like to find out;

1) If I left this run over night, is it possible, that the laptop ran out or RAM, and if it did, what would happen?

2) Can I make it that, when I press a button on the keyboard, the whole thing just closes?

Like I said before, I was only trying to prank my friends, and the program happened to not be closable... any advice?

Answer Source

Answers to your two questions:

  1. Leaving it overnight, without touching it. will not make it run out of RAM, or stack size, because it is not on a continues for loop, only making new Dialogs. This is the same thing as leaving a normal application overnight.

  2. Yes you can make a key make it close by using a KeyListener. You would make it do something like System.exit(0);.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download