Rerunning Parts of Code

• 12-03-2012, 03:23 AM
philip1597
Rerunning Parts of Code
In this two class project I have created a GUI that takes the input from the user and calculates an answer. In my GUI class, I used a JOptionPane.showInputDialog to obtain the numbers from the user, and a JFrame with JButtons to choose the function. Is it possible, and if so how, to create a button that makes the JOptionPane part of code or, if that is not possible, the entire GUI class run again? Any help is appreciated.

This is the class for the logic/calculations
Code:

import javax.swing.*;

public class Calculator {

public static void addReduce(int numeratorOne, int denominatorOne,
int numeratorTwo, int denominatorTwo) {
numeratorOne *= denominatorTwo;
numeratorTwo *= denominatorOne;
denominatorTwo *= denominatorOne;
denominatorOne = denominatorTwo;
for (int i = numeratorAnswer + 1; i > 1; i--) {
} else if (numeratorAnswer % i == 0
&& denominatorAnswer % i == 0) {
}
}
for (int i = denominatorAnswer + 1; i > 1; i--) {
} else if (numeratorAnswer % i == 0
&& denominatorAnswer % i == 0) {
}

}
}

}

public static void subtractReduce(int numeratorOne, int denominatorOne,
int numeratorTwo, int denominatorTwo) {
numeratorOne *= denominatorTwo;
numeratorTwo *= denominatorOne;
denominatorTwo *= denominatorOne;
denominatorOne = denominatorTwo;
for (int i = numeratorAnswer + 1; i > 1; i--) {
} else if (numeratorAnswer % i == 0
&& denominatorAnswer % i == 0) {
}
}
for (int i = denominatorAnswer + 1; i > 1; i--) {
} else if (numeratorAnswer % i == 0
&& denominatorAnswer % i == 0) {
}

}
}
}

public static void multiplyReduce(int numeratorOne, int denominatorOne,
int numeratorTwo, int denominatorTwo) {

for (int i = numeratorAnswer + 1; i > 1; i--) {
} else if (numeratorAnswer % i == 0
&& denominatorAnswer % i == 0) {
}
}
for (int i = denominatorAnswer + 1; i > 1; i--) {
} else if (numeratorAnswer % i == 0
&& denominatorAnswer % i == 0) {
}

}
}
}

public static void divideReduce(int numeratorOne, int denominatorOne,
int numeratorTwo, int denominatorTwo) {
for (int i = numeratorAnswer + 1; i > 1; i--) {
} else if (numeratorAnswer % i == 0
&& denominatorAnswer % i == 0) {
}
}
for (int i = denominatorAnswer + 1; i > 1; i--) {
} else if (numeratorAnswer % i == 0
&& denominatorAnswer % i == 0) {
}

}
}
}
}

This is the class for the GUI.
Code:

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class GUI {

public static void main(String[] args) {
JButton subtractpiggy = new JButton("-");
JButton multiplypiggy = new JButton("*");
JButton dividepiggy = new JButton("/");
JFrame functions = new JFrame("Choose a Function");
functions.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
functions.pack();
functions.setVisible(true);

@Override
public void actionPerformed(ActionEvent arg0) {
}
});

String numerator1 = JOptionPane.showInputDialog("Insert a Numerator");
int numeratorOne = Integer.parseInt(numerator1);
String denominator1 = JOptionPane
.showInputDialog("Insert a Denominator");
int denominatorOne = Integer.parseInt(denominator1);
String numerator2 = JOptionPane
.showInputDialog("Insert Another Numerator");
int numeratorTwo = Integer.parseInt(numerator2);
String denominator2 = JOptionPane
.showInputDialog("Insert Another Denominator");
int denominatorTwo = Integer.parseInt(denominator2);

}
}
public static void clickedSubtract(){
Calculator.subtractReduce(numeratorOne, denominatorOne, numeratorTwo, denominatorTwo)
}
public static void clickedMultiply(){
Calculator.multiplyReduce(numeratorOne, denominatorOne, numeratorTwo, denominatorTwo)
}
public static void clickedDivide(){
Calculator.divideReduce(numeratorOne, denominatorOne, numeratorTwo, denominatorTwo)
}
}

• 12-03-2012, 08:09 AM
DarrylBurke
Re: Rerunning Parts of Code
Don't double post. Please go through the Forum Rules -- particularly the second paragraph.

db