| | |
I need help making a button for my panel
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Feb 2008
Posts: 1
Reputation:
Solved Threads: 0
Java Syntax (Toggle Plain Text)
import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.Scanner; public class ExpressionCalculatorPanel extends JPanel { // Variables to be used private JLabel inputLabel, resultLabel; private JTextField ExpressionCalculator; private JButton computeButton; //----------------------------------------------------------------- // Constructor: Sets up the main GUI components. //----------------------------------------------------------------- public ExpressionCalculatorPanel() { inputLabel = new JLabel ("Enter a value of x"); resultLabel = new JLabel ("Final result = ---"); ExpressionCalculator = new JTextField (5); ExpressionCalculator.addActionListener(new ButtonListener()); // Set buttons and listeners computeButton = new JButton("Compute Final Result"); computeButton.addActionListener(new ButtonListener()); // Add to panels add (computeButton); add (inputLabel); add (resultLabel); setPreferredSize (new Dimension(300, 75)); setBackground (Color.white); } //***************************************************************** // Represents an action listener for the temperature input field. //***************************************************************** private class ButtonListener implements ActionListener { //-------------------------------------------------------------- // Performs the conversion when the enter key is pressed in // the text field. //-------------------------------------------------------------- public void actionPerformed (ActionEvent event) { int x, String, Result, Stringresult; //Math.sqrt (Math.pow(x,5)-(2)*Math.pow(x,3)- // Math.abs(5)*Math.pow(x,2)+(4)*(x)); String stringResult = Double.toString(result); ExpressionCalculator.setText("Final result:"+ Result); }
![]() |
Similar Threads
- Can't access control panel at all (Viruses, Spyware and other Nasties)
- control panel won't open and can't remove hacktool.root kit (Viruses, Spyware and other Nasties)
- HELP pls, making a Login form. (Visual Basic 4 / 5 / 6)
- System Tray Notification/No Control Panel Access (Viruses, Spyware and other Nasties)
- Resizing output window (Java)
- gateway solo 9550 (Cases, Fans and Power Supplies)
- cPanel: email account creation. I need help making a PHP script. (PHP)
- New Thread button hard to find? (DaniWeb Community Feedback)
- Buttons problem (Java)
- CD Rom Drive Keeps opening and closing (Storage)
Other Threads in the Java Forum
- Previous Thread: Converting boolean to integer
- Next Thread: arrayList indexOf
Views: 493 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application arguments array arrays automation binary bluetooth c# capture chat chatprogramusingobjects class classes client code color component count database draw eclipse eclipsedevelopment encryption error event exception file fractal game givemetehcodez graphics gridlayout gui helpwithhomework high html ide if_statement image input integer interface j2me java javadesktopapplications javaprojects jmf jni jpanel julia keyword linux list loop macintosh map method methods mobile multithreading netbeans newbie number object oracle os print problem producer program programming project projectideas read recursion replaysolutions scanner screen server set size sms socket sort sql string swing test threads time transfer transforms tree ui unicode windows






