salve
ho il seguente component:
import java.awt.*;
import javax.swing.*;

public class PlotTest extends JComponent
{
int PAD = 20;
boolean drawLine = true;
boolean drawDots = true;
int dotRadius = 3;

// the y coordinates of the points to be drawn; the x coordinates are evenly spaced
int[] data = { 25, 30, 42, 45 };

protected void paintComponent (Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASIN G, RenderingHints.VALUE_ANTIALIAS_ON);
int w = getWidth();
int h = getHeight();
g2.drawLine(PAD, PAD, PAD, h-PAD);
g2.drawLine(PAD, h-PAD, w-PAD, h-PAD);
double xScale = (w - 2*PAD) / (data.length + 1);
double maxValue = 100.0;
double yScale = (h - 2*PAD) / maxValue;
// The origin location
int x0 = PAD;
int y0 = h-PAD;

// draw connecting line
if (drawLine)
{
for (int j = 0; j < data.length-1; j++)
{
int x1 = x0 + (int)(xScale * (j+1));
int y1 = y0 - (int)(yScale * data[j]);
int x2 = x0 + (int)(xScale * (j+2));
int y2 = y0 - (int)(yScale * data[j+1]);
g2.drawLine(x1, y1, x2, y2);
}
}

// draw the points as little circles in red
if (drawDots)
{
g2.setPaint(Color.red);
for (int j = 0; j < data.length; j++)
{
int x = x0 + (int)(xScale * (j+1));
int y = y0 - (int)(yScale * data[j]);
g2.fillOval(x-dotRadius, y-dotRadius, 2*dotRadius, 2*dotRadius);
}
}
}
}
che vorrei visualizzare all'interno di un panel contenuto in un'applet dopo il click di un bottone
l'applet è la seguente:
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

PlotTest d = new PlotTest();
d.setVisible(true);
jPanel2.add(d);

jPanel2.setVisible(true);
jPanel2.updateUI();

}
ma non mi visulizza il component PlotTest

se invece scrivo:
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
JFrame f = new JFrame();

f.getContentPane().add(new PlotTest());
f.setSize(400,400);
f.setLocation(200,200);
f.setVisible(true);
}
riesco a visualizzare il component PlotTest, ma lo visualizza all'interno di un'altra finestra
io invece appunto voglio visualizzarlo all'interno del panel jPanel2
se volete posso scrivere tutto il codice dell'applet ma non credo che servi
ringrazio anicipatemnte chi puo aiutarmi
ciauz