public class ventanaGrafica extends Frame {
BufferedImage grafica = null;
/** Creates new form ventanaGrafica */
public ventanaGrafica() {
initComponents();
}
/** 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.
*/
private void initComponents() {
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
pack();
}
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
System.out.println("cantidad");
ventanaGrafica miventana = new ventanaGrafica();
miventana.setSize(400,400);
miventana.show();
}
public void paint(Graphics g) {
//super.paint(g);
if(grafica == null)
{
grafica = this.readData();
}
g.drawImage(grafica,30,30,null);
}
private BufferedImage readData() {
JFreeChart chart = null;
// JDBCPieDataset data = null;
JDBCXYDataset xyDataset = null;
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost/jnior",
"root", "");
//Statement stmt = con.createStatement();
xyDataset =new JDBCXYDataset(con);
String sql = "select Faren,Cent from temp;";
xyDataset.executeQuery(sql);
chart = ChartFactory.createXYLineChart("title", "ABS CODE",
"AVERAGE", xyDataset, PlotOrientation.VERTICAL, true, true, true);
con.close();
}catch(SQLException y)
{
y.printStackTrace();
}
catch(ClassNotFoundException y)
{
y.printStackTrace();
}
BufferedImage image = chart.createBufferedImage(300,300);
return image;
}
}
--
kitty
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------