Advertisement
Valya123

Untitled

Jan 27th, 2020
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.54 KB | None | 0 0
  1. package nananan;
  2. import javax.swing.*;
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. public class Nananan {
  6.     public static void main(String[] args) {
  7.         okno nf = new okno();
  8.     }
  9. }
  10. class okno extends JFrame {
  11.     private JTextArea text;
  12.     private double a1=0, a2=0;
  13.     private int oper = 0;
  14.     private void btnClick(JButton btn)  {
  15. }
  16.     public okno() {
  17.         Container cont = getContentPane();
  18.         JPanel pan = new JPanel();
  19.         pan.setLayout(null);
  20.         Font btnFont = new Font ("arial",0,20);
  21.         Font labFont = new Font ("arial",1,20);
  22.         Font textFont = new Font ("arial",2,20);
  23.         JButton[]btn = new JButton[17];
  24.         for (int i=0;i<17;i++) {
  25.             btn[i] = new JButton();
  26.             btn[i].setSize(100,25);
  27.             btn[i].setFont(btnFont);
  28.             btn[i].setLocation(30,50+i*30);
  29.             btn[i].addActionListener(new ActionListener() {
  30.                 public void actionPerformed(ActionEvent e) {
  31.                     btnClick((JButton)e.getSource());
  32.                 }
  33.             });
  34.             pan.add(btn[i]);
  35.         }
  36.         for (int i=0;i<10;i++) btn[i].setText(" "+i);
  37.         btn[10].setText("+");
  38.         btn[11].setText("-");
  39.         btn[12].setText("/");
  40.         btn[13].setText("*");
  41.         btn[14].setText("=");
  42.         btn[15].setText("C");
  43.         btn[16].setText("Выход");
  44.         JLabel lab = new JLabel("Результат: ");
  45.         lab.setFont(labFont);
  46.         lab.setBounds(130,0,300,50);
  47.         pan.add(lab);
  48.         text = new JTextArea();
  49.         text.setFont(textFont);
  50.         text.setBounds(300,10,300,35);
  51.         text.setForeground(new Color(0,0,100));
  52.         text.setBackground(Color.WHITE);
  53.         cont.add(pan);
  54.         setBounds(0,0,800,600);
  55.         setTitle("Калькулятор");
  56.         setVisible(true);
  57.         }
  58.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement