Código del Panel
Código:
Código Randomimport java.awt.Color; import java.awt.Dimension; import java.awt.Frame; import java.awt.Graphics; import java.awt.Panel; import javax.swing.JTabbedPane; public class GPanel extends Panel{ public GPanel() { setBackground(Color.white); this.setMinimumSize(new Dimension(800, 600)); } @Override public void paint(Graphics g) { g.drawRect(5, 5, getWidth()-10, getHeight()-10); } @Override public Dimension getPreferredSize() { return new Dimension(160,150); } public static void main(String[] args) { Frame f = new Frame("G"); GPanel pr1 = new GPanel(); GPanel pr2 = new GPanel(); PanelBarra pr3 = new PanelBarra(); GPanel pr4 = new GPanel (); GRandom pr5 = new GRandom(); f.add(pr1,"West"); f.add(pr2,"East"); f.add(pr3,"Center"); f.add(pr4,"North"); f.add(pr5, "South"); f.pack(); f.setVisible(true); } }
Código:
Código de Gráfico Barrasimport java.applet.*; import java.awt.Graphics; import java.util.Random; class GRandom extends Applet implements Runnable { static int instan; Thread t; int i=0; boolean suspended; Random aleatorio = new Random(); GRandom() { suspended=false; t=new Thread(this); t.start(); } public void run() { while(true) { instan= aleatorio.nextInt(100); i++; repaint(); try { Thread.sleep(10); } catch (InterruptedException e) {} } } @Override public void paint(Graphics g) { String Prueba="Dato Instantaneo: "+instan+" Proceso Numero: "+i; g.drawString(Prueba,15,10); } @Override public void stop() { t.stop(); } }
Código:
Si no se entiende la idea no duden en decirme import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import javax.swing.*; import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.category.DefaultCategoryDataset; public class PanelBarra extends JPanel { JFreeChart barra; DefaultCategoryDataset datos; JLabel grafico; JButton b; public PanelBarra(){ datos = new DefaultCategoryDataset(); b=new JButton("Actualizar"); b.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e) { datos.setValue(GRandom.instan, "A", ""); BufferedImage graficobarra=barra.createBufferedImage(200, 300); ImageIcon img=new ImageIcon(graficobarra); grafico.setIcon(img); } }); datos.addValue(GRandom.instan, "A", ""); barra = ChartFactory.createBarChart3D("Cola", "Quarters","Sales",datos,PlotOrientation.VERTICAL,true,true,true); BufferedImage graficobarra=barra.createBufferedImage(450, 300); ImageIcon img=new ImageIcon(graficobarra); grafico=new JLabel(img); JPanel p=new JPanel(); p.add(b); add(grafico); add(p,BorderLayout.SOUTH); } }