Reputation: 27
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);
}
}
It prints out two Jpanels, one that I want and one that I don't. It also prints out the one that I want the size that I want and the second one is the smallest it can be. How do I get rid of the second Jpanel?
Upvotes: 0
Views: 41
Reputation: 25950
You create 2 Rectangle
objects via new
operator, which creates 2 JPanel
instances.
Abandon creating one of them.
Upvotes: 2