题目内容

本题中定义了一个简单的计算器,可以进行基本的四则运算。程序中包含16个按钮用来表示0~9、+、-、*、/、=运算符和小数点,程序顶部的文本框用来显示操作数以及结果。 import java. awt. * ; import java. awt. event. * ; import javax. swing. * ; public class java2 public static void main(String[] args) try UIManager. setLookAndFeel(UIManager. getSystemLookAndFeelClassName()); catch (Exception e) JFrame frame=new CalculatorFrame(); frame. show(); class CalculatorPanel extends JPanel implements ActionListener private JTextField display; private JButton btn; private double arg=0; private String op="= "; private boolean start=true; public CalculatorPanel() setLayout(new BorderLayout()); dispIay=new JTextField("0"); display, setEditable(false); add(display, "North"); JPanel p=new JPanel(); p. setLayout(new GridLayout(4,4)); String buttons="789/456*123-0.=+"; for (int i=0; i<buttons, length(); i++) btn=new JButton(buttons. substring(i, i+1)); p. add(btn); ______; add(p, "Center"); public void actionPerformed(ActionEvent evt) String s=evt. getActionCommand(); if(’0’<=s. charAt(0) && s. charAt(0)<=’9’ || s. equals(".")) if (start) display. setText(s); else display, setText(display, getText()+s); start=false; else if (start) if (s. equals("-")) display. setText(s); start=false; else op=s; else double x=______; calculate(x); op=s; start=true; public void calculate(double n) if (op. equals("+")) arg+=n; else if (op. equals("-")) arg-= n; else if (op. equals("*")) arg *=n; else if (op. equals("/")) arg /=n; else if (op. equals("=")) arg=n; display, setText(""+arg); class CalculatorFrame extends JFrame public CalculatorFrame() setTitle("java2"); setSize(220,180); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System. exit(0); ); Container contentPane=getContentPane(); contentPane, add(new CalculatorPanel());

查看答案
更多问题

The manager ()a rise in salary for ages,but nothing has happened yet.

A. is promised
B. is promising
C. has been promising
D. promised

Many teachers believe that the responsibilities for learning lie with the student. (61) a long reading assignment is given, instructors expect students to be familiar with the (62) in the reading even if they do not discuss it in class or take an examination. The (63) student is considered to be (64) who is motivated (激发) to learn for the sake of (65) , not the one interested only in getting high grades. Sometimes homework is returned (66) brief written comments but without a grade. Even if a grade is not given, the students is (67) for learning the material assigned. When research is (68) , the professor expects the student to take it actively and to complete it with (69) guidance. It is the (70) responsibility to find books, magazines, and articles in the library. Professors do not have the time to explain (71) a university library works; they expect students, (72) graduate students, to be able to exhaust the reference (73) in the library. Professors will help students who need it, but (74) that their students not be (75) dependent on them. In the United States, professors have many other duties (76) teaching, such as administrative or research work. (77) the time that a professor can spend with a student outside of class is (78) . If a student has problems with classroom work, the student should either (79) a professor during office hours (80) make an appointment. 76()

A. but
B. except
C. with
D. besides

All()you can do to comfort her is to listen to her story patiently.

A. what
B. that
C. which
D. things

Many teachers believe that the responsibilities for learning lie with the student. (61) a long reading assignment is given, instructors expect students to be familiar with the (62) in the reading even if they do not discuss it in class or take an examination. The (63) student is considered to be (64) who is motivated (激发) to learn for the sake of (65) , not the one interested only in getting high grades. Sometimes homework is returned (66) brief written comments but without a grade. Even if a grade is not given, the students is (67) for learning the material assigned. When research is (68) , the professor expects the student to take it actively and to complete it with (69) guidance. It is the (70) responsibility to find books, magazines, and articles in the library. Professors do not have the time to explain (71) a university library works; they expect students, (72) graduate students, to be able to exhaust the reference (73) in the library. Professors will help students who need it, but (74) that their students not be (75) dependent on them. In the United States, professors have many other duties (76) teaching, such as administrative or research work. (77) the time that a professor can spend with a student outside of class is (78) . If a student has problems with classroom work, the student should either (79) a professor during office hours (80) make an appointment. 78()

A. plentiful
B. limited
C. irregular
D. flexible

答案查题题库