I need help making a button for my panel

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2008
Posts: 1
Reputation: kpp003 is an unknown quantity at this point 
Solved Threads: 0
kpp003 kpp003 is offline Offline
Newbie Poster

I need help making a button for my panel

 
0
  #1
Feb 17th, 2008
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. import java.util.Scanner;
  5.  
  6. public class ExpressionCalculatorPanel extends JPanel
  7. {
  8. // Variables to be used
  9. private JLabel inputLabel, resultLabel;
  10. private JTextField ExpressionCalculator;
  11. private JButton computeButton;
  12.  
  13. //-----------------------------------------------------------------
  14. // Constructor: Sets up the main GUI components.
  15. //-----------------------------------------------------------------
  16. public ExpressionCalculatorPanel()
  17. {
  18. inputLabel = new JLabel ("Enter a value of x");
  19. resultLabel = new JLabel ("Final result = ---");
  20.  
  21. ExpressionCalculator = new JTextField (5);
  22. ExpressionCalculator.addActionListener(new ButtonListener());
  23.  
  24.  
  25. // Set buttons and listeners
  26. computeButton = new JButton("Compute Final Result");
  27. computeButton.addActionListener(new ButtonListener());
  28.  
  29.  
  30. // Add to panels
  31. add (computeButton);
  32. add (inputLabel);
  33. add (resultLabel);
  34.  
  35.  
  36. setPreferredSize (new Dimension(300, 75));
  37. setBackground (Color.white);
  38. }
  39.  
  40. //*****************************************************************
  41. // Represents an action listener for the temperature input field.
  42. //*****************************************************************
  43. private class ButtonListener implements ActionListener
  44. {
  45. //--------------------------------------------------------------
  46. // Performs the conversion when the enter key is pressed in
  47. // the text field.
  48. //--------------------------------------------------------------
  49. public void actionPerformed (ActionEvent event)
  50. {
  51.  
  52. int x, String, Result, Stringresult;
  53.  
  54. //Math.sqrt (Math.pow(x,5)-(2)*Math.pow(x,3)-
  55. // Math.abs(5)*Math.pow(x,2)+(4)*(x));
  56. String stringResult = Double.toString(result);
  57. ExpressionCalculator.setText("Final result:"+ Result);
  58.  
  59.  
  60. }
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,842
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 503
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: I need help making a button for my panel

 
0
  #2
Feb 17th, 2008
What problem(s) are you having? What is it not doing that you intend it to do? What does it do that you don't want it to do? What works? Please be more specific.
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
Other Threads in the Java Forum


Views: 493 | Replies: 1
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC