
package my4;
/**
 *
 * @author Viliam Krizan
 */



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



public class GUI extends JFrame {
    
    private JPanel mousePanel;
    private JLabel statusBar;
    int p=0;
    Date date1, date2;
    
    public GUI(){
        super("title");
        
        mousePanel = new JPanel();
        
        setUndecorated(true);
        
        add(mousePanel, BorderLayout.CENTER);
        
        statusBar = new JLabel("default");
        add(statusBar, BorderLayout.NORTH);
        
        HandlerClass handler = new HandlerClass();
        
        mousePanel.addMouseMotionListener(handler);
        
    }
    
    private class HandlerClass implements  MouseMotionListener{

        
        public void mouseDragged(MouseEvent e) {
            //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            //statusBar.setText("mouse draging");
        }

        public void mouseMoved(MouseEvent e) {
            int k = MouseData.addNewCoordinate(e.getX(), e.getY());
            if(p==0){
                date1 = new Date();
                p++;
            }
            
            if(k==1){
                statusBar.setText(String.format("moving %d, %d", e.getX(), e.getY()));
            }else{
                date2 = new Date();
                dispose();
                JFrame frame = new JFrame();
                JOptionPane.showMessageDialog(frame, "Memory is full");
                MouseData.processData();
                System.out.println("total time: " + (date2.getTime()-date1.getTime()));
                System.exit(0);
            }
            
        }
        
    }
    
}
