Hello Everyone,
I am trying to extract integer values from 2 int variables i have created in my database table "mytab". The data or table values i have extracted on console and its working fine. But i want to use the values as x,y coordinate for my label i have created on my frame. I want to display the label "*" at different pixel positions according to the x,y values extracted from sql table. But i am not able to achieve the same. Any help?
import java.sql.*;
import java.io.*;
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.*;
import java.applet.Applet;
import java.awt.Graphics2D;
import java.awt.Point;
import javax.swing.JPanel;
import javax.swing.*;
import java.awt.geom.Point2D;
public class myclass extends JFrame{
public static void main(String[] args)
{int varx,vary;
JLabel textLabel;
JFrame f = new JFrame("Pixel representation");
f.setSize(500,500);
f.setVisible(true);
f.setDefaultLookAndFeelDecorated(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
textLabel = new JLabel("*",SwingConstants.CENTER);
textLabel.setPreferredSize(new Dimension(300, 100));
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:mytab","","");
Statement s = con.createStatement();
s.execute("select * from mytab");
ResultSet rs = s.getResultSet();
if (rs != null)
while (rs.next()) {
varx=rs.getInt(1);
vary=rs.getInt(2);
System.out.println("X: " +varx);
System.out.println("Y: " +vary);
setLocation(varx,vary);
}
f.getContentPane().add(textLabel, BorderLayout.CENTER);
s.close();
con.close();
}
catch (Exception err) {
System.out.println("ERROR: " + err);
}
}
}
ERROR MESSAGE:
37 line: non-static method setLocation(int,int) cannot be referenced from a static context
setLocation(varx,vary);
^
Cheers