By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,648 Members | 1,489 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,648 IT Pros & Developers. It's quick & easy.

create buttons with jpanel

P: 59
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.
**


Expand|Select|Wrap|Line Numbers
  1.     public class Main extends JFrame{
  2.  
  3.         public Main() {
  4.             // TODO Auto-generated constructor stub
  5.         }
  6.  
  7.         public static void main(String[] args){
  8.             aaaa a = new aaaa(); //??
  9.         }
  10.     }
  11.  
  12.  
  13.  
  14.  
  15.     public class aaaa extends JFrame{    //???
  16.  
  17.         public aaaa() {
  18.             bbbb b = new bbbb(); //??
  19.         }
  20.     }
  21.  
  22.  
  23.  
  24.  
  25.  
  26.     public class bbbb implements ActionListener{  //????
  27.  
  28.         JButton b1 = new JButton("check here");
  29.  
  30.         public bbbb() {
  31.             //??
  32.         }
  33.  
  34.  
  35.     public void actionPerformed(ActionEvent e) {
  36.  
  37.     }
  38.     }
  39.  
  40.  
Jun 5 '13 #1
Share this Question
Share on Google+
1 Reply


10K+
P: 13,264
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
Jun 11 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.