.


:




:

































 

 

 

 


5. Java

:

- , , .

, :

importjavax.swing.*;

importjava.awt.*;

java.swing - Java.

Java.awt - .

extendsJFrame{}. , Rabota JFrame. . . :

publicclassRabotaextendsJFrame{

JTextFieldjta1 = newJTextField(10);

JTextField jta2 = new JTextField(10);

JButton button1 = new JButton(" + ");

JButton button2 = new JButton(" - ");

JButton button3 = new JButton(" X ");

JButton button4 = new JButton(" / ");

JButton button5 = new JButton(" x2 ");

JButton button6 = new JButton(" SQR ");

Font font = new Font("Times new roman",Font.BOLD,100);

 

JTextFieldjta = newJTextField(10); 10.

JButtonbutton1 = newJButton(" + "); - + ..

Font font = new Font("Times new roman",Font.BOLD,100); - .

, , :

Rabota() {

 

super("");

setLayout(new FlowLayout());

setSize(400,200);

add(new JLabel(" "));

add (jta1);

add(newJLabel(""));

add (jta2);

add(button1);

add(button2);

add(button3);

add(button4);

add(button5);

add(button6);

 

super () .

setLayout (newFlowLayout()) .

setSize(400,200); - .

add(newJLabel("")); - (jta).

add(newJLabel(" ")); - (jta) .

add(button1); - .

. , . . +.

button1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

try{

double x1 = Double.parseDouble(jta1.getText().trim());

double x2 = Double.parseDouble(jta2.getText().trim());

JOptionPane.showMessageDialog(null, " = "

+(x1+x2), "!", JOptionPane.INFORMATION_MESSAGE);

}

catch (Exception e1){

JOptionPane.showMessageDialog(null, " !\n !",

"!",JOptionPane.ERROR_MESSAGE);

 

}

 

}

});

 

button1.addActionListener(newActionListener() { - .

public void actionPerformed(ActionEvent e) { - ActionEvent.

try , , . ( jtaTextField)

doublex = Double.parseDouble(jta.getText().trim()); - double.

JOptionPane.showMessageDialog(null, " = " +(x1+x2), "!", JOptionPane.INFORMATION_MESSAGE); - ( ). (x1+x2) - .

catch (Exceptione1) , , . ( jtaTextField).

JOptionPane.showMessageDialog(null, " !\n !", "!", JOptionPane.ERROR_MESSAGE); - .

(, ..). SQR , .. , .

2- :

setVisible(true);

 

}

 

public static void main(String[] args) {

newRabota();

}

}

 

setVisible(true); - .

public static void main(String[] args) {new Rabota()}; - .

 

.19

 

.20

 

.21

 

 



<== | ==>
4. Java |
:


: 2018-10-18; !; : 447 |


:

:

- , 20 40 . - .
==> ...

1885 - | 1829 -


© 2015-2024 lektsii.org - -

: 0.013 .