java - jbutton id not showing -
I have just created a simple image panel and added a button to the panel
Can the person also tell me the problem in the code?
Image is displayed but no button
Package Inventory Management; Import java.awt.Dimension; Import java.awt.Graphics; Import java.awt.Image; Import javax.swing.JButton; Import javax.swing.ImageIcon; Import javax.swing.JFrame; Import javax.swing.JPanel; Public class imagery {public static zero main (string [] algs) {image panel panel = new image panel (new image ("E: / desktop [/ icon / 647072 9-exclamation mark mark button 3D-red-luminous-cycle .jpg ") getImage ()). Jebton Jebtone 1 = New Jebton ("Jebton 1"); Panel.add (jButton1); Jeffre Frame = New Gefram (); . Frame.getContentPane () add (panel); Frame.pack (); Frame.setVisible (true); }} Square ImagePanel Extended JPanel {Personal Image img; Public ImagePanel (String Image) {This (new IMG (IMG) .getImage ()); } Public imagepanel (image image) {this.img = img; Size of dimension = new dimension (IMG .getWidth (faucet), IMG Gatehite (faucet)); SetPreferredSize (size); SetMinimumSize (size); SetMaximumSize (size); SetSize (size); SetLayout (zero); } Public Zero Paint Component (Graphics G) {g.drawImage (IMG, 0, 0, empty); }}
You have to set a layout for the panel
Just add panel.setLayout (new Java.att.flowout ()); panel.add (jButton1) before adding the button ; .
Comments
Post a Comment