Insert a JFrame into a JPanel or something
Hi,
I have a plotter that is being shown in JFrame. It has a main code.
I need to show this plot inside al applet, so I thought that maybe I could put it into a Jpanel inside an applet (the applet window contains more things than the plot).
Is this possible? How? are there any restrictions?
Is there any other option to do this?
[360 byte] By [
kandua] at [2007-11-27 9:31:57]

# 2
Is there a way that I do what I have in my JFrame but inside a Panel or another structure instead?
I'll show you my code:
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import ptolemy.plot.Plot;
//////////////////////////////////////////////////////////////////////////
//// TwoPlotExample
public class TwoPlotExampleinvento extends JFrame {
TwoPlotExampleinvento() {
// Instantiate the two plots.
Plot leftPlot = new Plot();
Plot rightPlot = new Plot();
// Set the size of the toplevel window.
setSize(400, 500);
leftPlot.setSize(350, 200);
leftPlot.setButtons(true);
leftPlot.setTitle("Se馻l en el tiempo");
leftPlot.setXLabel("Tiempo (segundos)");
leftPlot.setYLabel("Amplitud");
leftPlot.setMarksStyle("none");
leftPlot.setImpulses(true,1);
for (double i = -4; i <= 50; i=i+1) {
leftPlot.addPoint(1, i, 5 * Math.sin((Math.PI * i) / 20), false);
leftPlot.addPoint(2, i, 10 * Math.cos((Math.PI * i) / 25), true);
}
int T=5;
for (double i = -4; i <= T; i=i+1){
leftPlot.addPoint(4,i,2*i+1,true);
}
rightPlot.setButtons(true);rightPlot.setSize(350, 200);
for (int i = -4; i <= 50; i++) {
rightPlot.addPoint(0, i, 5 * Math.cos((Math.PI * i) / 20), true);
}
rightPlot.setTitle("Espectro de Frecuencia");
rightPlot.setXLabel("Frecuencia (Hz)");
rightPlot.setYLabel("Amplitud");
// Layout the two plots
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
getContentPane().setLayout(gridbag);
// Handle the leftPlot
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 1;
gridbag.setConstraints(leftPlot, c);
getContentPane().add(leftPlot);
// Handle the rightPlot
c.gridx = 0;
c.gridy = 1;
c.gridwidth = 1;
//c.fill = GridBagConstraints.BOTH;//Creo que esto obliga a que los graficos ocupen toda la pantalla
c.weightx = 1.0;
c.weighty = 1.0;
gridbag.setConstraints(rightPlot, c);
getContentPane().add(rightPlot);
setVisible(true);
}
/** main method called in a standalone java application.
* We simple instantiate this class, most of the work
* happens in the constructor.
*/
[b] public static void main(String[] args) {
// We execute everything in the Swing Event Thread, see
// the comment
Runnable doAction = new Runnable() {
public void run() {
new TwoPlotExampleinvento();
}
};[/b]
SwingUtilities.invokeLater(doAction);
}
}
kandua at 2007-7-12 22:48:13 >
