0
我的輸出多的JLabel與查詢JAVA
192.123.123
123.344.344
152.254.123
,我需要創造3的JLabel , 這是我的代碼,但只有3個Jlabel的第一個輸出和我ne ED三
String val= null;
String sql = "";
sql = "SELECT ipswitch,x,y FROM switch where Act='A'";
try {
com.mysql.jdbc.Statement sta = (com.mysql.jdbc.Statement) cn.createStatement();
ResultSet r = sta.executeQuery(sql);
int contador1=3;
if (r.next() == true) {
for (int i = 0; i < contador1; i++) {
lipe = new javax.swing.JLabel();
lipe.setText(r.getString(1));
paneldesiwtch.add(lipe);
lipe.setBounds(r.getInt(2), r.getInt(3), 100, 40);
green.setLocation(r.getInt(2), r.getInt(3) + 40);
yellow.setLocation(r.getInt(2) + 30, r.getInt(3) + 40);
red.setLocation(r.getInt(2) + 60, r.getInt(3) + 40);
}
} else {
JOptionPane.showMessageDialog(null, "No Found");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e.toString());
}
感謝您的幫助 – user3676851