Tuesday 15 July 2014

add Objects to jframe java -


I created my package in two classes called ball and hat. And I want to add them to crush in my third grade JFrame I did but when I use the container, the objects were not displayed in Jeffreme and only one of them was added to the JFrame without the container. Here is my code:

  package matry; Import java.awt. *; Import java.awt.event. *; Import java.util.ArrayList; Import javax.swing *; Public class triple zephyr (JFrame frame = new JFrame ()) increases; Container Panel = New Container (); Public triplell () {toop c = new toop (); Ball a = new ball (2020,1); Frame.setVisible (true); Frame.setSize (550550); Frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); Panel.add (c); Panel.add (a); . Frame.getContentPane () add (panel); C.run (); }}   

How can I add my classes to the JFrame ??

Because your class increases JFrame, this line should be deleted:

  JFrame frame = new JFrame ();   

This means that all references to frames should also be removed, or it should be replaced.

Instead of using the container you want to use the zenal, so replace it line:

  container panel = new container ();   

to

  jpial panel = new zpn ();   

And in this way add frames to the panel in the constructor:

  this.add (panel); Instead of using frame.getContentPane (),   

Add (panel);

This should work, even if I have not tried your code.

You can also use the layout manager with JPNL to ensure the right layout of things.

No comments:

Post a Comment