The problem is here
public Panel()
{
setLayout(null);
JLabel label = new JLabel("Hello");
label.setSize(40,40); label.setLocation(0, 20);
add(label);
MenuBar mb = new MenuBar();
add(mb); // Right here!
}
The whole class
import javax.swing.*;
import java.awt.*;
public class Panel extends JPanel{
/* all drawing methods, fields, labels, and GUI components will
Placed inside of this panel
*/
public Panel()
{
setLayout(null);
JLabel label = new JLabel("Hello");
label.setSize(40,40); label.setLocation(0, 20);
add(label);
MenuBar mb = new MenuBar();
add(mb);
}
public void paint(Graphics g)
{
g.setColor(Color.ORANGE);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.red);
g.drawRect(0, 500, 250, 20);// Recipe's Name
g.drawRect(0, 530, 250, 20);// Author's Name
g.drawRect(0, 560, 250, 20);// Rating Value
g.drawRect(0, 590, 250, 20);// Serving Size
g.setColor(Color.BLACK);
Graphics2D g2 = (Graphics2D) g;
g2.setStroke(new BasicStroke(3));
g2.drawRect(0, 40, 250, getHeight());
g2.drawRect(250, 700, getWidth(), getHeight());
}
}


Sign In
Create Account


Back to top









