por favor dêem uma olhada nessa aplicação e digam-me se há solução para que a malha de pinos não pisque quando movo o mouse, já botei a função isDoubleFuffered(), mas não resolveu
classe Esp que pus no pacote model
/*
- Esp.java
- Created on December 4, 2007, 10:01 AM
- To change this template, choose Tools | Template Manager
- and open the template in the editor.
*/
package Model;
import View.FrameG;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
/**
*
-
@author root
*/
public class Esp implements MouseMotionListener{
public int xValor;
public int yValor;
private FrameG f;
/** Creates a new instance of Esp */
public Esp(FrameG frame) {
f = frame;
f.addMouseMotionListener(this);
}
public void mouseMoved(MouseEvent e){
xValor = e.getX();
yValor = e.getY();
f.repaint();
}
public void mouseDragged(MouseEvent e) {
}
}
classe do frame criada no netbeans que está no pacote view
/*
- FrameG.java
- Created on December 4, 2007, 10:04 AM
*/
package View;
import Model.Esp;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
/**
*
-
@author root
*/
public class FrameG extends javax.swing.JFrame {
private Graphics g;
Esp es;
/** Creates new form FrameG */
public FrameG() {
initComponents();
es = new Esp(this);
g = getGraphics();
}
/** 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.
*/
public void paint(Graphics g) {
super.paint(g);
malhaDePinos(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setStroke(new BasicStroke(3.0f));
g.drawLine(83, 103, es.xValor, es.yValor);
}
//
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().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)
);
pack();
}//
public void malhaDePinos(Graphics g){
int x = 80;
int y = 100;
int width = 8;
int heigth = 8;
<a href="//super.paint">//super.paint</a>(g);
//cria 2D convertendo g para Graphics2D
Graphics2D g2d = (Graphics2D) g;
for({int i=0; i<14; i++)
for({int j=0; j<14; j++)
g.setColor(Color.ORANGE);
g.fillRect(x,y,width,heigth);
x = x + 30;
}
y = y + 30;
x = 80;
}
}
/**
-
@param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new FrameG().setVisible(true);
}
});
}
// Variables declaration - do not modify
// End of variables declaration
}