Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

learning examples

  Asked By: Nichole    Date: Dec 14    Category: Java    Views: 733
  

I'm trying to get this program to run which i used from java examples
and i created a main for it. Although the compiler only runs the
frame and not the contained buttons. Can anyone help a learner?

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"));


}
}

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on learning examples Or get search suggestion and latest updates.




Tagged: