Advertisement
martaczaska

Licz_29.11

Nov 30th, 2020
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.41 KB | None | 0 0
  1. package eti.radio.pr_inz;
  2.  
  3. import javax.imageio.ImageIO;
  4. import javax.swing.*;
  5. import java.awt.event.MouseEvent;
  6. import java.awt.event.MouseListener;
  7. import java.awt.geom.*;
  8. import java.lang.Math;
  9. import java.awt.*;
  10. import java.awt.event.ActionEvent;
  11. import java.awt.event.ActionListener;
  12. import java.awt.image.BufferedImage;
  13. import java.io.File;
  14. import java.io.IOException;
  15.  
  16. public class Licz extends JPanel implements ActionListener, MouseListener {
  17.  
  18.     private JButton wykresy;
  19.     private JButton wyjscie;
  20.     private JLabel tytul6, l_BS0, l_BS1, l_BS2, l_BS3, l_BS4, l_BS5, l_BS6, l_UT, f_cLabel;
  21.     private JTextField f_cJT;
  22.     //public JSlider f_cSlider;
  23.     //public double xp = 470, yp = 400; //xp = 470, yp = 315;
  24.     public Double[] xp = new Double[850];
  25.     public Double[] yp = new Double[850];
  26.     //public double xp = 0, yp = 0; //xp = 470, yp = 315;
  27.     /*public Integer[] x = {0, -170, -170, 0, 170, 170, 0};
  28.     public Integer[] y = {0, -80, 77, 170, 77, -80, -170};*/
  29.     public Integer[] x = {470, 300, 300, 470, 640, 640, 470};
  30.     public Integer[] y = {400, 480, 313, 230, 313, 480, 570};
  31.     public BufferedImage tlo_dane;
  32.     //public double UT_x, UT_y;
  33.     public double BS0_x = x[0], BS0_y = y[0];
  34.  
  35.     String str_UT = "";
  36.  
  37.     int nw = 0, s = 1;
  38.     //double f_c = 2.6; // [GHz] *Math.pow(10, 9);
  39.     //double f_c = 10;
  40.     double d_2D; //m
  41.     double c = 3*Math.pow(10, 8);
  42.  
  43.     int d_2D_IN = 1;
  44.     int h_BS = 25, h_UT = 1;  ///zrobić jako Slidery
  45.     int h_E = 1; // 1m
  46.     int h = 5; //w metrach, do RMa
  47.     int W = 20; //w metrach, do RMa
  48.  
  49.     double sigma_LOS, sigma_NLOS;
  50.     public Double[][] PL_LOS= new Double[7][850];
  51.     public Double[][] PL_NLOS= new Double[7][850];
  52.     public Double[][] PL_NLOS2= new Double[7][850];
  53.     double d_BP, d2_BP;
  54.     //public Double[] p = {10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0};
  55.     public Double[] d2D = {10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0};
  56.     public Double[][] d_3D = new Double[7][850];
  57.     public Double[] radius = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
  58.     public Double[] SNR = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
  59.     public Double[] SNR_WAT = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
  60.     public double I_suma_NLOS = 0, I_suma_LOS = 0;
  61.     double N = -174;
  62.     double N_W = Math.pow(10, (N/10 - 3));
  63.  
  64.     Wykresy rysuj_wykresy;
  65.  
  66.     public Licz(Wykresy rysuj_wykresy){
  67.         setLayout(null);
  68.         this.rysuj_wykresy = rysuj_wykresy;
  69.  
  70.         File zdj_menu = new File("zdjecia/strona_logo.png");
  71.         try{ tlo_dane = ImageIO.read(zdj_menu); }
  72.         catch(IOException e){ System.err.println("Blad odczytu obrazków"); }
  73.  
  74.         wyjscie = new JButton("Wyjście");
  75.         wyjscie.addActionListener(this);
  76.         wyjscie.setBounds(100, 620, 200, 60);
  77.         wyjscie.setFont(new Font("Sitka Text", Font.BOLD, 25));
  78.         wyjscie.setBackground(Color.white);
  79.  
  80.         wykresy = new JButton("Wykresy");
  81.         wykresy.addActionListener(this);
  82.         wykresy.setBounds(724, 620, 200, 60);
  83.         wykresy.setFont(new Font("Sitka Text", Font.BOLD, 25));
  84.         wykresy.setBackground(Color.white);
  85.  
  86.         System.out.println("Wybrany model: " + s);
  87.         System.out.println("Wybrany scenariusz O2I: " + nw);
  88.  
  89.         tytul6 = new JLabel( "Wskaż położenie terminala użytkownika w komórce zerowej", JLabel.CENTER);
  90.         tytul6.setSize(1000, 100);
  91.         tytul6.setLocation(5, 50);
  92.         tytul6.setFont(new Font("Sitka Text", Font.BOLD, 23));
  93.  
  94.         l_BS0 = new JLabel( "BS0", JLabel.CENTER);
  95.         l_BS0.setFont(new Font("Sitka Text", Font.BOLD, 23));
  96.         l_BS1 = new JLabel( "BS1", JLabel.CENTER);
  97.         l_BS1.setFont(new Font("Sitka Text", Font.BOLD, 23));
  98.         l_BS2 = new JLabel( "BS2", JLabel.CENTER);
  99.         l_BS2.setFont(new Font("Sitka Text", Font.BOLD, 23));
  100.         l_BS3 = new JLabel( "BS3", JLabel.CENTER);
  101.         l_BS3.setFont(new Font("Sitka Text", Font.BOLD, 23));
  102.         l_BS4 = new JLabel( "BS4", JLabel.CENTER);
  103.         l_BS4.setFont(new Font("Sitka Text", Font.BOLD, 23));
  104.         l_BS5 = new JLabel( "BS5", JLabel.CENTER);
  105.         l_BS5.setFont(new Font("Sitka Text", Font.BOLD, 23));
  106.         l_BS6 = new JLabel( "BS6", JLabel.CENTER);
  107.         l_BS6.setFont(new Font("Sitka Text", Font.BOLD, 23));
  108.         l_UT = new JLabel( "UT", JLabel.CENTER);
  109.         l_UT.setFont(new Font("Sitka Text", Font.BOLD,23));
  110.         l_UT.setForeground(Color.RED);
  111.  
  112.         /*f_cSlider = new JSlider(3, 30, 3); // GHz
  113.         f_cSlider.setMajorTickSpacing(5);
  114.         f_cSlider.setMinorTickSpacing(1);
  115.         f_cSlider.setPaintLabels(true);
  116.         f_cSlider.setPaintTicks(true);
  117.         f_cSlider.setBounds(385, 650, 250, 50);
  118.         f_cSlider.setBackground(Color.WHITE);
  119.         f_cSlider.addChangeListener(this);
  120.  
  121.         f_cLabel = new JLabel();
  122.         f_cLabel.setBounds(450, 610, 200, 50);
  123.         f_cLabel.setFont(new Font("Sitka Text", Font.PLAIN, 16));
  124.         f_cLabel.setText("f = 3 GHz");*/
  125.  
  126.         f_cLabel = new JLabel("Podaj częstotliwość dla BS0 [GHz]:");
  127.         f_cLabel.setBounds(720, 350, 300, 50);
  128.         f_cLabel.setFont(new Font("Sitka Text", Font.BOLD, 16));
  129.         f_cJT = new JTextField("");
  130.         f_cJT.setBounds(800, 400, 100, 30);
  131.         f_cJT.setFont(new Font("Sitka Text", Font.PLAIN, 20));
  132.  
  133.         add(tytul6); add(l_BS0); add(l_BS1); add(l_BS2); add(l_BS3); add(l_BS4); add(l_BS5); add(l_BS6); add(l_UT); add(wyjscie); add(wykresy);
  134.         add(f_cLabel); add(f_cJT);
  135.         addMouseListener(this);
  136.     }
  137.  
  138.     public void actionPerformed(ActionEvent e){
  139.         Object source = e.getSource();
  140.         if(source == wykresy){
  141.             CardLayout CL =(CardLayout)(Main.noweOkno.karty.getLayout());
  142.             CL.show(Main.noweOkno.karty, "rysuj_wykresy");
  143.  
  144.             rysuj_wykresy.f_c = Double.parseDouble(f_cJT.getText());
  145.             System.out.println("Wpisana częstotliwość f_c : " + rysuj_wykresy.f_c);
  146.  
  147.             rysuj_wykresy.pathLossDlaModelu(rysuj_wykresy.UT_x, rysuj_wykresy.UT_y, rysuj_wykresy.f_c, false);
  148.             rysuj_wykresy.licz_SINR();
  149.             rysuj_wykresy.daneNLOS();
  150.             rysuj_wykresy.daneLOS();
  151.             rysuj_wykresy.zaniki();
  152.             rysuj_wykresy.daneNLOS_zaniki();
  153.             rysuj_wykresy.daneLOS_zaniki();
  154.             rysuj_wykresy.Rysuj_wykres();
  155.  
  156.             System.out.println("SINR dla NLOS : " + rysuj_wykresy.SINR_dB_NLOS[0]);
  157.             System.out.println("SINR dla LOS : " + rysuj_wykresy.SINR_dB_LOS[0]);
  158.  
  159.         }
  160.         else if(source == wyjscie){
  161.             System.exit(0);
  162.         }
  163.     }
  164.  
  165.     public void mouseClicked(MouseEvent e) {}
  166.  
  167.     public void mousePressed(MouseEvent e) {
  168.         rysuj_wykresy.UT_x = e.getX();
  169.         rysuj_wykresy.UT_y = e.getY();
  170.         str_UT = "UT";
  171.         System.out.println("Nacisnięty punkt: x = " + rysuj_wykresy.UT_x + " y = " + rysuj_wykresy.UT_y);
  172.         repaint();
  173.     }
  174.  
  175.     public void mouseReleased(MouseEvent e) {}
  176.     public void mouseEntered(MouseEvent e) {}
  177.     public void mouseExited(MouseEvent e) {}
  178.  
  179.     public void paintComponent(Graphics graphic) {
  180.         //int R = Math.round(Math.sqrt(3)*125);
  181.         Graphics2D g2d = (Graphics2D) graphic;
  182.         g2d.drawImage(tlo_dane, 0, 0, this);
  183.  
  184.         Ellipse2D circle0 = new Ellipse2D.Double(370, 300, 200, 200);
  185.         Rectangle2D BS0 = new Rectangle2D.Double((int)circle0.getCenterX(), (int)circle0.getCenterY(), 5, 5);
  186.         l_BS0.setBounds((int)BS0.getX()-15, (int)BS0.getY()-15, 100, 50);
  187.  
  188.  
  189.         Ellipse2D circle1 = new Ellipse2D.Double(200, 380, 200, 200);
  190.         Rectangle2D BS1 = new Rectangle2D.Double((int)circle1.getCenterX(), (int)circle1.getCenterY(), 5, 5);
  191.         l_BS1.setBounds((int)BS1.getX()-15, (int)BS1.getY()-15, 100, 50);
  192.  
  193.         Ellipse2D circle2 = new Ellipse2D.Double(200, 213, 200, 200);
  194.         Rectangle2D BS2 = new Rectangle2D.Double((int)circle2.getCenterX(), (int)circle2.getCenterY(), 5, 5);
  195.         l_BS2.setBounds((int)BS2.getX()-15, (int)BS2.getY()-15, 100, 50);
  196.  
  197.         Ellipse2D circle3 = new Ellipse2D.Double(370, 130, 200, 200);
  198.         Rectangle2D BS3 = new Rectangle2D.Double((int)circle3.getCenterX(), (int)circle3.getCenterY(), 5, 5);
  199.         l_BS3.setBounds((int)BS3.getX()-15, (int)BS3.getY()-15, 100, 50);
  200.  
  201.         Ellipse2D circle4 = new Ellipse2D.Double(540, 213, 200, 200);
  202.         Rectangle2D BS4 = new Rectangle2D.Double((int)circle4.getCenterX(), (int)circle4.getCenterY(), 5, 5);
  203.         l_BS4.setBounds((int)BS4.getX()-15, (int)BS4.getY()-15, 100, 50);
  204.  
  205.         Ellipse2D circle5 = new Ellipse2D.Double(540, 380, 200, 200);
  206.         Rectangle2D BS5 = new Rectangle2D.Double((int)circle5.getCenterX(), (int)circle5.getCenterY(), 5, 5);
  207.         l_BS5.setBounds((int)BS5.getX()-15, (int)BS5.getY()-15, 100, 50);
  208.  
  209.         Ellipse2D circle6 = new Ellipse2D.Double(370, 470,200, 200);
  210.         Rectangle2D BS6 = new Rectangle2D.Double((int)circle6.getCenterX(), (int)circle6.getCenterY(), 5, 5);
  211.         l_BS6.setBounds((int)BS6.getX()-15, (int)BS6.getY()-15, 100, 50);
  212.  
  213.         Ellipse2D UT = new Ellipse2D.Double(rysuj_wykresy.UT_x, rysuj_wykresy.UT_y, 5, 5);
  214.         l_UT.setBounds((int)UT.getX()-15, (int)UT.getY()-15, 80, 50);
  215.  
  216.         g2d.draw(UT); g2d.draw(BS0); g2d.draw(BS1); g2d.draw(BS2); g2d.draw(BS3); g2d.draw(BS4); g2d.draw(BS5); g2d.draw(BS6);
  217.         g2d.draw(circle0); g2d.draw(circle1); g2d.draw(circle2); g2d.draw(circle3); g2d.draw(circle4); g2d.draw(circle5); g2d.draw(circle6);
  218.     }
  219.  
  220.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement