I am very new on making Gui using java and its supporting libraries/classes.But I made calculator.I use to code in c++.So I found it difficult to give system call in java code to run c++ file.This is calc code implemented on eclipse editor using some libraries/classes.
package calc;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Font;
public class calc_app {
private JFrame frame;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
calc_app window = new calc_app();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public calc_app() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 455, 297);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
textField = new JTextField();
textField.setBounds(50, 52, 86, 20);
frame.getContentPane().add(textField);
textField.setColumns(10);
textField_1 = new JTextField();
textField_1.setBounds(226, 52, 86, 20);
frame.getContentPane().add(textField_1);
textField_1.setColumns(10);
JButton btnNewButton = new JButton("ADD");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try {
int num1,num2,ans;
num1=Integer.parseInt(textField.getText());
num2=Integer.parseInt(textField_1.getText());
ans = num1+num2;
textField_2.setText(Integer.toString(ans));
}catch(Exception arg2){
JOptionPane.showMessageDialog(null, "Please Enter valid Number");
}
}
});
btnNewButton.setBounds(50, 105, 89, 23);
frame.getContentPane().add(btnNewButton);
JButton btnNewButton_1 = new JButton("SUBtract");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try {
int num1,num2,ans;
num1=Integer.parseInt(textField.getText());
num2=Integer.parseInt(textField_1.getText());
ans = num1-num2;
textField_2.setText(Integer.toString(ans));
}catch(Exception arg1){
JOptionPane.showMessageDialog(null, "Please Enter valid Number");
}
}
});
btnNewButton_1.setBounds(223, 105, 89, 23);
frame.getContentPane().add(btnNewButton_1);
JLabel lblNewLabel = new JLabel("The Answer is ");
lblNewLabel.setFont(new Font("Times New Roman", Font.BOLD, 15));
lblNewLabel.setBounds(50, 152, 142, 35);
frame.getContentPane().add(lblNewLabel);
textField_2 = new JTextField();
textField_2.setBounds(226, 159, 86, 20);
frame.getContentPane().add(textField_2);
textField_2.setColumns(10);
}
}
My gui interface is following.
I just want to run the one c++ file(say add.cpp ) when I click ADD Button. I also searched on google and also got many solutions but got very lengthy solution deviated from my case.