the program should be a lamer application that busts balls of user with popping windows from time to time
the only input parameter that we have is the listener on the red X closing button
the idea is that more is user trying to close every one of them,the more it pops out
so I have counter of clicks,I need also a timer so I could divide it to find out the speed of clicking and then calculate how much new windows it's going to pop out
so I need one class in which I'll be able to control all this and add some amount of randomness
and off course program should not be running CPU more than 3%
//import java.awt.event.WindowEvent;
//import java.awt.event.WindowListener;
import java.awt.*;
//import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.*;
import javax.swing.*;
//import javax.swing.JPanel;
import java.util.Timer;
import java.util.TimerTask;
//class just for frame and panel painting
public class WinLsnrExp extends JFrame {
private boolean a;
public WinLsnrExp() {
setTitle("Suncica2222");
setSize(150, 150);
KlasaPanel panel = new KlasaPanel();
//Container panel = getContentPane();
panel.setBackground(Color.green);
add(panel); // IF I COMMENT THIS LINE IT GETS NORMAL ON 5% CPU BUT ITS WHITHOUT STRING DRAWED!!!!!!!!!!!!!!!!!
//repaint();
panel.repaint();
//panel1.setBackground(Color.red);
}
}
//class that counts clicks on red X closing button of the window
class BrojiKlikove
{
public static int a=0;
public BrojiKlikove()
{
a++;
System.out.println(a);
for (int i=0;i<a-4;i++){
CekajSekundi y= new CekajSekundi(0);
KlasaKojaSlusa x=new KlasaKojaSlusa();
}
}
}
//class that makes the window frame and has a listener on red X //closing button
class KlasaKojaSlusa extends JFrame
{
private static boolean b;//nicemu ne sluzi
public KlasaKojaSlusa(String s){}
public KlasaKojaSlusa()
{
WinLsnrExp wle = new WinLsnrExp();
//wle.setTitle("Suncica2222 ");
//wle.setSize(150, 150);
//wle.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
wle.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
wle.setLocation((int)(Math.random()*900),(int)(Math.random()*750));
wle.setVisible(true);
wle.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent arg0) {
System.out.println("Window Closing");
//this.b=true; // a cannot be resolved or is not a field
BrojiKlikove x=new BrojiKlikove();
}
});
}// konstrukt
}
//class for drawing "xD" string on panel
//I would also like to draw some more strings but it wont let me...
class KlasaPanel extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
//g.Font(50);
Font font = new Font("Serif", Font.PLAIN, 100);
setFont(font);
//g.setColor(Color.red);
g.drawString("xD",10, 90);
}
}
class just for calling everything in main()
public class KlasaZaMain
{
public static void main(String[] args) throws Exception
{
for (int i=0;i<5;i++){
KlasaKojaSlusa x=new KlasaKojaSlusa();
CekajSekundi y= new CekajSekundi(0);
//x.praviProzor();
//y=new KlasaKojaSlusa("xaxaxa");
//KlasaKojaSlusa.brojiKlikove();
}
/*while(true){
Thread.sleep(500);
}*/
//if (KlasaKojaSlusa x==null)
System.out.println(BrojiKlikove.a + "izbrojao sam");
}
}//klasa
class which constructor make pause of int seconds in running program
public class CekajSekundi {
public CekajSekundi(int sekunde) {
try
{
//wait(sekunde*1000);
Thread.sleep(sekunde*1000);
}
catch (Exception e) {}
}
}