I have taken some code
from 'java examples' which is a frame with contained buttons and i
created a main. Only that when I compile it only gives me the fram
without the contained buttons? Can you help?
import javax.swing.*;
import java.awt.*;
public class ContainersButton extends JPanel
{
public static void main(String []args)
{
JFrame frame = new JFrame("ShowContainedButtons");
frame.setTitle("Show contained buttons in frame");
//frame.setDefaultCloseOperation
(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 400);
frame.setVisible(true);
}
public ContainersButton()
{
this.setBackground(Color.white);
this.setFont(new Font("Dialog", Font.BOLD, 24));
JPanel p1 = new JPanel();
p1.setBackground(new Color(200, 200, 200));
this.add(p1);
p1.add(new JButton("#1"));
JPanel p2 = new JPanel();
p2.setBackground(new Color(150, 150, 150));
p1.add(p2);
p2.add(new JButton("#2"));
JPanel p3 = new JPanel();
p3.setBackground(new Color(100, 100, 100));
p2.add(p3);
p3.add(new JButton("#3"));
JPanel p4 = new JPanel();
p4.setBackground(new Color(150, 150, 150));
p1.add(p4);
p4.add(new JButton("#4"));
p4.add(new JButton("#5"));
this.add(new JButton("#6"));
}
}