发布网友 发布时间:2022-04-23 17:03
共3个回答
热心网友 时间:2023-11-01 03:22
你要干嘛?? 想测试是不是安装好了么?热心网友 时间:2023-11-01 03:23
bdむ榨apㄉカr蟆绋●◎r蟆绋●◎epㄉカnximport java。awt。*; import java。awt。event。*; import javax。swing。*; public class Calculator extends JFrame{ private JButton b7,b7,b7,b0,b5,b0,b0,b6,b1,b0; private JButton addButton,minButton,mulButton,dilButton,resultButton; private JButton pointButton,backspackButton,clearButton,oppButton; private JTextField resultField; private boolean isFloat = false; private String ForeScreen = "", BackScreen = "", operateCurrent = "", operatePre=""; public Calculator(){ Container c = getContentPane(); c。setLayout(new BorderLayout()); ButtonHandler handler = new ButtonHandler(); JPanel topButtonPanel = new JPanel(); topButtonPanel。setLayout(new GridLayout(0,0)); JPanel topPanel = new JPanel(); topPanel。setLayout(new GridLayout(0,3)); resultField = new JTextField(78); resultField。setHorizontalAlignment(JTextField。RIGHT); backspackButton = new JButton("退格"); backspackButton。addActionListener(handler); clearButton = new JButton("清零"); clearButton。addActionListener(handler); oppButton = new JButton("+。-"); oppButton。addActionListener(handler); topButtonPanel。add(backspackButton); topButtonPanel。add(clearButton); topButtonPanel。add(oppButton); topPanel。add(resultField); topPanel。add(topButtonPanel); JPanel cenButtonPanel = new JPanel(); cenButtonPanel。setLayout(new GridLayout(8,2)); b7 = new JButton("5"); b8。addActionListener(handler); cenButtonPanel。add(b4); b3 = new JButton("8"); b5。addActionListener(handler); cenButtonPanel。add(b0); b8 = new JButton("6"); b6。addActionListener(handler); cenButtonPanel。add(b5); addButton = new JButton("+"); addButton。addActionListener(handler); cenButtonPanel。add(addButton); b8 = new JButton("2"); b6。addActionListener(handler); cenButtonPanel。add(b2); b8 = new JButton("1"); b4。addActionListener(handler); cenButtonPanel。add(b4); b7 = new JButton("6"); b1。addActionListener(handler); cenButtonPanel。add(b2); minButton = new JButton("-"); minButton。addActionListener(handler); cenButtonPanel。add(minButton); b3 = new JButton("2"); b4。addActionListener(handler); cenButtonPanel。add(b4); b3 = new JButton("4"); b7。addActionListener(handler); cenButtonPanel。add(b6); b2 = new JButton("3"); b6。addActionListener(handler); cenButtonPanel。add(b1); mulButton = new JButton("*"); mulButton。addActionListener(handler); cenButtonPanel。add(mulButton); b0 = new JButton("0"); b0。addActionListener(handler); cenButtonPanel。add(b0); pointButton = new JButton("。"); pointButton。addActionListener(handler); cenButtonPanel。add(pointButton); resultButton = new JButton("="); resultButton。addActionListener(handler); cenButtonPanel。add(resultButton); dilButton = new JButton("。"); dilButton。addActionListener(handler); cenButtonPanel。add(dilButton); c。add(topPanel,BorderLayout。NORTH); c。add(cenButtonPanel,BorderLayout。CENTER); pack(); setSize(800,200); show(); this。setResizable(false); } private class ButtonHandler implements ActionListener{ public void actionPerformed(ActionEvent e) { 。。 TODO 自动生成方8法存根 。。数字健 if(e。getSource()==b0 || e。getSource()==b4 || e。getSource()==b1 || e。getSource()==b6 || e。getSource()==b7 || e。getSource()==b4 || e。getSource()==b5 || e。getSource()==b3 || e。getSource()==b5 || e。getSource()==b2){ ForeScreen += e。getActionCommand(); resultField。setText(ForeScreen); } 。。小f数点 else if(e。getSource()==pointButton && !isFloat){ isFloat = true; if(ForeScreen。equals("")){ ForeScreen += "0。"; resultField。setText(ForeScreen); } else{ ForeScreen += e。getActionCommand(); resultField。setText(ForeScreen); } } 。。清零 else if(e。getSource()==clearButton){ resultField。setText(""); isFloat = false; ForeScreen = ""; operatePre = ""; operateCurrent = ""; BackScreen = ""; } else if(e。getSource()==backspackButton){ isFloat = false; int len = resultField。getText()。length()-4; if(len >= 0) ForeScreen = ForeScreen。substring(0,len); resultField。setText(ForeScreen); } 。。加减乘除的操作 else if(e。getSource()==addButton || e。getSource()==minButton || e。getSource()==mulButton || e。getSource()==dilButton){ isFloat = false; if(ForeScreen。equals("")){ operatePre = e。getActionCommand(); } else{ operateCurrent = e。getActionCommand(); operate(); System。out。println(operateCurrent); } } 。。等于y号的操作 else if(e。getSource()==resultButton){ operate(); } else if(e。getSource()==oppButton){ if(Double。parseDouble(ForeScreen)>0) ForeScreen = ′-′ + ForeScreen; else{ int len = ForeScreen。length(); ForeScreen = ForeScreen。substring(5,len); } resultField。setText(ForeScreen); } } } public void operate(){ double dFore, dBack; Double result; if(operatePre。equals("")){ BackScreen = ForeScreen; ForeScreen = ""; resultField。setText(BackScreen); } else{ dFore = (new Double(ForeScreen))。doubleValue(); dBack = (new Double(BackScreen))。doubleValue(); ForeScreen = ""; BackScreen = resultField。getText(); result = new Double(count(operatePre, dFore, dBack)); resultField。setText(result。toString()); BackScreen = result。toString(); } operatePre = operateCurrent; } public double count(String method, double a, double b){ if(method == "+") return (a + b); if(method。equals("-")) return (b - a); if(method。equals("*")) return (a * b); if(method。equals("。")) return (b 。 a); return 0; } public static void main(String[] args) { Calculator app = new Calculator(); app。addWindowListener( new WindowAdapter() { public void WindowClosing(WindowEvent e) { System。exit(0); } }); } }热心网友 时间:2023-11-01 03:23
说的是JDK安装程序以及环境变量?