Results 1 to 6 of 6

Thread: jpanel

  1. #1
    mharsijamel is offline Member
    Join Date
    Aug 2011
    Posts
    60
    Rep Power
    0

    Default jpanel

    when i made a class that extends Jpanel it works
    but now, i have another extends so i want to know what i should to do to use jpanel in a jframe(without extends Jpanel) and to show them(from void main or a call of a method)
    please help me

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: jpanel

    Favor composition over inheritance. Your class can have any number of JFrames/JPanels whatever as static or instance members, or local variables.

    Extending a class is done to add/modify state or behavior. Not just for use.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    mharsijamel is offline Member
    Join Date
    Aug 2011
    Posts
    60
    Rep Power
    0

    Default Re: jpanel

    please give me an example of class that contains jpanel + its call

  4. #4
    mharsijamel is offline Member
    Join Date
    Aug 2011
    Posts
    60
    Rep Power
    0

    Default Re: jpanel

    i still in wait of example : java class without extends that contains a jframe and a jpanel at least

  5. #5
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    299
    Rep Power
    4

    Default Re: jpanel

    Ok, if I understand you right, following VERY simple example might help.

    Java Code:
    import javax.swing.JPanel; 
    import javax.swing.JFrame;   
    
    class Example {
    	
    	JFrame frame;
    	JPanel panel;
    	
    	public Example(){
    		frame = new JFrame();
    		panel = new JPanel();
    		frame.add(panel);
    		frame.setVisible(true);
    	}
    	
    	public static void main(String[] args) {   
    		new Example();
    	}
    }

  6. #6
    mharsijamel is offline Member
    Join Date
    Aug 2011
    Posts
    60
    Rep Power
    0

Similar Threads

  1. Replies: 1
    Last Post: 12-13-2011, 02:38 AM
  2. Change JPanel text of Parent JPanel from JDialog
    By bikashlama in forum AWT / Swing
    Replies: 7
    Last Post: 12-09-2011, 03:47 AM
  3. Adding a jpanel to a customized Jpanel Class
    By trishtren in forum AWT / Swing
    Replies: 7
    Last Post: 04-05-2011, 06:52 PM
  4. Placing a new JPanel over a paint overriden JPanel
    By Tanshaydar in forum AWT / Swing
    Replies: 4
    Last Post: 12-08-2010, 06:00 PM
  5. Replies: 3
    Last Post: 04-20-2009, 11:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •