Zdravim, potrebovala bych pomoct s aplikaci osciloskop. Vycitam data ze seriove linky a ty vykresluji pomoci graphic2D do Jpanelu. Zatim to delam tak ze do promene nacitam data a ty vzdy, kdyz mam vice jak 100 bodu vykreslim. Jenze vzdy prekresluji cely panel, neexistuje funkce ktera by jen dovykreslila novy bod a posunula okno tak, ze druhe strany by se ten bod zase smazal? Aby se mi nemenilo meritko a nemusela bych porad prekreslovat cely Jpanel, potrebuju aby to fungovalo reatime tak 50x za sekundu.
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
int w = getWidth();
int h = getHeight();
//System.out.println(w + "x" + h);
double xScale = (w - 2 * PAD) / (xMax - xMin);
double yScale = (h - 2 * PAD) / (yMax - yMin);
if (firstTime) {
System.out.printf("xScale = %.1f yScale = %.1f%n",
xScale, yScale);
}
Point2D.Double origin = new Point2D.Double(); // Axes origin.
Point2D.Double offset = new Point2D.Double(); // Locate data.
origin.x = PAD;
offset.x = w;
origin.y = h - PAD;
offset.y = origin.y;
// Draw abcissa.
g2.draw(new Line2D.Double(PAD, origin.y, w - PAD, origin.y));
// Draw ordinate.
g2.draw(new Line2D.Double(origin.x, PAD, origin.x, h - PAD));
g2.setPaint(Color.red);
// Mark origin.
g2.fill(new Ellipse2D.Double(origin.x - 2, origin.y - 2, 4, 4));
g2.setPaint(Color.green.darker());
double x1, x2, y1, y2;
for (int i = 0; i < x.length - 2; i++) {
x1 = offset.x - xScale * x[i];
y1 = offset.y - yScale * y[i];
x2 = offset.x - xScale * x[i + 1];
y2 = offset.y - yScale * y[i + 1];
g2.setPaint(Color.green.darker());
g2.draw(new Line2D.Double(x1, y1, x2, y2));