handeling button

Reply

Join Date: Aug 2008
Posts: 40
Reputation: coolbuddy059 has a little shameless behaviour in the past 
Solved Threads: 0
coolbuddy059 coolbuddy059 is offline Offline
Light Poster

handeling button

 
0
  #1
Jun 11th, 2009
I've written a code for JButton handeling.The code is=
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.util.Calendar;
  4. import java.awt.event.ActionListener;
  5. import java.awt.event.ActionEvent;
  6.  
  7. // Example using defaultButton and JRootPane.setDefaultButton()
  8. public class DefaultButtonExample {
  9.  
  10.  
  11. public static void main(String[] args) {
  12. // Create some buttons
  13. JButton ok = new JButton("OK");
  14. JButton cancel = new JButton("Cancel");
  15. JPanel buttonPanel = new JPanel();
  16. buttonPanel.add(ok);
  17. buttonPanel.add(cancel);
  18.  
  19. Calendar cl=Calendar.getInstance();
  20. int i=cl.get(Calendar.YEAR);
  21. int j=cl.get(Calendar.MONTH);
  22. String a="001";
  23. i=i%100;
  24. String p=Integer.toString(i);
  25. String q=Integer.toString(j);
  26.  
  27. if(p.length()==1)
  28. p=0+p;
  29. if(q.length()==1)
  30. q=0+q;
  31. String r=p+q+a;
  32. public void actionPerformed(ActionEvent ae){
  33. String str=ae.getActionCommand();
  34. if(str.equals("ok"))
  35. {
  36. int b=Integer.parseInt(a);
  37. b++;
  38. String a1=Integer.toString(b);
  39. if(a1.length()==1)
  40. a1=00+a1;
  41. if(a1.length()==2)
  42. a1=0+a1;
  43. r=p+q+a1;
  44.  
  45.  
  46.  
  47. JLabel msg = new JLabel("visitor ID="+r, JLabel.CENTER);
  48.  
  49.  
  50. // Create a frame, get its root pane, and set the "ok" button as the
  51. // default. This button will be "pressed" if we hit <ENTER> while the
  52. // frame has focus.
  53. JFrame f = new JFrame();
  54. //f.addWindowListener(new BasicWindowMonitor());
  55. JRootPane root = f.getRootPane();
  56. root.setDefaultButton(ok);
  57. // Layout and Display
  58. Container content = f.getContentPane();
  59.  
  60. content.setLayout(new BorderLayout());
  61. content.add(msg, BorderLayout.CENTER);
  62. content.add(buttonPanel, BorderLayout.SOUTH);
  63. f.setSize(200,100);
  64. f.setVisible(true);
  65.  
  66.  
  67. }
  68. }




But getting the following errors while compiling it.
Last edited by Tekmaven; Jun 11th, 2009 at 11:00 pm. Reason: Code Tags
Attached Thumbnails
12345.JPG  
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,444
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 510
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: handeling button

 
0
  #2
Jun 11th, 2009
You can't write methods in the middle of other methods.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC