Results 1 to 13 of 13

Thread: Java

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User juslen's Avatar
    Join Date: Dec:2008
    Location: Sofia
    Posts: 614

    Question Java

    ! Java.() , , . . . "" . , , , . . :



    . , ( ) "???" . , .
    :
    Code:
    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();
    } 
    });	
    }
    }
    Calculator
    Code:
    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();	
    }
    }
    }
    Result
    Code:
    public interface Result { //   Result ???
    public String showResult(); // ???
    }
    !
    Dell. Purely You.

  2. #2
    System.gc()'s Avatar
    Join Date: Apr:2007
    Location: back in time
    Posts: 1,075
    , ? ... , "someObject.doSomething() // doSomething() someObject". , , 100 () .... , , .


    Quote Originally Posted by DarkEnergy View Post
    ! ????

    , ( C++) JNI, ... .
    () , .
    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.

  3. #3

    Join Date: Sep:2005
    Location: Sofia
    Posts: 18,517
    . , .
    - Javadoc.

  4. #4
    Registered User
    Join Date: Apr:2009
    Location:
    Posts: 243
    ! ????

    , ( C++) JNI, ... .

  5. #5
    Registered User juslen's Avatar
    Join Date: Dec:2008
    Location: Sofia
    Posts: 614
    , . . -. ..., Java . , . 2 3. . . ., , . .
    Dell. Purely You.

  6. #6
    System.gc()'s Avatar
    Join Date: Apr:2007
    Location: back in time
    Posts: 1,075
    Quote Originally Posted by juslen View Post
    , . . -. ..., Java . , . 2 3. . . ., , . .
    . - . , . , .
    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.

  7. #7
    Registered User juslen's Avatar
    Join Date: Dec:2008
    Location: Sofia
    Posts: 614
    Quote Originally Posted by System.gc() View Post
    - .
    , , , , . "", "" . , ( ), , , . , ... .

    .. . .
    Last edited by juslen; 6th May 2009 at 01:11.
    Dell. Purely You.

  8. #8
    _
    Join Date: Apr:2006
    Location: _
    Posts: 1,128
    Quote Originally Posted by juslen View Post
    , , , , . "", "" . , ( ), , , . , ... .

    .. . .
    ? 5kW 10kW, ?

  9. #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.

  10. #10
    Registered User juslen's Avatar
    Join Date: Dec:2008
    Location: Sofia
    Posts: 614
    Quote Originally Posted by Red_Leader View Post
    ? 5kW 10kW, ?
    . , . , , (). , . ... . , .
    .. . , , , .
    Last edited by juslen; 6th May 2009 at 11:02.
    Dell. Purely You.

  11. #11
    Registered User 's Avatar
    Join Date: Feb:2006
    Location:
    Posts: 653
    .
    : , , , . '' . , , ....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |