• Post Reply Bookmark Topic Watch Topic
  • New Topic

draw dynamic lines

 
suraya ya'acob
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is class can be loop ?
Here is my coding...
My output should be a few lines depends on data of t_diagnosa1 in database...but the thing is...only 1 line appear in my interface but the output from "system.out.println..." appear the looping data..
let say..t_diagnosa1 have value for "302" and "402" then i should have two lines...
*********mdinamik.java**************
import java.awt.*;
import java.awt.Container;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import javax.swing.JPanel;
import javax.swing.ImageIcon;
import javax.swing.border.*;
import java.awt.image.*;
import java.sql.*;
import java.util.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.text.*;
public class mdinamik extends JFrame{
String starikh;
int tarikh;
int bil;
int piksel;

public mdinamik()
{
Container pane = getContentPane();
pane.setLayout(new FlowLayout());

try
{
String url = "jdbc dbc b2";
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(url);

Statement stmt = conn.createStatement();

String query = "SELECT t_diagnosa1 FROM diagnosa WHERE nopesakit = '51' ";
ResultSet rs = stmt.executeQuery(query);

while (rs.next() )
{
starikh = rs.getString("t_diagnosa1");
tarikh = Integer.parseInt(starikh);
System.out.println("starikh" + tarikh);

bil = 0;
piksel = 0;

if(tarikh != 102)
{
bil++;
if(tarikh != 202)
{
bil++;
if(tarikh != 302)
{
bil++;
if(tarikh !=402)
{bil++;
}}}}
if(bil == 1)
piksel = 30;
else if(bil == 2)
piksel = 60;
else if(bil == 3)
piksel = 90;
pixel p1 = new pixel (piksel, 20,600);
pane.add(p1);
System.out.println("bil :" + bil);
System.out.println("piksel :" + piksel);
}
conn.close();
}
catch (Exception e) {
System.err.println("dddd");
System.err.println(e.getMessage());
}


setBounds(0,0,904,750);
setVisible(true);
}
public static void main (String args[])
{
mdinamik aya = new mdinamik();
aya.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
*******pixel.java**********************
import javax.swing.*;
import javax.swing.plaf.ComponentUI;
import java.awt.*;
import java.awt.Container;
import java.awt.event.*;
import java.applet.*;
import javax.swing.JPanel;
import javax.swing.ImageIcon;
import javax.swing.border.*;
import java.awt.image.*;
import java.sql.*;
import java.util.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.text.*;

public class pixel extends JComponent {
int piksel, x,x2;
public pixel(int piksel, int x, int x2) {
this.piksel = piksel;
this.x = x;
this.x2 = x2;
this.setPreferredSize(new Dimension(1000,1000));
}

public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d=(Graphics2D) g;
g2d.drawLine(piksel,x,piksel,x2);

}

public int getpiksel() {
return piksel;
}
public void setY(int piksel) {
this.piksel = piksel;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}

public int getX2() {
return x2;
}
public void setX2(int x2) {
this.x2 = x2;
}

}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!