p align="left">staff[4] = new Device("размер массива не является частью типа параметра. Поэтому функция не знает реального размера передаваемого массива. Компилятор тоже не может это проверить"); staff[5] = new Device("При проверке типов параметров компилятор способен распознать, что в обоих случаях тип аргумента int* соответствует объявлению функции. Однако контроль за тем, не является ли аргумент массивом, не производится."); staff[6] = new Device("По принятому соглашению C-строка является массивом символов, последний элемент которого равен нулю. Во всех остальных случаях при передаче массива в качестве параметра необходимо указывать его размер. Это относится и к массивам символов, внутри которых встречается 0. Обычно для такого указания используют дополнительный параметр функции."); staff[7] = new Device("Другой способ сообщить функции размер массива-параметра - объявить параметр как ссылку. В этом случае размер становится частью типа, и компилятор может проверить аргумент в полной мере."); staff[8] = new Device("Еще один способ получить размер переданного массива в функции - использовать абстрактный контейнерный тип. (Такие типы были представлены в главе 6. В следующем подразделе мы поговорим об этом подробнее"); staff[9] = new Device("Параметры шаблона заключаются в угловые скобки. Ключевое слово class означает, что идентификатор Type служит именем параметра, при конкретизации шаблона функции putValues() он заменяется на реальный тип - int, double, string и т.д. (В главе 10 мы продолжим разговор о шаблонах функций"); Device[] staff3 = new Device[10]; staff3[0] = new Device("Передача массивов в С++"); staff3[1] = new Device("Размер массива "); staff3[2] = new Device("Передача массивов как указателей имеет следующие особенности..."); staff3[3] = new Device("Свойство 1"); staff3[4] = new Device("Свойство 2"); staff3[5] = new Device("Расмотрение примера"); staff3[6] = new Device("Дополнительный параметер функции"); staff3[7] = new Device("Объявление параметра как ссылку"); staff3[8] = new Device("Абстрактный контейнерный тип"); staff3[9] = new Device("Шаблоны"); try { PrintWriter out = new PrintWriter( new FileWriter("device.dat")); writeData(staff,out); out.close(); PrintWriter out1 = new PrintWriter( new FileWriter("device1.dat")); writeData(staff3,out1); out1.close(); } catch(IOException exception){ exception.printStackTrace(); } } static void writeData(Device[] e, PrintWriter out) throws IOException { out.println(e.length); for(int i=0;i<e.length;i++) e[i].writeData(out); } } class ButtonFrame extends JFrame { public ButtonFrame() { Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int screenHeight = screenSize.height; int screenWidth = screenSize.width; setSize(screenWidth/2,screenHeight/2); setLocation(screenWidth/4,screenHeight/4); Image img = kit.getImage("icon.gif"); setIconImage(img); setTitle("CenteredFrame"); Container contantPane = getContentPane(); JMenuBar menuBar = new JMenuBar(); JMenu stMenu = new JMenu("Студент"); JMenuItem WorkSpace = new JMenuItem("Просмотреть материал",new ImageIcon("page_bookmark.gif")); stMenu.add(WorkSpace); menuBar.add(stMenu); JButton yellowButton = new JButton("WorkSpace"); JButton greenButton = new JButton("I_want_to_see"); JButton blueButton = new JButton("I am a teacher"); JButton redButton = new JButton("Check_Knowlarge"); JButton ExitButton = new JButton("Exit"); JPanel wer= new JPanel(); wer.add(yellowButton); wer.add (blueButton); wer.add(redButton); wer.add(ExitButton); wer.add(greenButton); //contantPane.add(wer,BorderLayout.SOUTH); contantPane.add(menuBar,BorderLayout.NORTH); ColorAction yellowAction = new ColorAction(2); ColorAction blueAction = new ColorAction(3); ColorAction redAction = new ColorAction(4); ColorAction ExitAction = new ColorAction(5); ColorAction greenAction = new ColorAction(6); yellowButton.addActionListener(yellowAction); blueButton.addActionListener(blueAction); redButton.addActionListener(redAction); ExitButton.addActionListener(ExitAction); greenButton.addActionListener(greenAction); WorkSpace.addActionListener(yellowAction); JMenuItem Check = new JMenuItem("Проверить знания",new ImageIcon("icon_security.gif")); stMenu.add(Check); Check.addActionListener(redAction); JMenuItem Exit = new JMenuItem("Выход",new ImageIcon("action_stop.gif")); stMenu.add(Exit); Exit.addActionListener(ExitAction); JMenu prMenu = new JMenu("Преподаватель"); JMenuItem teacher = new JMenuItem("Изменить",new ImageIcon("page_down.gif")); prMenu.add(teacher); teacher.addActionListener(blueAction); JMenuItem teacher1 = new JMenuItem("Посмотреть",new ImageIcon("icon_world_dynamic.gif")); prMenu.add(teacher1); teacher1.addActionListener(greenAction); menuBar.add(prMenu); try { FileInputStream is = new FileInputStream(new File("C:\\USER\\teacher.txt")); DataInputStream ids = new DataInputStream(is); String S2=ids.readUTF(); n=Integer.parseInt(S2); } catch(IOException exception){ System.out.println("bgbvhgfj"); } if(n==0) { teacher.setEnabled(false); teacher1.setEnabled(false); System.out.println(n); } else { Check.setEnabled(false); Exit.setEnabled(false); System.out.println(n); } } private class ColorAction implements ActionListener { public ColorAction(int c) { ccc=c; } public void actionPerformed(ActionEvent event) { if(ccc==2) { JFrame1 frame2 = new JFrame1 (); frame2.setVisible(true); } if(ccc==3) { JFrame2 frame3 = new JFrame2 (); frame3.setVisible(true); } if(ccc==4) { CheckBoxFrame frame3 = new CheckBoxFrame(); frame3.setVisible(true); } if(ccc==5) { MyTimer frame3 = new MyTimer(); frame3.setVisible(true); } if(ccc==6) { MyTimer1 frame3 = new MyTimer1(); frame3.setVisible(true); } } private int ccc; } private int n=0; } class MyTimer extends JFrame { public MyTimer() { setSize(650,350); setTitle("Your answer"); try { FileInputStream is = new FileInputStream(new File("C:\\USER\\NOW.txt")); DataInputStream ids = new DataInputStream(is); S2=ids.readUTF(); GregorianCalendar d = new GregorianCalendar(); int year=d.get(Calendar.YEAR); int mouth=d.get(Calendar.MONTH); int day=d.get(Calendar.DAY_OF_MONTH); int hour=d.get(Calendar.HOUR); int minute=d.get(Calendar.MINUTE); int seconds=d.get(Calendar.SECOND); FileInputStream is1 = new FileInputStream(new File("C:\\USER\\Time.txt")); DataInputStream ids1 = new DataInputStream(is1); String S22=ids1.readUTF(); int year_0=Integer.parseInt(S22); String S33=ids1.readUTF(); int mouth_0=Integer.parseInt(S33); String S44=ids1.readUTF(); int day_0=Integer.parseInt(S44); String S55=ids1.readUTF(); int hour_0=Integer.parseInt(S55); String S66=ids1.readUTF(); int minute_0=Integer.parseInt(S66); String S77=ids1.readUTF(); int seconds_0=Integer.parseInt(S77); if(seconds<seconds_0) { seconds_1=seconds-seconds_0+60; minute=minute-1; } else { seconds_1=seconds-seconds_0; } if(minute<minute_0) { minute_1=minute-minute_0+60; hour=hour-1; } else { minute_1=minute-minute_0; } if(hour<hour_0) { hour_1=hour-hour_0+24; day=day-1; } else { hour_1=hour-hour_0; } if(day<day_0) mouth==5 else { day_1=day-day_0; } if(mouth<mouth_0) { mouth_1=mouth - mouth_0+12; year=year-1; } else { mouth_1=mouth - mouth_0; } year_1=year-year_0; FileInputStream is12 = new FileInputStream(new File("C:\\Student\\"+S2+".txt")); ids13 = new DataInputStream(is12); String E=ids13.readUTF(); int f=Integer.parseInt(E); df=new Device[f]; m1=new int [f]; FileInputStream is121 = new FileInputStream(new File("C:\\Student1\\"+S2+".txt")); ids131 = new DataInputStream(is121); for(int r123=0;r123<f;r123++) { String E1=ids131.readUTF(); int f1=Integer.parseInt(E1); m1[r123]=f1; } BufferedReader in = new BufferedReader(new FileReader("device1.dat")); newStaff1=readData(in); in.close(); for(int g1=0;g1<f;g1++) { r3=m1[g1]; df[r34]=newStaff1[r3]; r34++; } label9= new JLabel("FFF"); for(int g1=0;g1<f;g1++) { String rrr=df[g1].getName(); hhh=hhh+"<br>"+rrr; } label9.setText("<html><br> Вы правильно ответили на следующие темы(это - "+(f*10)+"%)<br>"+hhh+"</html>"); Container contentPane = getContentPane (); JPanel panel = new JPanel(); JPanel panel1 = new JPanel(); label = new JLabel ("Вниманиe "+S2+" , вы прошли тестирование"); label1 = new JLabel ("Ваше время пребывания:"); label2 = new JLabel (year_1+" лет "); label3 = new JLabel (mouth_1+" месяцев "); label4 = new JLabel (day_1+" дней "); label5 = new JLabel (hour_1+" часов "); label6 = new JLabel (minute_1+" минут "); label7 = new JLabel (seconds_1+" секунд "); contentPane.add(label,BorderLayout.NORTH); panel1.add(label1); panel1.add(label2); panel1.add(label3);
Страницы: 1, 2, 3, 4
|