| | |
Recognizing when a button is pressed.
![]() |
•
•
Join Date: Jul 2005
Posts: 5
Reputation:
Solved Threads: 0
I really appreciate all the help i've been getting on my project lately from you guys, and hopefully this will be the last problem.
I've written an applet, and it uses ActionListener to detect when the button is pressed. The program is supposed to go through my methods when the button is pressed. However when i launch the applet and put values in the boxes, nothing happens when i click. Using an embedded class is too hard for me (i've been doing java for 5 weeks, and the only prior experience i had was html). Also i can't seem to make two seperate files, because only one can implement ActionListener.
here's what i have so far.
making the button -
running my methods when i click the button -
I've written an applet, and it uses ActionListener to detect when the button is pressed. The program is supposed to go through my methods when the button is pressed. However when i launch the applet and put values in the boxes, nothing happens when i click. Using an embedded class is too hard for me (i've been doing java for 5 weeks, and the only prior experience i had was html). Also i can't seem to make two seperate files, because only one can implement ActionListener.
here's what i have so far.
making the button -
Java Syntax (Toggle Plain Text)
enter = new JButton("Click here to calculate numeric palindrome."); enter.addActionListener(this);
running my methods when i click the button -
Java Syntax (Toggle Plain Text)
public void actionPerformed(ActionEvent e) { Numtemp = displayN.getText(); Base = displayB.getText(); convert(); FindPalindrome(); reconvert(); print(); }
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 7
Hi everyone,
I have no idea the number of JButtons in your application but where's the source??
Try this
I hope this helps you
Yours Sincerely
Richard West
I have no idea the number of JButtons in your application but where's the source??
Try this
Java Syntax (Toggle Plain Text)
public void actionPerformed(ActionEvent e) { JButton B = (JButton)e.getSource(); if(B == enter) Numtemp = displayN.getText(); Base = displayB.getText(); convert(); FindPalindrome(); reconvert(); print(); } }
I hope this helps you
Yours Sincerely
Richard West
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
•
•
Join Date: Jul 2005
Posts: 5
Reputation:
Solved Threads: 0
Thanks for responding. I took that code and adapted it to my code, and it compiles, but i still have the same problem. Here is all of the relevant code. Oh and there is only one button.
Java Syntax (Toggle Plain Text)
public void init() { displayN = new JTextField(35); displayN.setFont(new Font("Monospaced", Font.BOLD, 14)); String message1 = "Enter Number Here"; displayN.setText(message1); displayB = new JTextField(15); displayB.setFont(new Font("Monospaced", Font.BOLD, 14)); String message2 = "Enter Base Here"; displayB.setText(message2); enter = new JButton("Click here to calculate numeric palindrome."); enter.addActionListener(this); displayS = new JTextField(60); displayS.setFont(new Font("Monospaced", Font.BOLD, 14)); Container c = getContentPane(); c.setLayout(new FlowLayout()); c.setBackground(Color.darkGray); c.add(displayN); c.add(displayB); c.add(enter); c.add(displayS); } //This tells the program to run when the button is clicked. Help for this code came from //freesoft_2000 at the www.daniweb.com/techtalkforums public void actionPerformed(ActionEvent e) { JButton B = (JButton)e.getSource(); if(B == enter) { Numtemp = displayN.getText(); Base = displayB.getText(); convert(); FindPalindrome(); reconvert(); print(); } }
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
Debugging 101: Put some system.out.println()'s throughout the actionPerformed() method, and all methods it calls. check to make sure all variables have the proper values, and that it even enters certain methods.
By the way, what are you doing with these lines:
Numtemp = displayN.getText();
Base = displayB.getText();
If those are used in the coorisponding methods called, I would suggest passing them as parameters instead.
By the way, what are you doing with these lines:
Numtemp = displayN.getText();
Base = displayB.getText();
If those are used in the coorisponding methods called, I would suggest passing them as parameters instead.
![]() |
Similar Threads
- Problem changing contents of JTable when button is pressed... (Java)
- URGENT!: Saving Database information from ASP.NET Button (ASP.NET)
- Gettig delphi to wait for a button press before continuing (Pascal and Delphi)
- Help in printing mulitple documents using print button (Java)
Other Threads in the Java Forum
- Previous Thread: help with Java
- Next Thread: securing code on a webserver
| Thread Tools | Search this Thread |
account android api applet application array arrays automation bidirectional binary birt bluetooth class classes client code columns component constructor database designadrawingapplicationusingjavajslider draw eclipse error errors exception expand fractal game givemetehcodez graphics gui guidancer homework html ide image inetaddress inheritance integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jlabel jme jni jpanel jtextfield jtree julia linux list loop map method methods midlethttpconnection mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source oracle plazmic print problem program project property recursion ria scanner search server set sharepoint smart sms smsspam sort sourcelabs splash sql sqlite static string subclass support swing testautomation threads tree unlimited webservices windows






