#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    65
    Rep Power
    2

    Button using javaX...


    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(); //??
        	}
        }



    Code:
     public class aaaa extends JFrame{    //???
        
        	public aaaa() {
        		bbbb b = new bbbb(); //??
        	}
        }



    Code:
        
        public class bbbb implements ActionListener{  //????
        
            JButton b1 = new JButton("check here");
        	
            public bbbb() {
        		//??
        	}
        
        
        public void actionPerformed(ActionEvent e) {
        
        }
        }
    Last edited by game2d; June 5th, 2013 at 09:49 AM.
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348
    Can you explain what you are trying to do?
    How many windows do you want to be shown?
    What component(s) do you want shown in those windows?

    Please wrap your code in code tags:
    [code]
    your code here
    [/code]
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    65
    Rep Power
    2
    just one window. i want to:

    create one window.
    add jframe on to window.
    add jpanel to jframe.
    add button to jpanel.
    add actionlistion to button

    create window and jframe in main class only.
    create jpanel, button and actionlistion in bbbb.java class.

    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.
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348
    add jframe on to window.
    Does that mean there are to be two windows open at the same time?

    The button must be added to the panel and the panel added to the window. The listener can be added to the button anytime after the button object is created.

    See the tutorial for how to build a GUI:: http://docs.oracle.com/javase/tutorial/uiswing/index.html

    There must be many code samples on forums that show how to do this.

IMN logo majestic logo threadwatch logo seochat tools logo