I am creating a small program in Java eclipse windowbuilder. The user inputs the left hand side (LHS) and right hand side (RHS) of the inequality statement such that LHS < (m/n) < RHS. The program will output the lowest integer values m and n which satisfy the condition. I have the logic/code required to do this, but I am unsure how to get the user values of LHS and RHS in windowbuilder. The text field to the left is called lhs and the text field on the right is called rhs, which you can see in the image below. How can I get the user's inputs for these (as double data type)? When the user enters these two values, I will put the code logic under actionPerformed. Thanks!
JButton btnCompute = new JButton("Compute");
btnCompute.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
package ntheory;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Ntheory {
private JFrame frame;
private JTextField lhs;
private JTextField rhs;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Ntheory window = new Ntheory();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Ntheory() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
lhs = new JTextField();
lhs.setBounds(6, 46, 68, 26);
frame.getContentPane().add(lhs);
lhs.setColumns(10);
JLabel label = new JLabel("<");
label.setBounds(86, 51, 10, 16);
frame.getContentPane().add(label);
JLabel label_1 = new JLabel("<");
label_1.setBounds(159, 51, 10, 16);
frame.getContentPane().add(label_1);
rhs = new JTextField();
rhs.setColumns(10);
rhs.setBounds(181, 46, 68, 26);
frame.getContentPane().add(rhs);
JLabel lblmn = new JLabel("(m/n)");
lblmn.setBounds(108, 51, 61, 16);
frame.getContentPane().add(lblmn);
JButton btnCompute = new JButton("Compute");
btnCompute.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
btnCompute.setBounds(261, 46, 117, 29);
frame.getContentPane().add(btnCompute);
}
}