This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Draw the line in JPanel using variables from the database  RSS feed

 
suraya ya'acob
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I want to draw the line using class with extends JPanel. I 've tried my coding below using class with extends JFrame and it works! but when it comes to extends JPanel, paintComponent seems didn't get the variables that I passed. I attach my coding below
please help me!

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.*;
class carian23 extends JPanel implements ActionListener{
int xxmula,yymula,xxtamat,yytamat;
int xx1,yy1,xx2,yy2;
private mukadepan mdepan;
private DataPanel dpanel;
public carian23(mukadepan mk, DataPanel dp)
{
mdepan=mk;
dpanel=dp;

}
public void actionPerformed (ActionEvent e)
{
try{
String r=mdepan.cuba();
String url="jdbc dbc b2";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(url);
String nama, satu2, dua2,tiga2, empat2 = null;
Statement statement =conn.createStatement();

String query = "SELECT * FROM personal p, koordinat k, koordinat2 k2 WHERE p.nopesakit = '" + r + "'";
ResultSet rs = statement.executeQuery( query );
while (rs.next())
{
satu2= rs.getString("xxone");
tiga2 = rs.getString("yone");
dua2=rs.getString("xxtwo");
empat2 = rs.getString("ytwo");
int xx1 = Integer.parseInt(satu2);
int yy1 = Integer.parseInt(tiga2);
int xx2 = Integer.parseInt(dua2);
int yy2 = Integer.parseInt(empat2);
statement.close();
}
catch (Exception ec)
{
System.err.println("silap DataPanel carian11 ");
System.err.println(ec.getMessage());
}
xxmula = xx1;
yymula = yy1;
xxtamat = xx2;
yytamat = yy2;
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g.setColor(Color.black);
int width = 10; g2d.setStroke(new BasicStroke (width));
g2d.drawLine(xxmula, yymula,xxtamat,yytamat);
}
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!