开发者

Typecast String to JLayeredPane

开发者 https://www.devze.com 2023-02-18 21:08 出处:网络
Is there a way to typecast String type to JLayeredPane? Following is the code I am using: private static void build_tables() {

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


JLayeredPane JL = (JLayeredPane)rs.getObject("parent_floor");

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 a JLabel using the string returned from the database query and then you add the label to the panel.

Something like:

String text = rs.getObject("parent_floor").toString();
JLabel label = new JLabel( text );
panel.add(label);
0

精彩评论

暂无评论...
验证码 换一张
取 消