Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.40 KB | None | 0 0
  1.  
  2. ////READER.java
  3.  
  4. package com.company;
  5.  
  6. import javax.swing.*;
  7. import java.awt.*;
  8. import java.awt.event.ActionEvent;
  9. import java.awt.event.ActionListener;
  10. import java.io.File;
  11. import java.io.FileWriter;
  12. import java.io.IOException;
  13.  
  14. public class Reader extends JFrame {
  15.     int k, i;
  16.     Object boxA, boxB, boxC, textM;
  17.     File file = new File("retro.txt");
  18.     static JLabel l1, l2, l3, l4;
  19.     JComboBox box_1, box_2, box_3, text1;
  20.     JRadioButton flag1, flag2;
  21.     JRadioButton flag11, flag22;
  22.     ButtonGroup bg;
  23.     ButtonGroup ge;
  24.      JButton b, del;
  25.      String[] text = {"Выберите врача", "ЛОР", "Хирург", "Офтальмолог", "Терапевт", "Кардиолог"};
  26.      JTextArea area;
  27.      String[] box1 = {"...", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"};
  28.      String[] box2 = {"...", "январь", "февраль", "март", "апрель", "май", "июнь", "июль", "август", "сентябрь", "октябрь", "ноябрь", "декабрь"};
  29.      String[] box3 = {"...", "2019", "2020", "2021", "2022"};
  30.  
  31.     public Reader(String str, Color color) {
  32.         super(str);
  33.         setSize(500, 450);
  34.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  35.         setBackground(color);
  36.  
  37.         b = new JButton("Внесение в базу");
  38.         del = new JButton("Очистить");
  39.         text1 = new JComboBox(text);
  40.         area = new JTextArea(9, 9);
  41.         l1 = new JLabel("Врачебный специалист");
  42.         l2 = new JLabel("Причина посещения");
  43.         l3 = new JLabel("Дата получения талона");
  44.         l4 = new JLabel("Стоимость услуги");
  45.         box_1 = new JComboBox(box1);
  46.         box_2 = new JComboBox(box2);
  47.         box_3 = new JComboBox(box3);
  48.         flag1 = new JRadioButton("бесплатно");
  49.         flag2 = new JRadioButton("платно");
  50.  
  51.         flag11 = new JRadioButton("болен");
  52.         flag22 = new JRadioButton("не болен");
  53.         bg = new ButtonGroup();
  54.  
  55.         ge = new ButtonGroup();
  56.         ge.add(flag11);
  57.         ge.add(flag22);
  58.  
  59.         bg.add(flag1);
  60.         bg.add(flag2);
  61.  
  62.         setLayout(null);
  63.         b.setSize(200, 30);
  64.         b.setLocation(150, 370);
  65.         del.setSize(100, 30);
  66.         del.setLocation(10, 370);
  67.         text1.setSize(220, 25);
  68.         text1.setLocation(250, 20);
  69.         area.setSize(220, 150);
  70.         area.setLocation(250, 60);
  71.         l1.setSize(200, 25);
  72.         l1.setLocation(30, 20);
  73.         l2.setSize(220, 25);
  74.         l2.setLocation(30, 60);
  75.         l3.setSize(200, 25);
  76.         l3.setLocation(30, 250);
  77.         l4.setSize(200, 25);
  78.         l4.setLocation(30, 310);
  79.         box_1.setSize(60, 25);
  80.         box_1.setLocation(250, 250);
  81.         box_2.setSize(100, 25);
  82.         box_2.setLocation(300, 250);
  83.         box_3.setSize(90, 25);
  84.         box_3.setLocation(390, 250);
  85.         flag1.setSize(110, 25);
  86.         flag1.setLocation(250, 310);
  87.         flag2.setSize(110, 25);
  88.         flag2.setLocation(360, 310);
  89.  
  90.         flag11.setSize(110, 25);
  91.         flag11.setLocation(30, 150);
  92.         flag22.setSize(110, 25);
  93.         flag22.setLocation(140, 150);
  94.  
  95.         add(b);
  96.         add(del);
  97.         add(text1);
  98.         add(area);
  99.         add(l1);
  100.         add(l2);
  101.         add(l3);
  102.         add(l4);
  103.         add(box_1);
  104.         add(box_2);
  105.         add(box_3);
  106.         add(flag1);
  107.         add(flag2);
  108.  
  109.         add(flag11);
  110.         add(flag22);
  111.  
  112.         text1.addActionListener(new BoxActionListener());
  113.         b.addActionListener(new ButtonActionListener());
  114.         flag1.addActionListener(new FlagActionListener());
  115.         flag2.addActionListener(new FlagActionListener());
  116.  
  117.         flag11.addActionListener(new FlagActionListener());
  118.         flag22.addActionListener(new FlagActionListener());
  119.  
  120.         del.addActionListener(new DelActionListener());
  121.         box_1.addActionListener(new BoxActionListener());
  122.         box_2.addActionListener(new BoxActionListener());
  123.         box_3.addActionListener(new BoxActionListener());
  124.     }
  125.  
  126.     public class ButtonActionListener implements ActionListener {
  127.         public void actionPerformed(ActionEvent e) {
  128.             try {
  129.                 if (!file.exists()) {
  130.                     file.createNewFile();
  131.                 }
  132.                 FileWriter out = new FileWriter(file, true);
  133.                 try {
  134.                     out.write("Врачебный специалист: " + textM + "\n");
  135.                     String area2 = area.getText();
  136.                     out.write("Описание болезни пациента: " + area2 + "\n");
  137.                     if (k == 1)
  138.                         out.write("Бесплатная услуга. " + "\n");
  139.                     else if (k == -1)
  140.                         out.write("Платная услуга. " + "\n");
  141.                     out.write(" (Дата заказа талона:" + boxA + " " + boxB + " " + boxC + ")");
  142.                 } finally {
  143.                     out.close();
  144.                 }
  145.             } catch (IOException e1) {
  146.                 throw new RuntimeException(e1);
  147.             }
  148.         }
  149.     }
  150.  
  151.     public class FlagActionListener implements ActionListener {
  152.         public void actionPerformed(ActionEvent e) {
  153.             k = 0;
  154.             if (e.getSource() == flag1) {
  155.                 k++;
  156.             } else if (e.getSource() == flag2) {
  157.                 k--;
  158.             }
  159.         }
  160.     }
  161.  
  162.     public class FlagActionListener2 implements ActionListener {
  163.         public void actionPerformed(ActionEvent e) {
  164.             i = 0;
  165.             if (e.getSource() == flag11) {
  166.                 i++;
  167.             } else if (e.getSource() == flag22) {
  168.                 i--;
  169.             }
  170.         }
  171.     }
  172.  
  173.     public class DelActionListener implements ActionListener {
  174.         public void actionPerformed(ActionEvent e) {
  175.  
  176.                 area.setText(null);
  177.                 text1.setSelectedItem(text[0]);
  178.                 box_1.setSelectedItem(box1[0]);
  179.                 box_2.setSelectedItem(box2[0]);
  180.                 box_3.setSelectedItem(box3[0]);
  181.  
  182.                bg.clearSelection();
  183.  
  184.  
  185.         }
  186.     }
  187.  
  188.     public class BoxActionListener implements ActionListener {
  189.         public void actionPerformed(ActionEvent e) {
  190.             if (e.getSource() == text1) {
  191.                 textM = text1.getSelectedItem();
  192.             }
  193.             if (e.getSource() == box_1) {
  194.                 boxA = box_1.getSelectedItem();
  195.             }
  196.             if (e.getSource() == box_2) {
  197.                 boxB = box_2.getSelectedItem();
  198.             }
  199.             if (e.getSource() == box_3) {
  200.                 boxC = box_3.getSelectedItem();
  201.             }
  202.  
  203.         }
  204.     }
  205.  
  206.  
  207.  
  208. ///////////MAIN
  209.  
  210.  
  211. package com.company;
  212.  
  213. import java.awt.*;
  214.  
  215. public class Main {
  216.     public static void main(String[] args) {
  217.         Reader med = new Reader("Бронирование талона", Color.BLUE);
  218.         med.setVisible(true);
  219.         med.setResizable(false);
  220.         med.setLocationRelativeTo(null);
  221.  
  222.         Reader med2 = new Reader("Второе окно", Color.RED);
  223.         med2.setVisible(true);
  224.         med2.setResizable(false);
  225.         med2.setLocationRelativeTo(null);
  226.     }
  227. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement