Results 1 to 13 of 13
Thread: Java
Hybrid View
-
5th May 2009 13:47 #1
Java
! Java.() , , . . . "" .
, , , . . :

. , ( ) "???" . , .
:
CalculatorCode:import java.awt.*; // java.swing, java.awt java.awt.event import java.awt.event.*; import javax.swing.*; public class GUI extends JFrame implements ActionListener{ // , " " // GUI JFrame ActionListener // : : private JTextField left; // left; private JTextField right; // right; private JButton clear; // clear; private JTextField result; // result; private JButton add; // add; private JButton subtract; // subtract; private JButton multiply; // multiply; private JButton divide; // divide. public GUI() { // - "" super(""); Container container = getContentPane(); // container.setLayout(new GridLayout(0,2)); // (0 )??? 2 // : left = new JTextField(""); // left ; right = new JTextField(""); // right ; add = new JButton("+"); // add "+"; subtract = new JButton("-"); // subtract "-"; multiply = new JButton("*"); // multiply "*"; divide = new JButton("/"); // divide "/"; clear = new JButton("C"); // clear "C"; result = new JTextField(""); // result . // : container.add(left); // left; container.add(right); // right; container.add(clear); // clear; container.add(result); // result; container.add(add); // add; container.add(subtract); // subtract; container.add(multiply); // multiply; container.add(divide); // divide. // , : clear.addActionListener(this); // clear; add.addActionListener(this); // add; subtract.addActionListener(this); // subtract; multiply.addActionListener(this); // multiply; divide.addActionListener(this); // divide. setSize(200,150); // 200150 setVisible(true); // setLocationRelativeTo(null); //??? } // actionPerformed " " public void actionPerformed(ActionEvent e) { try{ //( )??? if (e.getSource()== clear){ // clear left.setText(""); // left right.setText(""); // right result.setText(""); // result } else if (e.getSource()== add){ // , add Calculator calc = new Calculator(Double.parseDouble(left.getText()),"+",Double.parseDouble(right.getText())); calc.add(); //??? result.setText(calc.showResult()); // (calc.showResult)??? result } else if (e.getSource()== subtract){ // , subtract Calculator calc = new Calculator(Double.parseDouble(left.getText()),"-",Double.parseDouble(right.getText())); calc.subtract(); result.setText(calc.showResult()); // (calc.showResult)??? result } else if (e.getSource()== multiply){ // , multiply Calculator calc = new Calculator(Double.parseDouble(left.getText()),"*",Double.parseDouble(right.getText())); calc.multiply(); result.setText(calc.showResult()); // (calc.showResult)??? result } else if (e.getSource()== divide){ // , divide Calculator calc = new Calculator(Double.parseDouble(left.getText()),"/",Double.parseDouble(right.getText())); calc.divide(); result.setText(calc.showResult()); // (calc.showResult)??? result/ } } catch (Exception ex) { // Exception // showMessage JOptionPane (null)??? , , // , : " !", :"", // , : ERROR_MESSAGE JOptionPane.showMessageDialog(null," !","",JOptionPane.ERROR_MESSAGE); left.setText(""); // left right.setText(""); // right result.setText(""); // result } } public static void main(String[] args) { // main EventQueue.invokeLater(new Runnable() { public void run() { new GUI(); } }); } }
ResultCode:public class Calculator implements Result { // Calculator Result // : private double left; // left double private String oper; //oper String private double right; //right double public Calculator(double left,String oper,double right) { // this.left=left; // left this.oper=oper; // oper this.right=right; // right } // : public double add() { return left+right; // left right } public double subtract() { return left-right; // left right } public double multiply() { return left*right; // left right } public double divide() { return left/right; // left right } public String showResult(){ if (oper == "+"){ //??? return left + oper + right + "=" + add(); //??? } else if (oper == "-"){ return left + oper + right + "=" + subtract(); } else if (oper == "*"){ return left + oper + right + "=" + multiply(); } else { return left + oper + right + "=" + divide(); } } }
!Code:public interface Result { // Result ??? public String showResult(); // ??? }
Dell. Purely You.
-
5th May 2009 17:50 #2
Last edited by System.gc(); 5th May 2009 at 22:01.
UD3R|Q9550+1283|4x2 G.Skill@1066|MX500+1002FAEX+640AAKS+ST31 60|RX580-8GB|1841BLT|SS-760XP|Define7|z24i|Edifier S350DB
geniusloci: ) ; ) ; ) ?
nope|r.i.p.
-
5th May 2009 19:45 #3
Join Date: Sep:2005
Location: Sofia
Posts: 18,517
. , .
- Javadoc.
-
5th May 2009 20:00 #4Registered User
Join Date: Apr:2009
Location:
Posts: 243
! ????
, ( C++) JNI, ...
.
-
5th May 2009 22:40 #5
, . . -. ..., Java . , . 2 3. . . ., , . .
Dell. Purely You.
-
5th May 2009 23:04 #6UD3R|Q9550+1283|4x2 G.Skill@1066|MX500+1002FAEX+640AAKS+ST31 60|RX580-8GB|1841BLT|SS-760XP|Define7|z24i|Edifier S350DB
geniusloci: ) ; ) ; ) ?
nope|r.i.p.
-
6th May 2009 01:06 #7
-
6th May 2009 01:44 #8
-
6th May 2009 02:59 #9
Join Date: Sep:2005
Location: Sofia
Posts: 18,517
. . 3 25, 16 , 63. 25 2-3 . 10, - 5 .
- - .Last edited by vvvlado; 6th May 2009 at 03:07.
-
6th May 2009 10:41 #10
-
6th May 2009 22:42 #11




Reply With Quote
, , .

Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in