아래 코드와 같이 데이터베이스의 x와 y 값을 가져옵니다. 그리고 배열 x
에 저장하십시오. 그 후 프레임에이 선을 그리려고하지만 그려지지 않습니다. 어떻게 프레임에 선을 그릴 수 있습니까?왜 선을 그릴 수 없나요? JFrame에
public class TestFrame{
static JFrame test;
public static void main(String ar[]){
test=new JFrame("Test");
JButton openLine=new JButton(new AbstractAction("Open Line"){
public void actionPerformed(ActionEvent e) {
String lineId=JOptionPane.showInputDialog("Enter Line id");
ImageComponent image=new ImageComponent();
image.openLine(lineId);
}
});
test.add(openLine, BorderLayout.NORTH);
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
test.setSize(600,600);
test.setVisible(true);
}
static class ImageComponent extends JComponent{
static int[] x=new int[100];
static ArrayList al=new ArrayList();
public void openLine(String line_id){
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:image");
Statement pstm=con.createStatement();
ResultSet rs=pstm.executeQuery("select * from Line where ID= '"+line_id+"'");
while(rs.next()){
x[0]=rs.getInt(3);
x[1]=rs.getInt(4);
x[2]=rs.getInt(5);
x[3]=rs.getInt(6);
al.add(x);
}
repaint();
} catch (Exception ex) {
System.out.println("Exception : "+ex);
}
}
public Graphics2D gd;
Line2D[] line=new Line2D[100];
protected void paintComponent(Graphics g) {
super.paintComponent(g);
gd=(Graphics2D)g;
gd.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
for(int i=0;i<al.size();i++){
line[i]=new Line2D.Double(x[0], x[1],x[2],x[3]);
gd.draw(line[i]);
}
}
}
}
미안하지만, 당신의 요점을 얻지 못했습니다 ... – Parth
음 ... 대체 할 수있는 ' 프레임 '을'이미지에 선을 그립니다 (그리고 원하는 경우 프레임에 넣으십시오) '하고 작동하는 (애니메이션으로 된) 예제가 있습니다. 코드를 실행 해 보셨습니까? –