Browse Source

Создана ветвь

Настя 5 years ago
parent
commit
4b45c9df54
4 changed files with 196 additions and 22 deletions
  1. 16 0
      src/javaapp1/Average1.java
  2. 17 17
      src/javaapp1/Main.java
  3. 1 5
      src/javaapp1/Student.java
  4. 162 0
      src/javaapp1/Tablet1.java

+ 16 - 0
src/javaapp1/Average1.java

@@ -0,0 +1,16 @@
+package javaapp1;
+
+
+import java.io.*;
+import java.util.Scanner;
+ 
+class Average1{
+
+public double averageMark(double[] marks){
+    double sum = 0.0;
+    for (int i = 0; i < marks.length; i++){
+        sum += marks[i];
+    }
+    return sum/marks.length;
+}
+}

+ 17 - 17
src/javaapp1/Main.java

@@ -16,14 +16,14 @@ public class Main {
     public static void main (String[] args) {
         Main m = new Main();
         m.createData();
-        Tablet tablet = new Tablet();
+        Tablet1 tablet = new Tablet1();
         tablet.runGUI(m.students);
         Sortirovka sort = new Sortirovka();
-        m.students = sort.quickSort(m.students, 0);
+        //m.students = sort.quickSort(m.students, 0);
     }
 
     public void createData(){
-        Average avg = new Average();
+        /*Average avg = new Average();
         double[][] marks = {{5, 5, 4, 5, 4},
             {5, 4, 5, 5, 5},
             {4, 3, 4, 5, 5},
@@ -37,7 +37,7 @@ public class Main {
             {3, 5, 5, 4, 4},
             {5, 5, 5, 5, 5},
             {5, 5, 5, 5, 5}
-        };
+        };*/
         /*students = new Object[][]{
                     {"Андронова Вероника",new Double (5), new Double (5),new Double (4),new Double (5),new Double (4), avg.averageMark(marks[0])},
                  {"Баранов Михаил",new Double (5), new Double (4),new Double (5),new Double (5),new Double (5),avg.averageMark(marks[1])},
@@ -53,19 +53,19 @@ public class Main {
                  {"Подугольников Александр",new Double (5), new Double (5),new Double (5),new Double (5),new Double (5),avg.averageMark(marks[11])},
                  {"Тазиева Ирина",new Double (4), new Double (5),new Double (5),new Double (5),new Double (4),avg.averageMark(marks[12])}
           };*/
-        students.add(new Student("Андронова Вероника", 5, 5, 4, 5, 4, avg.averageMark(marks[0])));
-        students.add(new Student("Баранов Михаил", 5, 4, 5, 5, 5, avg.averageMark(marks[1])));
-        students.add(new Student("Белкин Пётр", 4, 3, 3, 5, 5, avg.averageMark(marks[2])));
-        students.add(new Student("Бурдаев Павел", 5, 4, 4, 5, 3, avg.averageMark(marks[3])));
-        students.add(new Student("Голубева Анастасия", 5, 4, 5, 5, 4, avg.averageMark(marks[4])));
-        students.add(new Student("Губанов Александр", 5, 4, 3, 5, 3, avg.averageMark(marks[5])));
-        students.add(new Student("Ларионова Анастасия", 5, 3, 5, 4, 5, avg.averageMark(marks[6])));
-        students.add(new Student("Леонов Никита", 4, 5, 5, 3, 3, avg.averageMark(marks[7])));
-        students.add(new Student("Лыско Илья", 4, 5, 5, 4, 3, avg.averageMark(marks[8])));
-        students.add(new Student("Марченков Максим", 4, 5, 5, 3, 5, avg.averageMark(marks[9])));
-        students.add(new Student("Пивоваров Тимур", 3, 5, 5, 4, 4, avg.averageMark(marks[10])));
-        students.add(new Student("Подугольников Александр", 5, 5, 5, 5, 5, avg.averageMark(marks[11])));
-        students.add(new Student("Тазиева Ирина", 4, 5, 5, 5, 4, avg.averageMark(marks[12])));
+        students.add(new Student("Андронова Вероника", 5, 5, 4, 5, 4));
+        students.add(new Student("Баранов Михаил", 5, 4, 5, 5, 5));
+        students.add(new Student("Белкин Пётр", 4, 3, 3, 5, 5));
+        students.add(new Student("Бурдаев Павел", 5, 4, 4, 5, 3));
+        students.add(new Student("Голубева Анастасия", 5, 4, 5, 5, 4));
+        students.add(new Student("Губанов Александр", 5, 4, 3, 5, 3));
+        students.add(new Student("Ларионова Анастасия", 5, 3, 5, 4, 5));
+        students.add(new Student("Леонов Никита", 4, 5, 5, 3, 3));
+        students.add(new Student("Лыско Илья", 4, 5, 5, 4, 3));
+        students.add(new Student("Марченков Максим", 4, 5, 5, 3, 5));
+        students.add(new Student("Пивоваров Тимур", 3, 5, 5, 4, 4));
+        students.add(new Student("Подугольников Александр", 5, 5, 5, 5, 5));
+        students.add(new Student("Тазиева Ирина", 4, 5, 5, 5, 4));
     }
     
 }

+ 1 - 5
src/javaapp1/Student.java

@@ -17,16 +17,14 @@ public class Student {
     public double markModelingSystems;
     public double markPravo;
     public double markTermeh;
-    public double markAverage;
     
-    Student (String name, double english, double bd, double modeling, double pravo, double termeh, double avg){
+    Student (String name, double english, double bd, double modeling, double pravo, double termeh){
         this.Name = name;
         this.markEnglish = english;
         this.markBD = bd;
         this.markModelingSystems = modeling;
         this.markPravo = pravo;
         this.markTermeh = termeh;
-        this.markAverage = avg;
     }
     
     public double getMark(int index){
@@ -41,8 +39,6 @@ public class Student {
                 return this.markPravo;
             case 5:
                 return this.markTermeh;
-            case 6:
-                return this.markAverage;
         }
         return 0;
     }

+ 162 - 0
src/javaapp1/Tablet1.java

@@ -0,0 +1,162 @@
+package javaapp1;
+
+    
+
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import javax.swing.*;
+import javax.swing.JFrame;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.table.*;
+import java.util.*;
+ 
+public class Tablet1 extends JFrame {
+ 
+     public void createGUI(ArrayList<Student> students) {
+          JFrame frame = new JFrame("Test frame");
+          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ 
+          String[] columnNames = {
+                    "ФИО",
+                    "Английский",
+                    "Базы данных",
+                    "Моделирование систем",
+                    "Право",
+                    "Термех"
+          };
+           
+          /*Object [][] data = {
+                    {"Андронова Вероника",new Double (5), new Double (5),new Double (4),new Double (5),new Double (4),""},
+                 {"Баранов Михаил",new Double (5), new Double (4),new Double (5),new Double (5),new Double (5),""},
+                 {"Белкин Пётр",new Double (4), new Double (3),new Double (4),new Double (5),new Double (5),""},
+                 {"Бурдаев Павел",new Double (5), new Double (4),new Double (4),new Double (5),new Double (3),""},
+                 {"Голубева Анастасия",new Double (5), new Double (4),new Double (5),new Double (5),new Double (4),""},
+                 {"Губанов Александр",new Double (5), new Double (4),new Double (3),new Double (5),new Double (3),""},
+                 {"Ларионова Анастасия",new Double (5), new Double (3),new Double (5),new Double (4),new Double (5),""},
+                 {"Леонов Никита",new Double (4), new Double (5),new Double (5),new Double (3),new Double (3),""},
+                 {"Лыско Илья",new Double (4), new Double (5),new Double (5),new Double (4),new Double (3),""},
+                 {"Марченков Максим",new Double (4), new Double (5),new Double (5),new Double (3),new Double (5),""},
+                 {"Пивоваров Тимур",new Double (3), new Double (5),new Double (5),new Double (4),new Double (4),""},
+                 {"Подугольников Александр",new Double (5), new Double (5),new Double (5),new Double (5),new Double (5),""},
+                 {"Тазиева Ирина",new Double (4), new Double (5),new Double (5),new Double (5),new Double (4),""}
+          };*/ 
+          Object[][] data = listToObject(students);
+          
+          TableModel model = new DefaultTableModel(data, columnNames) {
+          public Class getColumnClass(int column) {
+            Class returnValue;
+            if ((column >= 0) && (column < getColumnCount())) {
+              returnValue = getValueAt(0, column).getClass();
+            } else {
+              returnValue = Object.class;
+            }
+            return returnValue;
+          }
+        };
+          
+          JTable table = new JTable(model){
+              @Override
+            public boolean isCellEditable(int arg0, int arg1) {
+                return false;
+            }
+          };
+          
+          RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(
+            model);
+        table.setRowSorter(sorter);
+           
+          JScrollPane scrollPane = new JScrollPane(table);
+           
+          frame.getContentPane().add(scrollPane);
+          frame.setPreferredSize(new Dimension(450, 200));
+          frame.pack();
+          frame.setLocationRelativeTo(null);
+          frame.setVisible(true);
+          
+        table.addMouseListener(new MouseAdapter(){
+            public void mouseClicked(MouseEvent e){
+                if (e.getClickCount() == 2){
+                    JTable target = (JTable)e.getSource();
+                    int row = target.getSelectedRow();
+                    if (row != -1){
+                        String FIO = target.getValueAt(row, 0).toString();
+                        double English = (double)target.getValueAt(row, 1);
+                        double bd = (double)target.getValueAt(row, 2);
+                        double modelSystems = (double)target.getValueAt(row, 3);
+                        double pravo = (double)target.getValueAt(row, 4);
+                        double termeh = (double)target.getValueAt(row, 5);
+                        Average1 avg = new Average1();
+                        double[] marks = {English, bd, modelSystems, pravo, termeh};
+                        double avgMark = avg.averageMark(marks);
+
+                        JFrame frame2 = new JFrame(FIO);
+                        JPanel panel = new JPanel();
+                        panel.setPreferredSize(new Dimension(250, 100));
+                        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
+                        frame2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+                        String labelText = "English: " + Double.toString(English);
+                        JLabel labelEnglish = new JLabel(labelText);
+                        labelEnglish.setAlignmentX(panel.LEFT_ALIGNMENT);
+                        labelText = "BD: " + Double.toString(bd);
+                        JLabel labelBD = new JLabel(labelText);
+                        labelBD.setAlignmentX(panel.LEFT_ALIGNMENT);
+                        labelText = "Modeling Systems: " + Double.toString(modelSystems);
+                        JLabel labelModel = new JLabel(labelText);
+                        labelModel.setAlignmentX(panel.LEFT_ALIGNMENT);
+                        labelText = "Pravo: " + Double.toString(pravo);
+                        JLabel labelPravo = new JLabel(labelText);
+                        labelPravo.setAlignmentX(panel.LEFT_ALIGNMENT);
+                        labelText = "Termeh: " + Double.toString(termeh);
+                        JLabel labelTermeh = new JLabel(labelText);
+                        labelTermeh.setAlignmentX(panel.LEFT_ALIGNMENT);
+                        labelText = "Average mark: " + Double.toString(avgMark);
+                        JLabel labelAVG = new JLabel(labelText);
+                        labelAVG.setAlignmentX(panel.LEFT_ALIGNMENT);
+                        panel.add(labelEnglish);
+                        panel.add(labelBD);
+                        panel.add(labelModel);
+                        panel.add(labelPravo);
+                        panel.add(labelTermeh);
+                        panel.add(labelAVG);
+                        frame2.setContentPane(panel);
+                        frame2.setResizable(false);
+                        frame2.pack();
+                        frame2.setVisible(true);
+                    }
+                }
+            }
+        } );
+    }
+ 
+     public void runGUI(ArrayList<Student> students) {
+          javax.swing.SwingUtilities.invokeLater(new Runnable() {
+               public void run() {
+                    JFrame.setDefaultLookAndFeelDecorated(true);
+                    createGUI(students);
+               }
+          });
+     }
+     
+     public Object[][] listToObject(ArrayList<Student> students) {
+        Object[][] res = new Object[students.size()][6];
+        
+        Student student;
+        for (int i = 0; i < students.size(); i++){
+            Object[] ob = new Object[6];
+            student = students.get(i);
+            ob[0] = student.Name;
+            ob[1] = student.markEnglish;
+            ob[2] = student.markBD;
+            ob[3] = student.markModelingSystems;
+            ob[4] = student.markPravo;
+            ob[5] = student.markTermeh;
+            res[i] = ob;
+        }
+        return res;
+    }
+     
+    
+}