Page 1

package virus; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Virus { private DrawCanvas dc; Virus(){ GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment (); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); Rectangle bounds = gc.getBounds(); JFrame jf = new JFrame(gc); jf.setLocation(0,0); jf.setUndecorated(true); jf.setMaximizedBounds(bounds); gd.setFullScreenWindow(jf); dc = new DrawCanvas(); dc.setBackground(new Color(0,0,0)); jf.add(dc); jf.setVisible(true); jf.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } }); } public static void main(String[] args) { new Virus(); } private class DrawCanvas extends Canvas implements ActionListener{ private int percent = 0; private Timer t; DrawCanvas(){ t = new Timer(800, DrawCanvas.this); t.start(); } public void paint (Graphics g){ g.setColor(new Color(255,255,255)); String message = "DELETING YOUR HARD DRIVE: " + percent + "%"; g.drawString(message, 450, 400); if(percent == 100)stop(); } public void actionPerformed(ActionEvent e){ percent++; repaint(); } public void stop(){ t.stop(); } } }

JavaW3ex3  

Victoria University

Read more
Read more
Similar to
Popular now
Just for you