Ok so i have a program using JFrame when ever i add more than 2 classes in the frame one disappears? How can i add more than 1 class with one of them to dissappear?

Tester Class

public class TestYourFace
{
 
 public static void main(String args[]) {
      JFrame frame = new JFrame();
      frame.setSize(850,850);      
      frame.setTitle("Choose YOUR Features?");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      Face1 Component = new Face1();
      Hair1 Component2 = new Hair1();
      frame.add(Component);
      frame.add(Component2);
      frame.setVisible(true);
  }
}

Classes i want to combine under 1 Frame

Class1

public class Face1 extends JComponent
{
    Shape Head = new Ellipse2D.Float(0, 50, 0, 150);
    public void paint(Graphics g) 
    {
        Graphics2D g2 = (Graphics2D)g;
    
        int Red1 =  205;
        int Green1 = 175;
        int Blue1 =  149;
        Color lightBrown = new Color(Red1, Green1, Blue1);
        
        g2.setColor(lightBrown);
        g2.fill(Head);
    }
}

Class2

public class Hair1 extends JComponent
{
    Shape Hair = new Rectangle2D.Float(0, 0, 50, 50);
    public void paint(Graphics g) 
    {
        Graphics2D g2 = (Graphics2D)g;
    
        int Red1 =  205;
        int Green1 = 175;
        int Blue1 =  149;
        Color lightBrown = new Color(Red1, Green1, Blue1);
        
        g2.setColor(lightBrown);
        g2.fill(Hair);
    }
}

Recommended Answers

All 2 Replies

You need to study how layout managers work. Each container (like a JFrame) uses a layout manager. The layout manager controls where components that are added to the container are positioned.

Try the tutorials: http://download.oracle.com/javase/tutorial/reallybigindex.html

Go to the above and Find layout

commented: its really big :P +7
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.