create buttons with jpanel

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • game2d
    New Member
    • Apr 2013
    • 59

    create buttons with jpanel

    i can some one help me with jframe and panel. i want to create button using jpanel. i look online but they seem to have different ways to do it and i have no idea which is the best way to do this. ex some people extends jframe at top. other create jframe j = new jframe in main etc...

    This is what iam trying to do. dont worry about my logic here. this is just so i can understand how to extends etc....
    **
    main.java will call aaaa.java.
    aaaa.java will call bbbb.java
    bbbb.java will create one button and that button will have a actionlistener.
    **


    Code:
        public class Main extends JFrame{
        
        	public Main() {
        		// TODO Auto-generated constructor stub
        	}
        	
        	public static void main(String[] args){
        		aaaa a = new aaaa(); //??
        	}
        }
        
        
        
        
        public class aaaa extends JFrame{    //???
        
        	public aaaa() {
        		bbbb b = new bbbb(); //??
        	}
        }
        
        
        
        
        
        public class bbbb implements ActionListener{  //????
        
            JButton b1 = new JButton("check here");
        	
            public bbbb() {
        		//??
        	}
        
        
        public void actionPerformed(ActionEvent e) {
        
        }
        }
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    You rarely need to extend JFrame. Most code that extends JFrame does so for bad reasons.
    You can read more general swing tips here: http://bytes.com/topic/java/insights...ng-swing-right

    Comment

    Working...