Created
January 25, 2016 11:35
-
-
Save ahmedengu/336e0bb7ab37835d9252 to your computer and use it in GitHub Desktop.
a expression evaluation using ScriptEngineManager ( JavaScript ) java , with a swing GUI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" ?> | |
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> | |
<Properties> | |
<Property name="defaultCloseOperation" type="int" value="3"/> | |
<Property name="title" type="java.lang.String" value="Discreet"/> | |
</Properties> | |
<SyntheticProperties> | |
<SyntheticProperty name="formSizePolicy" type="int" value="1"/> | |
<SyntheticProperty name="generateCenter" type="boolean" value="false"/> | |
</SyntheticProperties> | |
<AuxValues> | |
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> | |
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> | |
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> | |
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/> | |
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/> | |
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/> | |
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> | |
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> | |
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> | |
</AuxValues> | |
<Layout> | |
<DimensionLayout dim="0"> | |
<Group type="103" groupAlignment="0" attributes="0"> | |
<Group type="102" alignment="0" attributes="0"> | |
<EmptySpace max="-2" attributes="0"/> | |
<Component id="jPanel1" max="32767" attributes="0"/> | |
<EmptySpace max="-2" attributes="0"/> | |
</Group> | |
</Group> | |
</DimensionLayout> | |
<DimensionLayout dim="1"> | |
<Group type="103" groupAlignment="0" attributes="0"> | |
<Group type="102" alignment="0" attributes="0"> | |
<EmptySpace max="-2" attributes="0"/> | |
<Component id="jPanel1" max="32767" attributes="0"/> | |
<EmptySpace max="-2" attributes="0"/> | |
</Group> | |
</Group> | |
</DimensionLayout> | |
</Layout> | |
<SubComponents> | |
<Container class="javax.swing.JPanel" name="jPanel1"> | |
<Properties> | |
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor"> | |
<Border info="org.netbeans.modules.form.compat2.border.SoftBevelBorderInfo"> | |
<BevelBorder/> | |
</Border> | |
</Property> | |
</Properties> | |
<Layout> | |
<DimensionLayout dim="0"> | |
<Group type="103" groupAlignment="0" attributes="0"> | |
<Group type="102" alignment="1" attributes="0"> | |
<EmptySpace min="0" pref="0" max="32767" attributes="0"/> | |
<Component id="jTextField1" min="-2" pref="125" max="-2" attributes="0"/> | |
<EmptySpace min="-2" pref="58" max="-2" attributes="0"/> | |
</Group> | |
<Group type="102" attributes="0"> | |
<Group type="103" groupAlignment="0" attributes="0"> | |
<Group type="102" alignment="0" attributes="0"> | |
<EmptySpace min="-2" pref="59" max="-2" attributes="0"/> | |
<Component id="jButton1" min="-2" pref="175" max="-2" attributes="0"/> | |
</Group> | |
<Group type="102" alignment="0" attributes="0"> | |
<EmptySpace min="-2" pref="29" max="-2" attributes="0"/> | |
<Group type="103" groupAlignment="0" max="-2" attributes="0"> | |
<Group type="102" attributes="0"> | |
<Component id="jLabel4" min="-2" max="-2" attributes="0"/> | |
<EmptySpace min="-2" pref="32" max="-2" attributes="0"/> | |
<Component id="jTextField4" min="-2" pref="165" max="-2" attributes="0"/> | |
</Group> | |
<Component id="jPanel2" alignment="0" max="32767" attributes="0"/> | |
<Group type="102" attributes="0"> | |
<Group type="103" groupAlignment="0" attributes="0"> | |
<Component id="jTextField2" alignment="1" min="-2" pref="76" max="-2" attributes="0"/> | |
<Group type="102" alignment="0" attributes="0"> | |
<EmptySpace min="-2" pref="10" max="-2" attributes="0"/> | |
<Component id="jLabel2" min="-2" max="-2" attributes="0"/> | |
<EmptySpace min="12" pref="12" max="-2" attributes="0"/> | |
</Group> | |
</Group> | |
<EmptySpace max="32767" attributes="0"/> | |
<Component id="jSeparator3" min="-2" pref="15" max="-2" attributes="0"/> | |
<EmptySpace min="-2" pref="27" max="-2" attributes="0"/> | |
<Group type="103" groupAlignment="0" attributes="0"> | |
<Component id="jTextField3" alignment="1" min="-2" pref="72" max="-2" attributes="0"/> | |
<Group type="102" alignment="0" attributes="0"> | |
<Component id="jLabel3" min="-2" max="-2" attributes="0"/> | |
<EmptySpace min="-2" pref="13" max="-2" attributes="0"/> | |
</Group> | |
</Group> | |
</Group> | |
</Group> | |
</Group> | |
<Group type="102" alignment="0" attributes="0"> | |
<EmptySpace min="-2" pref="130" max="-2" attributes="0"/> | |
<Component id="jLabel1" min="-2" max="-2" attributes="0"/> | |
</Group> | |
<Group type="102" alignment="0" attributes="0"> | |
<EmptySpace min="-2" pref="82" max="-2" attributes="0"/> | |
<Group type="103" groupAlignment="0" attributes="0"> | |
<Component id="jSeparator2" alignment="0" min="-2" pref="131" max="-2" attributes="0"/> | |
<Component id="jSeparator1" min="-2" pref="125" max="-2" attributes="0"/> | |
</Group> | |
</Group> | |
</Group> | |
<EmptySpace max="32767" attributes="0"/> | |
</Group> | |
</Group> | |
</DimensionLayout> | |
<DimensionLayout dim="1"> | |
<Group type="103" groupAlignment="0" attributes="0"> | |
<Group type="102" alignment="0" attributes="0"> | |
<EmptySpace max="-2" attributes="0"/> | |
<Component id="jLabel1" min="-2" max="-2" attributes="0"/> | |
<EmptySpace max="-2" attributes="0"/> | |
<Component id="jTextField1" min="-2" max="-2" attributes="0"/> | |
<EmptySpace type="separate" max="-2" attributes="0"/> | |
<Group type="103" groupAlignment="1" attributes="0"> | |
<Group type="102" attributes="0"> | |
<Group type="103" groupAlignment="3" attributes="0"> | |
<Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/> | |
<Component id="jLabel3" alignment="3" min="-2" max="-2" attributes="0"/> | |
</Group> | |
<EmptySpace max="-2" attributes="0"/> | |
<Group type="103" groupAlignment="3" attributes="0"> | |
<Component id="jTextField2" alignment="3" min="-2" max="-2" attributes="0"/> | |
<Component id="jTextField3" alignment="3" min="-2" max="-2" attributes="0"/> | |
</Group> | |
</Group> | |
<Component id="jSeparator3" min="-2" pref="28" max="-2" attributes="0"/> | |
</Group> | |
<EmptySpace max="-2" attributes="0"/> | |
<Component id="jButton1" min="-2" max="-2" attributes="0"/> | |
<EmptySpace type="separate" max="-2" attributes="0"/> | |
<Component id="jSeparator1" min="-2" pref="10" max="-2" attributes="0"/> | |
<EmptySpace min="-2" pref="5" max="-2" attributes="0"/> | |
<Group type="103" groupAlignment="3" attributes="0"> | |
<Component id="jTextField4" alignment="3" min="-2" max="-2" attributes="0"/> | |
<Component id="jLabel4" alignment="3" min="-2" max="-2" attributes="0"/> | |
</Group> | |
<EmptySpace type="separate" max="-2" attributes="0"/> | |
<Component id="jSeparator2" min="-2" pref="10" max="-2" attributes="0"/> | |
<EmptySpace max="-2" attributes="0"/> | |
<Component id="jPanel2" min="-2" max="-2" attributes="0"/> | |
<EmptySpace max="32767" attributes="0"/> | |
</Group> | |
</Group> | |
</DimensionLayout> | |
</Layout> | |
<SubComponents> | |
<Component class="javax.swing.JLabel" name="jLabel1"> | |
<Properties> | |
<Property name="text" type="java.lang.String" value="formula"/> | |
</Properties> | |
</Component> | |
<Component class="javax.swing.JTextField" name="jTextField1"> | |
<Properties> | |
<Property name="text" type="java.lang.String" value="x+x"/> | |
<Property name="toolTipText" type="java.lang.String" value="use x to be change in the range"/> | |
</Properties> | |
<Events> | |
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jTextField1ActionPerformed"/> | |
</Events> | |
</Component> | |
<Component class="javax.swing.JLabel" name="jLabel2"> | |
<Properties> | |
<Property name="text" type="java.lang.String" value="range start"/> | |
</Properties> | |
</Component> | |
<Component class="javax.swing.JLabel" name="jLabel3"> | |
<Properties> | |
<Property name="text" type="java.lang.String" value="range end"/> | |
</Properties> | |
</Component> | |
<Component class="javax.swing.JTextField" name="jTextField2"> | |
<Properties> | |
<Property name="text" type="java.lang.String" value="0"/> | |
</Properties> | |
<Events> | |
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jTextField2ActionPerformed"/> | |
</Events> | |
</Component> | |
<Component class="javax.swing.JTextField" name="jTextField3"> | |
<Properties> | |
<Property name="text" type="java.lang.String" value="10"/> | |
</Properties> | |
<Events> | |
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jTextField3ActionPerformed"/> | |
</Events> | |
</Component> | |
<Component class="javax.swing.JButton" name="jButton1"> | |
<Properties> | |
<Property name="text" type="java.lang.String" value="Run It"/> | |
</Properties> | |
<Events> | |
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/> | |
</Events> | |
</Component> | |
<Component class="javax.swing.JLabel" name="jLabel4"> | |
<Properties> | |
<Property name="text" type="java.lang.String" value="output"/> | |
</Properties> | |
</Component> | |
<Component class="javax.swing.JTextField" name="jTextField4"> | |
<Properties> | |
<Property name="editable" type="boolean" value="false"/> | |
</Properties> | |
</Component> | |
<Component class="javax.swing.JSeparator" name="jSeparator1"> | |
</Component> | |
<Component class="javax.swing.JSeparator" name="jSeparator2"> | |
</Component> | |
<Container class="javax.swing.JPanel" name="jPanel2"> | |
<Properties> | |
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor"> | |
<Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo"> | |
<TitledBorder title="How to use"/> | |
</Border> | |
</Property> | |
<Property name="toolTipText" type="java.lang.String" value=""/> | |
</Properties> | |
<Layout> | |
<DimensionLayout dim="0"> | |
<Group type="103" groupAlignment="0" attributes="0"> | |
<Group type="102" attributes="0"> | |
<EmptySpace max="-2" attributes="0"/> | |
<Group type="103" groupAlignment="0" attributes="0"> | |
<Component id="jLabel5" alignment="0" min="-2" max="-2" attributes="0"/> | |
<Component id="jLabel6" alignment="0" min="-2" max="-2" attributes="0"/> | |
</Group> | |
<EmptySpace max="32767" attributes="0"/> | |
</Group> | |
</Group> | |
</DimensionLayout> | |
<DimensionLayout dim="1"> | |
<Group type="103" groupAlignment="0" attributes="0"> | |
<Group type="102" alignment="0" attributes="0"> | |
<EmptySpace max="-2" attributes="0"/> | |
<Component id="jLabel5" min="-2" max="-2" attributes="0"/> | |
<EmptySpace max="-2" attributes="0"/> | |
<Component id="jLabel6" min="-2" max="-2" attributes="0"/> | |
<EmptySpace max="32767" attributes="0"/> | |
</Group> | |
</Group> | |
</DimensionLayout> | |
</Layout> | |
<SubComponents> | |
<Component class="javax.swing.JLabel" name="jLabel5"> | |
<Properties> | |
<Property name="text" type="java.lang.String" value="type x to be substituted in the formula "/> | |
</Properties> | |
</Component> | |
<Component class="javax.swing.JLabel" name="jLabel6"> | |
<Properties> | |
<Property name="text" type="java.lang.String" value="Math.pow(X,Y) to calculate power"/> | |
</Properties> | |
</Component> | |
</SubComponents> | |
</Container> | |
<Component class="javax.swing.JSeparator" name="jSeparator3"> | |
<Properties> | |
<Property name="orientation" type="int" value="1"/> | |
</Properties> | |
</Component> | |
</SubComponents> | |
</Container> | |
</SubComponents> | |
</Form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package discreet; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
import javax.script.ScriptEngine; | |
import javax.script.ScriptEngineManager; | |
import javax.script.ScriptException; | |
import javax.swing.JOptionPane; | |
/** | |
* | |
* @author Ahmed Kamel Taha | |
*/ | |
public class Home extends javax.swing.JFrame { | |
/** | |
* Creates new form Home | |
*/ | |
public Home() { | |
initComponents(); | |
} | |
/** | |
* This method is called from within the constructor to initialize the form. | |
* WARNING: Do NOT modify this code. The content of this method is always | |
* regenerated by the Form Editor. | |
*/ | |
@SuppressWarnings("unchecked") | |
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents | |
private void initComponents() { | |
jPanel1 = new javax.swing.JPanel(); | |
jLabel1 = new javax.swing.JLabel(); | |
jTextField1 = new javax.swing.JTextField(); | |
jLabel2 = new javax.swing.JLabel(); | |
jLabel3 = new javax.swing.JLabel(); | |
jTextField2 = new javax.swing.JTextField(); | |
jTextField3 = new javax.swing.JTextField(); | |
jButton1 = new javax.swing.JButton(); | |
jLabel4 = new javax.swing.JLabel(); | |
jTextField4 = new javax.swing.JTextField(); | |
jSeparator1 = new javax.swing.JSeparator(); | |
jSeparator2 = new javax.swing.JSeparator(); | |
jPanel2 = new javax.swing.JPanel(); | |
jLabel5 = new javax.swing.JLabel(); | |
jLabel6 = new javax.swing.JLabel(); | |
jSeparator3 = new javax.swing.JSeparator(); | |
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); | |
setTitle("Discreet"); | |
jPanel1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); | |
jLabel1.setText("formula"); | |
jTextField1.setText("x+x"); | |
jTextField1.setToolTipText("use x to be change in the range"); | |
jTextField1.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
jTextField1ActionPerformed(evt); | |
} | |
}); | |
jLabel2.setText("range start"); | |
jLabel3.setText("range end"); | |
jTextField2.setText("0"); | |
jTextField2.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
jTextField2ActionPerformed(evt); | |
} | |
}); | |
jTextField3.setText("10"); | |
jTextField3.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
jTextField3ActionPerformed(evt); | |
} | |
}); | |
jButton1.setText("Run It"); | |
jButton1.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
jButton1ActionPerformed(evt); | |
} | |
}); | |
jLabel4.setText("output"); | |
jTextField4.setEditable(false); | |
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("How to use")); | |
jPanel2.setToolTipText(""); | |
jLabel5.setText("type x to be substituted in the formula "); | |
jLabel6.setText("Math.pow(X,Y) to calculate power"); | |
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); | |
jPanel2.setLayout(jPanel2Layout); | |
jPanel2Layout.setHorizontalGroup( | |
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(jPanel2Layout.createSequentialGroup() | |
.addContainerGap() | |
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addComponent(jLabel5) | |
.addComponent(jLabel6)) | |
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) | |
); | |
jPanel2Layout.setVerticalGroup( | |
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(jPanel2Layout.createSequentialGroup() | |
.addContainerGap() | |
.addComponent(jLabel5) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(jLabel6) | |
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) | |
); | |
jSeparator3.setOrientation(javax.swing.SwingConstants.VERTICAL); | |
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); | |
jPanel1.setLayout(jPanel1Layout); | |
jPanel1Layout.setHorizontalGroup( | |
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() | |
.addGap(0, 0, Short.MAX_VALUE) | |
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addGap(58, 58, 58)) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addGap(59, 59, 59) | |
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addGap(29, 29, 29) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addComponent(jLabel4) | |
.addGap(32, 32, 32) | |
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)) | |
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addComponent(jTextField2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addGap(10, 10, 10) | |
.addComponent(jLabel2) | |
.addGap(12, 12, 12))) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) | |
.addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addGap(27, 27, 27) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addComponent(jTextField3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addComponent(jLabel3) | |
.addGap(13, 13, 13)))))) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addGap(130, 130, 130) | |
.addComponent(jLabel1)) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addGap(82, 82, 82) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)))) | |
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) | |
); | |
jPanel1Layout.setVerticalGroup( | |
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addContainerGap() | |
.addComponent(jLabel1) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addGap(18, 18, 18) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) | |
.addComponent(jLabel2) | |
.addComponent(jLabel3)) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) | |
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) | |
.addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(jButton1) | |
.addGap(18, 18, 18) | |
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addGap(5, 5, 5) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) | |
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addComponent(jLabel4)) | |
.addGap(18, 18, 18) | |
.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) | |
); | |
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); | |
getContentPane().setLayout(layout); | |
layout.setHorizontalGroup( | |
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(layout.createSequentialGroup() | |
.addContainerGap() | |
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) | |
.addContainerGap()) | |
); | |
layout.setVerticalGroup( | |
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(layout.createSequentialGroup() | |
.addContainerGap() | |
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) | |
.addContainerGap()) | |
); | |
pack(); | |
}// </editor-fold>//GEN-END:initComponents | |
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed | |
// TODO add your handling code here: | |
}//GEN-LAST:event_jTextField1ActionPerformed | |
private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed | |
// TODO add your handling code here: | |
}//GEN-LAST:event_jTextField2ActionPerformed | |
private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField3ActionPerformed | |
// TODO add your handling code here: | |
}//GEN-LAST:event_jTextField3ActionPerformed | |
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed | |
// TODO add your handling code here: | |
String f=jTextField1.getText().replaceAll("X", "x"); | |
int s= Integer.valueOf(jTextField2.getText()); | |
int e = Integer.valueOf(jTextField3.getText()); | |
double sum = 0; | |
ScriptEngineManager mng = new ScriptEngineManager(); | |
ScriptEngine engine = mng.getEngineByName("JavaScript"); | |
for (int i = s; i <= e; i++) { | |
try { | |
sum +=Double.parseDouble(engine.eval(f.replaceAll("x", String.valueOf(i))).toString()); | |
} catch (ScriptException ex) { | |
JOptionPane.showMessageDialog(null , "invalid expression"); | |
break; | |
} | |
} | |
jTextField4.setText(String.valueOf(sum)); | |
}//GEN-LAST:event_jButton1ActionPerformed | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String args[]) { | |
/* Set the Nimbus look and feel */ | |
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> | |
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. | |
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html | |
*/ | |
try { | |
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { | |
if ("Nimbus".equals(info.getName())) { | |
javax.swing.UIManager.setLookAndFeel(info.getClassName()); | |
break; | |
} | |
} | |
} catch (ClassNotFoundException ex) { | |
java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (InstantiationException ex) { | |
java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (IllegalAccessException ex) { | |
java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (javax.swing.UnsupportedLookAndFeelException ex) { | |
java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} | |
//</editor-fold> | |
/* Create and display the form */ | |
java.awt.EventQueue.invokeLater(new Runnable() { | |
public void run() { | |
new Home().setVisible(true); | |
} | |
}); | |
} | |
// Variables declaration - do not modify//GEN-BEGIN:variables | |
private javax.swing.JButton jButton1; | |
private javax.swing.JLabel jLabel1; | |
private javax.swing.JLabel jLabel2; | |
private javax.swing.JLabel jLabel3; | |
private javax.swing.JLabel jLabel4; | |
private javax.swing.JLabel jLabel5; | |
private javax.swing.JLabel jLabel6; | |
private javax.swing.JPanel jPanel1; | |
private javax.swing.JPanel jPanel2; | |
private javax.swing.JSeparator jSeparator1; | |
private javax.swing.JSeparator jSeparator2; | |
private javax.swing.JSeparator jSeparator3; | |
private javax.swing.JTextField jTextField1; | |
private javax.swing.JTextField jTextField2; | |
private javax.swing.JTextField jTextField3; | |
private javax.swing.JTextField jTextField4; | |
// End of variables declaration//GEN-END:variables | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment