将字符串类型转换为 JLayeredPane
有没有办法将 String
类型转换为 JLayeredPane
?以下是我正在使用的代码:
private static void build_tables() {
String sql="SELECT * FROM pos_tables WHERE pos_company_id='"
+global_variables.company_id
+"' AND shop_type='"
+global_variables.shop_type
+"'";
if(mysql_query.count_mysqls(variables.con.conn, sql)>0){
try {
ResultSet rs = mysql_query.execute_mysql(variables.con.conn, sql);
while (rs.next()) {
JLayeredPane JL = (JLayeredPane)rs.getObject("parent_floor");
tablesetup.addButton(rs.getString("table_name"),
Integer.parseInt(rs.getString("x")),
Integer.parseInt(rs.getString("y")), JL);
}
} catch (SQLException ex) {
Logger.getLogger(builder.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
我收到以下错误:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to javax.swing.JLayeredPane
Is there a way to typecast String
type to JLayeredPane
? Following is the code I am using:
private static void build_tables() {
String sql="SELECT * FROM pos_tables WHERE pos_company_id='"
+global_variables.company_id
+"' AND shop_type='"
+global_variables.shop_type
+"'";
if(mysql_query.count_mysqls(variables.con.conn, sql)>0){
try {
ResultSet rs = mysql_query.execute_mysql(variables.con.conn, sql);
while (rs.next()) {
JLayeredPane JL = (JLayeredPane)rs.getObject("parent_floor");
tablesetup.addButton(rs.getString("table_name"),
Integer.parseInt(rs.getString("x")),
Integer.parseInt(rs.getString("y")), JL);
}
} catch (SQLException ex) {
Logger.getLogger(builder.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
I am getting the following error:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to javax.swing.JLayeredPane
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
数据库不包含
JLayeredPane
对象。它包含一个字符串。你想做什么?为什么要使用
JLayeredPane
?只需使用
JPanel
即可。然后,您可以使用从数据库查询返回的字符串创建一个JLabel
,然后将标签添加到面板中。像这样的东西:
A database doesn't contain
JLayeredPane
objects. It contains a string.What are you trying to do? Why are you using a
JLayeredPane
?Just use a
JPanel
. Then you can create aJLabel
using the string returned from the database query and then you add the label to the panel.Something like: