Skip to content

Commit

Permalink
MainWindow form: perform action on enter
Browse files Browse the repository at this point in the history
  • Loading branch information
alistat committed Mar 5, 2015
1 parent b61fe6b commit 00ca9db
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/ui/MainWindow.form
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
</Property>
<Property name="text" type="java.lang.String" value="elephant"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="firstWordFieldActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="-1" gridY="-1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="3" insetsBottom="2" insetsRight="5" anchor="10" weightX="0.1" weightY="0.0"/>
Expand All @@ -97,6 +100,9 @@
</Property>
<Property name="text" type="java.lang.String" value="relevant"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="secondWordFieldActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="1" gridY="1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="3" insetsBottom="2" insetsRight="5" anchor="10" weightX="0.1" weightY="0.0"/>
Expand Down
32 changes: 27 additions & 5 deletions src/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ public class MainWindow extends javax.swing.JFrame {
public MainWindow() {
initComponents();
}


private void action() {
final Algorithm alg = new Algorithm(firstWordField.getText(), secondWordField.getText());
alg.editDistance();
Graphics.generateAndShowGraphic(alg);
}

/**
* 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
Expand Down Expand Up @@ -59,6 +65,11 @@ private void initComponents() {

firstWordField.setFont(new java.awt.Font("Ubuntu", 0, 22)); // NOI18N
firstWordField.setText("elephant");
firstWordField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
firstWordFieldActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 0.1;
Expand All @@ -76,6 +87,11 @@ private void initComponents() {

secondWordField.setFont(new java.awt.Font("Ubuntu", 0, 22)); // NOI18N
secondWordField.setText("relevant");
secondWordField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
secondWordFieldActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
Expand All @@ -85,7 +101,7 @@ private void initComponents() {
mainPane.add(secondWordField, gridBagConstraints);

buttonPanel.setOpaque(false);
buttonPanel.setLayout(new java.awt.GridLayout());
buttonPanel.setLayout(new java.awt.GridLayout(1, 0));

calculateButton.setFont(new java.awt.Font("Ubuntu", 0, 17)); // NOI18N
calculateButton.setText("Calculate");
Expand Down Expand Up @@ -123,11 +139,17 @@ private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-F
}//GEN-LAST:event_closeButtonActionPerformed

private void calculateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_calculateButtonActionPerformed
final Algorithm alg = new Algorithm(firstWordField.getText(), secondWordField.getText());
alg.editDistance();
Graphics.generateAndShowGraphic(alg);
action();
}//GEN-LAST:event_calculateButtonActionPerformed

private void firstWordFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_firstWordFieldActionPerformed
action();
}//GEN-LAST:event_firstWordFieldActionPerformed

private void secondWordFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_secondWordFieldActionPerformed
action();
}//GEN-LAST:event_secondWordFieldActionPerformed

/**
* @param args the command line arguments
*/
Expand Down

0 comments on commit 00ca9db

Please sign in to comment.