| | |
handeling button
![]() |
•
•
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 |
911 addball addressbook android api append applet application apps array arrays automation binary bluetooth businessintelligence button card chat class client code collision component crashcourse css csv database eclipse ee error fractal free game gis givemetehcodez graphics gui html ide image input integer integration j2me japplet java javaarraylist javadoc javafx javaprojects jni jpanel julia jvm linux list loan loop machine map method methods migrate mobile netbeans newbie objects oriented output panel phone physics problem program programming project radio recursion reporting scanner se server service set sms socket software sort sql string swing test textfield threads transfer tree trolltech ubuntu utility windows






