/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package day3; import java.awt.Graphics; /** * * @author levenick */ public class MyPanel extends javax.swing.JPanel { MagicSquare mySquare = new MagicSquare(5); private final MagicFrame theFrame; private boolean running=true; /** * Creates new form MyPanel */ public MyPanel(MagicFrame f) { initComponents(); theFrame = f; } public void paintComponent(Graphics g) { g.fillRect(100, 100, 20, 20); mySquare.paint(g); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { addMouseListener(new java.awt.event.MouseAdapter() { public void mousePressed(java.awt.event.MouseEvent evt) { formMousePressed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 400, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 300, Short.MAX_VALUE) ); }// //GEN-END:initComponents private void formMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMousePressed int x = evt.getX(); int y = evt.getY(); System.out.print("x = " + x); System.out.println(" y = " + y); mySquare.handleClick(x, y); //theFrame.repaint(); }//GEN-LAST:event_formMousePressed void loop() { for (;;) { // forever! if (running) { step(); } delay(); } } private void step() { theFrame.repaint(); } private void delay() { try { Thread.sleep(5000); // sleep for 50 msecs } catch (Exception e) { } } // Variables declaration - do not modify//GEN-BEGIN:variables // End of variables declaration//GEN-END:variables }