| | |
handeling button
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2008
Posts: 40
Reputation:
Solved Threads: 0
I've written a code for JButton handeling.The code is=
But getting the following errors while compiling it.
java Syntax (Toggle Plain Text)
import javax.swing.*; import java.awt.*; import java.util.Calendar; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; // Example using defaultButton and JRootPane.setDefaultButton() public class DefaultButtonExample { public static void main(String[] args) { // Create some buttons JButton ok = new JButton("OK"); JButton cancel = new JButton("Cancel"); JPanel buttonPanel = new JPanel(); buttonPanel.add(ok); buttonPanel.add(cancel); Calendar cl=Calendar.getInstance(); int i=cl.get(Calendar.YEAR); int j=cl.get(Calendar.MONTH); String a="001"; i=i%100; String p=Integer.toString(i); String q=Integer.toString(j); if(p.length()==1) p=0+p; if(q.length()==1) q=0+q; String r=p+q+a; public void actionPerformed(ActionEvent ae){ String str=ae.getActionCommand(); if(str.equals("ok")) { int b=Integer.parseInt(a); b++; String a1=Integer.toString(b); if(a1.length()==1) a1=00+a1; if(a1.length()==2) a1=0+a1; r=p+q+a1; JLabel msg = new JLabel("visitor ID="+r, JLabel.CENTER); // Create a frame, get its root pane, and set the "ok" button as the // default. This button will be "pressed" if we hit <ENTER> while the // frame has focus. JFrame f = new JFrame(); //f.addWindowListener(new BasicWindowMonitor()); JRootPane root = f.getRootPane(); root.setDefaultButton(ok); // Layout and Display Container content = f.getContentPane(); content.setLayout(new BorderLayout()); content.add(msg, BorderLayout.CENTER); content.add(buttonPanel, BorderLayout.SOUTH); f.setSize(200,100); f.setVisible(true); } }
But getting the following errors while compiling it.
Last edited by Tekmaven; Jun 11th, 2009 at 11:00 pm. Reason: Code Tags
![]() |
Similar Threads
- Button to open a new browser window (ASP.NET)
- The name for the Resize Button to ad to Script (HTML and CSS)
- monitor power button not responding (Monitors, Displays and Video Cards)
- how can I change start page & recover the general page button to change (Web Browsers)
- [Tweak] Renaming your Start Button (Windows tips 'n' tweaks)
- Random Restarts (Windows NT / 2000 / XP)
- help please cannot use search button on ie6 (Web Browsers)
Other Threads in the Java Forum
- Previous Thread: Reading from File
- Next Thread: SetHorizontalTextPosition on a JLabel won't work
| Thread Tools | Search this Thread |
Tag cloud for Java
actionlistener android api apple applet application apps arguments array arrays automation balls binary bluetooth card chat class classes client code component consumer database draw eclipse error event exception file fractal free game gameprogramming gis givemetehcodez graphics gui helpwithhomework html ide image input integer j2me j2seprojects java javaprojects jmf jni jpanel julia jvm key linux list loop machine map method methods migrate mobile mobiledevelopmentcreatejar myaggfun netbeans newbie nextline nls number oracle output print problem program programming project recursion recursive scanner screen security server set size sms socket sort spamblocker sql sqlite string sun swing terminal test threads time tree trolltech windows






