2013-12-17 40 views
0
package Rectangle; 
import java.awt.*; 
import javax.swing.*; 

public class Rectangle extends JFrame { 


    public Rectangle(String arg) { 

     JPanel panel = new JPanel(); enter code here 
     panel.setBackground(Color.BLACK); 
     ImageIcon icon = new ImageIcon(this.getClass().getResource("1676858-livingforest2011.jpg")); 
     JLabel label = new JLabel(); 
     label.setIcon(icon); 
     panel.add(label); 
     this.getContentPane().add(panel); 

     } 
      public static void main(String[] args) { 
      Rectangle forestFrame = new Rectangle(args.length == 0 ? null : args[0]); 
      forestFrame.setSize(1698,770); 
      forestFrame.setVisible(true); 
      new Rectangle("/Users/computerscience2/Desktop/2njk8eq.png").setVisible(true); 



     } 
    } 

它打印出两个Jpanels,一个是我想要的,一个是我不需要的。它还打印出我想要的尺寸,第二个尺寸最小。我如何摆脱第二个Jpanel?当我只需要一个时创建两个JPanel。

+0

用'forestFrame'替换'new Rectangle(“/ Users ... /”)''。 – mostruash

回答

2

您可以通过new运算符创建2个Rectangle对象,该运算符创建2个JPanel实例。 放弃创建其中一个。

相关问题