原来这个流程图做的是VB的 按照那个思路画的 代码也能写出 最近几天接触JAVA 是作业 要求写计算器流程图
按照这个VB的流程图写JAVA代码没问题吧
我这个流程图 基本都是if  然后设置了7个变量 但是这个时候要变量转到java有蒙
比如我在VB中OP是计算种类 到JAVA里我都不知道他是什么变量了 如何定义
谢谢大侠给予帮助 思路。。

解决方案 »

  1.   

    我怎么发给你看 我在excel里画的
      

  2.   

    我怎么发给你看 我在excel里画的
      

  3.   


    import java.awt.BorderLayout;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.UIManager;import sun.util.calendar.JulianCalendar;public class CalculatorFrame extends JFrame {
    private JTextField text = new JTextField();
    private JButton btnEq = new JButton("=");
    private JButton[] btns = new JButton[16];
    private JPanel btnsPanel = new JPanel();
    private GridLayout glayout = new GridLayout(4,4,2,2);
    private String input="0";
    private double saveFirstInput = 0;
    private boolean lockpoint = false;
    private int firstNum = 0;
    private char c;


    public CalculatorFrame() {
    init();
    }

    private void init() {
    String[] arr = {"7","8","9","/",
    "4","5","6","*",
    "1","2","3","-",
    "0","+/-",".","+"};
    btnsPanel.setLayout(glayout);
    text.setHorizontalAlignment(JTextField.RIGHT); // 文字居右
    for (int i = 0; i < arr.length; i++) {
    JButton btn = new JButton(arr[i]);
    btns[i] = btn;
    btnsPanel.add(btn);
    }

    int[]index={0,1,2,4,5,6,8,9,10,12};
    for(int i=0;i<index.length;i++){
    btns[index[i]].addActionListener(new NumbtnListener());
    }
    btns[14].addActionListener(new PointbtnListener());
    btns[13].addActionListener(new changeSybtnListener());
    int[]index2={3,7,11,15};
    for(int i=0;i<index2.length;i++){
    btns[index2[i]].addActionListener(new calcbtnListener());
    }
    btnEq.addActionListener(new btnEqListener());

    this.getContentPane().add(btnsPanel);
    this.getContentPane().add(text,BorderLayout.NORTH);
    this.getContentPane().add(btnEq,BorderLayout.SOUTH);

    this.setLocation(300,250);
    this.setSize(240,250);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setTitle("计算器");
    this.setVisible(true);
    }

    class NumbtnListener implements ActionListener{
    public void actionPerformed(ActionEvent e) {
    if(firstNum++==0){
    input=e.getActionCommand();
    }else{
    input+=e.getActionCommand();
    }
    text.setText(input);
    }
    }

    class PointbtnListener implements ActionListener{
    public void actionPerformed(ActionEvent e) {
    if(lockpoint==false){
    input+=e.getActionCommand();
    lockpoint=true;
    }
    text.setText(input);
    }
    }

    class changeSybtnListener implements ActionListener{
    public void actionPerformed(ActionEvent e) {
    double d=Double.valueOf(input);
    d=-1*d;
    input=Double.toString(d);
    text.setText(input);
    }
    }

    class calcbtnListener implements ActionListener{
    public void actionPerformed(ActionEvent e) {
    c=e.getActionCommand().charAt(0);
    double d=Double.valueOf(input);
    saveFirstInput = d;
    firstNum=0;
    input="0";
    }
    }

    class btnEqListener implements ActionListener{
    public void actionPerformed(ActionEvent e) {
    double d=Double.valueOf(input);
    switch(c){
    case '+':
    d += saveFirstInput;
    break;
    case '-':
    d = saveFirstInput-d;
    break;
    case '*':
    d *= saveFirstInput;
    break;
    case '/':
    d = saveFirstInput / d;
    break;
    }
    input=Double.toString(d);
    text.setText(input);
    }
    }

    public static void main(String[] args) throws Exception {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    new CalculatorFrame();
    }
    }给你个计时器源码!