如何运行两个c++;使用java gui代码在cmd上创建文件 我很新的使用java及其支持库/类制作GUI,但我制作了计算器。我用C++来编写代码。因此,我发现用java代码调用系统C++来运行C++文件是困难的。这是在Eclipse编辑器上使用一些库/类实现的CALC代码。 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); } }
我的gui界面如下。 我只想在单击“添加”按钮时运行一个C++文件(如AD.CPP)。 我也在谷歌上搜索过,也得到了很多解决方案,但是我的解决方案却很长。 < p>你不运行C++代码或.cpp文件;这些代码被编译成机器代码,并由计算机处理器直接执行。我认为,编辑您的问题来解释为什么您认为要从Java程序运行.cpp文件可能会对您更有帮助。对于这个特定的例子,简单地用Java重写计算是最有意义的 为了实际回答这个问题,我认为基本上有三种选择,我将按照从最不疯狂到最疯狂的顺序来介绍如何运行两个c++;使用java gui代码在cmd上创建文件 我很新的使用java及其支持库/类制作GUI,但我制作了计算器。我用C++来编写代码。因此,我发现用java代码调用系统C++来运行C++文件是困难的。这是在Eclipse编辑器上使用一些库/类实现的CALC代码。 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); } },java,c++,user-interface,Java,C++,User Interface,我的gui界面如下。 我只想在单击“添加”按钮时运行一个C++文件(如AD.CPP)。 我也在谷歌上搜索过,也得到了很多解决方案,但是我的解决方案却很长。 < p>你不运行C++代码或.cpp文件;这些代码被编译成机器代码,并由计算机处理器直接执行。我认为,编辑您的问题来解释为什么您认为要从Java程序运行.cpp文件可能会对您更有帮助。对于这个特定的例子,简单地用Java重写计算是最有意义的 为了实际回答这个问题,我认为基本上有三种选择,我将按照从最不疯狂到最疯狂的顺序来介绍 编译C++代码