diff --git a/java/labs/DEV-J120.Задача 4.pdf b/java/labs/DEV-J120.Задача 4.pdf new file mode 100644 index 0000000..c66a3c9 Binary files /dev/null and b/java/labs/DEV-J120.Задача 4.pdf differ diff --git a/java/labs/j120-lab3.pdf b/java/labs/j120-lab3.pdf new file mode 100644 index 0000000..4260e32 Binary files /dev/null and b/java/labs/j120-lab3.pdf differ diff --git a/java/labs/j130-lab1.pdf b/java/labs/j130-lab1.pdf new file mode 100644 index 0000000..6fd587c Binary files /dev/null and b/java/labs/j130-lab1.pdf differ diff --git a/java/samples/collections/CollectionExample.java b/java/samples/collections/CollectionExample.java new file mode 100644 index 0000000..f9ed9e7 --- /dev/null +++ b/java/samples/collections/CollectionExample.java @@ -0,0 +1,125 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package collectionexample; + +import java.io.File; +import java.io.FileReader; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +/** + * + * @author denis + */ +public class CollectionExample { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + //collectionInteger(); + + collectionPerson(); + } + + public static void collectionPerson(){ + System.out.println("-----------------ArrayList------------------"); + List intArray = new ArrayList<>(); + intArray.add(new Person("Boby", 11)); + intArray.add(new Person("Andrey", 4)); + intArray.add(new Person("Boby", 1)); + intArray.add(new Person("Boby", 10)); + intArray.add(new Person("Boby", 5)); + intArray.forEach(System.out::println); + + System.out.println("-----------------LinkedList------------------"); + List intLink = new LinkedList<>(intArray); + intLink.forEach(System.out::println); + + System.out.println("-----------------HashSet------------------"); + Set intHashSet = new HashSet<>(intArray); + intHashSet.forEach(System.out::println); + + System.out.println("-----------------TreeSet------------------"); +// Set intTreeSet = new TreeSet<>(new Comparator() { +// @Override +// public int compare(Person o1, Person o2) { +// int res = o2.name.compareTo(o1.name); +// if(res==0) res = o2.phone.compareTo(o1.phone); +// return res; +// } +// }); + Set intTreeSet = new TreeSet<>((o1, o2) -> { + int res = o2.name.compareTo(o1.name); + if(res==0) res = o2.phone.compareTo(o1.phone); + return res; + }); + //Set intTreeSet = new TreeSet<>((o1, o2) -> o2.name.compareTo(o1.name)); + intTreeSet.addAll(intLink); + intTreeSet.forEach(System.out::println); + + System.out.println("-----------------HashMap------------------"); + Map maps = new HashMap<>(); + maps.put(intArray.get(0).phone, intArray.get(0)); + maps.put(intArray.get(1).phone, intArray.get(1)); + maps.put(intArray.get(2).phone, intArray.get(2)); + maps.put(intArray.get(3).phone, intArray.get(3)); + maps.put(intArray.get(4).phone, intArray.get(4)); + maps.forEach((e1, e2) -> {System.out.println(e1 + ": " + e2);}); + + } + + public static void collectionInteger(){ + System.out.println("-----------------ArrayList------------------"); + List intArray = new ArrayList<>(); + intArray.add(50); + intArray.add(26); + intArray.add(26); + intArray.add(50); + intArray.add(50); + intArray.forEach(System.out::println); + + System.out.println("-----------------LinkedList------------------"); + List intLink = new LinkedList<>(intArray); + intLink.forEach(System.out::println); + + System.out.println("-----------------HashSet------------------"); + Set intHashSet = new HashSet<>(intArray); + intHashSet.forEach(System.out::println); + + System.out.println("-----------------TreeSet------------------"); + Set intTreeSet = new TreeSet<>(intArray); + intTreeSet.forEach(System.out::println); + + System.out.println("-----------------HashMap------------------"); + Map maps = new HashMap<>(); + maps.put("One", intArray.get(0)); + maps.put("Two", intArray.get(1)); + maps.put("Three", intArray.get(2)); + maps.put("Four", intArray.get(3)); + maps.put("Five", intArray.get(4)); + maps.forEach((e1, e2) -> {System.out.println(e1 + ": " + e2);}); + + System.out.println("-----------------LinkedHashMap------------------"); + Map mapsLink = new LinkedHashMap<>(); + mapsLink.put("One", intArray.get(0)); + mapsLink.put("Two", intArray.get(1)); + mapsLink.put("Three", intArray.get(2)); + mapsLink.put("Four", intArray.get(3)); + mapsLink.put("Five", intArray.get(4)); + mapsLink.forEach((e1, e2) -> {System.out.println(e1 + ": " + e2);}); + } + +} diff --git a/java/samples/collections/CollectionExample2.java b/java/samples/collections/CollectionExample2.java new file mode 100644 index 0000000..4ace277 --- /dev/null +++ b/java/samples/collections/CollectionExample2.java @@ -0,0 +1,131 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package collectionexample2; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +/** + * + * @author denis + */ +public class CollectionExample2 { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + unique(); + //simple(); + + } + + private static void unique(){ + System.out.println("--------------------ArrayList-------------------------"); + List arrayList = new ArrayList<>(); + arrayList.add(new User("Andrey", 15)); + arrayList.add(new User("Andrey", 20)); + arrayList.add(new User("Andrey", 15)); + arrayList.add(new User("Andrey", 16)); + System.out.println("contains=" + arrayList.contains(new User("Andrey", 15))); + arrayList.forEach(System.out::println); + + { + System.out.println("--------------------LinkedList-------------------------"); + List collection = new LinkedList<>(arrayList); + collection.forEach(System.out::println); + } + + System.out.println("--------------------HashSet-------------------------"); + { + System.out.println("--------------------LinkedList-------------------------"); + Set collection = new HashSet<>(arrayList); + collection.forEach(System.out::println); + } + + System.out.println("--------------------TreeSet-------------------------"); + { + System.out.println("--------------------LinkedList-------------------------"); + SortedSet collection = new TreeSet<>(arrayList); + collection.forEach(System.out::println); + } + + System.out.println("--------------------HashMap-------------------------"); + { + Map mapColl = new HashMap<>(); + mapColl.put(1, new User("Andrey", 15)); + mapColl.put(10, new User("Andrey", 15)); + mapColl.put(5, new User("Andrey", 20)); + mapColl.put(9, new User("Andrey", 16)); + System.out.println("contains=" + mapColl.containsValue(new User("Andrey", 15))); + mapColl.entrySet().forEach(e -> System.out.println(e)); + } + + System.out.println("--------------------LinkedHashMap-------------------------"); + { + Map mapColl = new LinkedHashMap<>(); + mapColl.put(1, new User("Andrey", 15)); + mapColl.put(10, new User("Andrey", 15)); + mapColl.put(5, new User("Andrey", 20)); + mapColl.put(9, new User("Andrey", 16)); + System.out.println("contains=" + mapColl.containsValue(new User("Andrey", 15))); + mapColl.entrySet().forEach(e -> System.out.println(e)); + } + } + + private static void simple(){ + System.out.println("--------------------ArrayList-------------------------"); + List arrayList = new ArrayList<>(); + arrayList.add("Once"); + arrayList.add("Two"); + arrayList.add("Two"); + arrayList.add("Two"); + arrayList.add("Three"); + arrayList.add("Four"); + arrayList.add("Five"); + arrayList.add("Five"); + arrayList.forEach(System.out::println); + + System.out.println("--------------------LinkedList-------------------------"); + List linkedList = new LinkedList<>(arrayList); + linkedList.forEach(System.out::println); + + System.out.println("--------------------HashSet-------------------------"); + Set hashSet = new HashSet<>(arrayList); + hashSet.forEach(System.out::println); + + System.out.println("--------------------TreeSet-------------------------"); + SortedSet sorted = new TreeSet<>(arrayList); + sorted.forEach(System.out::println); + + System.out.println("--------------------HashMap-------------------------"); + Map mapColl = new HashMap<>(); + mapColl.put(1, "Once"); + mapColl.put(10, "Once"); + mapColl.put(5, "Two"); + mapColl.put(9, null); + mapColl.put(0, "Five"); + mapColl.entrySet().forEach(e -> System.out.println(e)); + + System.out.println("--------------------LinkedHashMap-------------------------"); + Map hashMap = new LinkedHashMap<>(); + hashMap.put(1, "Once"); + hashMap.put(10, "Once"); + hashMap.put(5, "Two"); + hashMap.put(9, null); + hashMap.put(0, "Five"); + hashMap.entrySet().forEach(e -> System.out.println(e)); + } + +} diff --git a/java/samples/collections/Person.java b/java/samples/collections/Person.java new file mode 100644 index 0000000..1a80bb6 --- /dev/null +++ b/java/samples/collections/Person.java @@ -0,0 +1,69 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package collectionexample; + +import java.util.Objects; + +/** + * + * @author denis + */ +public class Person implements Comparable{ + + public String name; + public Integer phone; + + public Person(String name, Integer phone) { + this.name = name; + this.phone = phone; + } + + @Override + public String toString() { + return "Person{" + "name=" + name + ", phone=" + phone + '}'; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 37 * hash + Objects.hashCode(this.name); + hash = 37 * hash + Objects.hashCode(this.phone); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Person other = (Person) obj; + if (!Objects.equals(this.name, other.name)) { + return false; + } + if (!Objects.equals(this.phone, other.phone)) { + return false; + } + if (!Objects.equals(this.hashCode(), other.hashCode())) { + return false; + } + return true; + } + + @Override + public int compareTo(Person person) { + int res = this.name.compareTo(person.name); + if(res==0) res = this.phone.compareTo(person.phone); + return res; + } + + +} diff --git a/java/samples/collections/User.java b/java/samples/collections/User.java new file mode 100644 index 0000000..0f4baeb --- /dev/null +++ b/java/samples/collections/User.java @@ -0,0 +1,68 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package collectionexample2; + +import java.util.Objects; + +/** + * + * @author denis + */ +public class User implements Comparable{ + String name; + Integer age; + + public User(String name, Integer age) { + this.name = name; + this.age = age; + } + + @Override + public String toString() { + return "User{" + "name=" + name + ", age=" + age + '}'; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 37 * hash + Objects.hashCode(this.name); + hash = 37 * hash + Objects.hashCode(this.age); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final User other = (User) obj; + if (!Objects.equals(this.name, other.name)) { + return false; + } + if (!Objects.equals(this.age, other.age)) { + return false; + } + if (!Objects.equals(this.hashCode(), other.hashCode())) { + return false; + } + return true; + } + + @Override + public int compareTo(User o) { + int res = this.name.compareTo(o.name); + if(res == 0) res = this.age.compareTo(o.age); + return res; + } + + +} diff --git a/java/samples/file/FileReaderAndWriter.java b/java/samples/file/FileReaderAndWriter.java new file mode 100644 index 0000000..654622e --- /dev/null +++ b/java/samples/file/FileReaderAndWriter.java @@ -0,0 +1,60 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package filereaderandwriter; + +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author denis + */ +public class FileReaderAndWriter { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + File file = new File("Text.txt"); + if(!file.exists()) try { + file.createNewFile(); + } catch (IOException ex) { + Logger.getLogger(FileReaderAndWriter.class.getName()).log(Level.SEVERE, null, ex); + } + + if(file.canWrite()){ + + String line = "Hello world!"; + try (FileWriter writer = new FileWriter(file, true)) { + writer.append("\n" + line); + } catch (IOException ex) { + Logger.getLogger(FileReaderAndWriter.class.getName()).log(Level.SEVERE, null, ex); + } + + } + + if(file.canRead()){ + String line = ""; + try(FileReader reader = new FileReader(file)){ + + char[]buf = new char[5]; + int c =0; + while((c=reader.read(buf))!=-1){ + line += new String(buf, 0, c); + } + + }catch (IOException ex) { + Logger.getLogger(FileReaderAndWriter.class.getName()).log(Level.SEVERE, null, ex); + } + System.out.println(line); + } + } + +} diff --git a/java/samples/file/FileReaderAndWriter2.java b/java/samples/file/FileReaderAndWriter2.java new file mode 100644 index 0000000..b7f45ae --- /dev/null +++ b/java/samples/file/FileReaderAndWriter2.java @@ -0,0 +1,49 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package filereaderandwriter2; + +import java.io.File; +import java.io.*; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author denis + */ +public class FileReaderAndWriter2 { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + File file = new File("SameFile.txt"); + if(!file.exists()) try { + file.createNewFile(); + } catch (IOException ex) { + Logger.getLogger(FileReaderAndWriter2.class.getName()).log(Level.SEVERE, null, ex); + } + + String message = "Hello world"; + try (FileWriter writer = new FileWriter(file, true)) { + writer.append("\n" + message); + } catch (IOException ex) { + } + + try(FileReader reader = new FileReader(file)){ + StringBuffer buffer = new StringBuffer(); + char[] cbuf = new char[1024]; + int count = 0; + while((count = reader.read(cbuf)) != -1){ + buffer.append(new String(cbuf, 0, count)); + } + System.out.println(buffer.toString()); + }catch(IOException e) {} + + } + +} diff --git a/java/samples/pecs/City.java b/java/samples/pecs/City.java new file mode 100644 index 0000000..ed78e8b --- /dev/null +++ b/java/samples/pecs/City.java @@ -0,0 +1,14 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package rulespecs; + +/** + * + * @author denis + */ +public class City extends Country{ + +} diff --git a/java/samples/pecs/Country.java b/java/samples/pecs/Country.java new file mode 100644 index 0000000..49421e1 --- /dev/null +++ b/java/samples/pecs/Country.java @@ -0,0 +1,14 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package rulespecs; + +/** + * + * @author denis + */ +public class Country { + +} diff --git a/java/samples/pecs/District.java b/java/samples/pecs/District.java new file mode 100644 index 0000000..a82bf62 --- /dev/null +++ b/java/samples/pecs/District.java @@ -0,0 +1,17 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package rulespecs; + +/** + * + * @author denis + */ +public class District extends City{ + + public void methods(){ + + } +} diff --git a/java/samples/pecs/RulesPECS.java b/java/samples/pecs/RulesPECS.java new file mode 100644 index 0000000..cfeaca7 --- /dev/null +++ b/java/samples/pecs/RulesPECS.java @@ -0,0 +1,62 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package rulespecs; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author denis + */ +public class RulesPECS { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + RulesPECS rules = new RulesPECS(); + + List countrys = new ArrayList<>(); + countrys.add(new Country()); + List citys = new ArrayList<>(); + citys.add(new City()); + List districts = new ArrayList<>(); + districts.add(new District()); + List streets = new ArrayList<>(); + streets.add(new Street()); + + rules.producer(countrys); + rules.producer(citys); + rules.producer(districts); + rules.producer(streets); + + rules.consumer(countrys); + rules.consumer(citys); + rules.consumer(districts); + rules.consumer(streets); + } + + public void producer (List list){ + list.add(new Country()); + list.add(new City()); + list.add(new District()); + list.add(new Street()); + } + + public void consumer (List list){ + Object district = list.get(0); + if(district instanceof Country) System.out.println("Object is Country"); + if(district instanceof City) System.out.println("Object is City"); + if(district instanceof District) System.out.println("Object is District"); + if(district instanceof Street) System.out.println("Object is Street"); + list.add(new Country()); + list.add(new City()); + list.add(new District()); + list.add(new Street()); + } + +} diff --git a/java/samples/pecs/Street.java b/java/samples/pecs/Street.java new file mode 100644 index 0000000..53a068e --- /dev/null +++ b/java/samples/pecs/Street.java @@ -0,0 +1,14 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package rulespecs; + +/** + * + * @author denis + */ +public class Street extends District{ + +} diff --git a/java/samples/pecs/rulespecs2/City.java b/java/samples/pecs/rulespecs2/City.java new file mode 100644 index 0000000..11f7a05 --- /dev/null +++ b/java/samples/pecs/rulespecs2/City.java @@ -0,0 +1,26 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package rulespecs2; + +/** + * + * @author denis + */ +public class City extends Country{ + protected String nameCity; + + public City(String nameCity, String nameCountry) { + super(nameCountry); + this.nameCity = nameCity; + } + + @Override + public String toString() { + return "City{" + "nameCountry=" + nameCountry + "nameCity=" + nameCity + '}'; + } + + +} diff --git a/java/samples/pecs/rulespecs2/Country.java b/java/samples/pecs/rulespecs2/Country.java new file mode 100644 index 0000000..5871b19 --- /dev/null +++ b/java/samples/pecs/rulespecs2/Country.java @@ -0,0 +1,25 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package rulespecs2; + +/** + * + * @author denis + */ +public class Country { + protected String nameCountry; + + public Country(String nameCountry) { + this.nameCountry = nameCountry; + } + + @Override + public String toString() { + return "Country{" + "nameCountry=" + nameCountry + '}'; + } + + +} diff --git a/java/samples/pecs/rulespecs2/District.java b/java/samples/pecs/rulespecs2/District.java new file mode 100644 index 0000000..03ee1c7 --- /dev/null +++ b/java/samples/pecs/rulespecs2/District.java @@ -0,0 +1,27 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package rulespecs2; + +/** + * + * @author denis + */ +public class District extends City{ + + protected String nameDistrict; + + public District(String nameDistrict, String nameCity, String nameCountry) { + super(nameCity, nameCountry); + this.nameDistrict = nameDistrict; + } + + @Override + public String toString() { + return "District{" + "nameCountry=" + nameCountry + "nameCity=" + nameCity + "nameDistrict=" + nameDistrict + '}'; + } + + +} diff --git a/java/samples/pecs/rulespecs2/RulesPECS2.java b/java/samples/pecs/rulespecs2/RulesPECS2.java new file mode 100644 index 0000000..4f822eb --- /dev/null +++ b/java/samples/pecs/rulespecs2/RulesPECS2.java @@ -0,0 +1,52 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package rulespecs2; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author denis + */ +public class RulesPECS2 { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + RulesPECS2 pecs = new RulesPECS2(); + List countrys = new ArrayList<>(); + pecs.consumerCity(countrys); + pecs.consumerStreet(countrys); + pecs.consumerDistrict(countrys); + + countrys.forEach(System.out::println); + } + + + public void producer(List list){ + + } + + public void consumerStreet(List list){ + list.add(new Street("Ленинский пр.", "Кировский", "Санкт-Петербург", "Россия")); + list.add(new Street("Московский пр.", "Московский", "Санкт-Петербург", "Россия")); + list.add(new Street("Стачек пр.", "Кировский", "Санкт-Петербург", "Россия")); + } + + public void consumerDistrict(List list){ + list.add(new District("Невский", "Санкт-Петербург", "Россия")); + } + + public void consumerCity(List list){ + list.add(new City("Санкт-Петербург", "Россия")); + } + + public void method(List list){ + + } +} diff --git a/java/samples/pecs/rulespecs2/Street.java b/java/samples/pecs/rulespecs2/Street.java new file mode 100644 index 0000000..71894e6 --- /dev/null +++ b/java/samples/pecs/rulespecs2/Street.java @@ -0,0 +1,30 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package rulespecs2; + +/** + * + * @author denis + */ +public class Street extends District{ + + protected String nameStreet; + + public Street(String nameStreet, String nameDistrict, String nameCity, String nameCountry) { + super(nameDistrict, nameCity, nameCountry); + this.nameStreet = nameStreet; + } + + @Override + public String toString() { + return "Street{" + "nameCountry=" + nameCountry + "nameCity=" + nameCity + "nameDistrict=" + nameDistrict + "nameStreet=" + nameStreet + '}'; + } + + + + + +} diff --git a/java/samples/properties/PropertiesExample.java b/java/samples/properties/PropertiesExample.java new file mode 100644 index 0000000..d35140f --- /dev/null +++ b/java/samples/properties/PropertiesExample.java @@ -0,0 +1,57 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package propertiesexample; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Properties; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author denis + */ +public class PropertiesExample { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + File fileProp = new File("prop.properties"); + if(!fileProp.exists()) try { + fileProp.createNewFile(); + } catch (IOException ex) { + Logger.getLogger(PropertiesExample.class.getName()).log(Level.SEVERE, null, ex); + } + + Properties properties = new Properties(); + try { + properties.load(new FileReader(fileProp)); + } catch (FileNotFoundException ex) { + Logger.getLogger(PropertiesExample.class.getName()).log(Level.SEVERE, null, ex); + } catch (IOException ex) { + Logger.getLogger(PropertiesExample.class.getName()).log(Level.SEVERE, null, ex); + } + +// properties.put("key", "key value"); +// properties.put("key", "key value2"); +// properties.put("key2", "key value2"); + + System.out.println(properties.getProperty("nameK", "Key is not exist")); + + try { + properties.store(new FileWriter(fileProp), null); + } catch (IOException ex) { + Logger.getLogger(PropertiesExample.class.getName()).log(Level.SEVERE, null, ex); + } + + } + +} diff --git a/java/samples/properties/swing1/AuthorizationFrame.java b/java/samples/properties/swing1/AuthorizationFrame.java new file mode 100644 index 0000000..ba42407 --- /dev/null +++ b/java/samples/properties/swing1/AuthorizationFrame.java @@ -0,0 +1,99 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package propertiesswing; + +import java.awt.BorderLayout; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.GridLayout; +import java.util.List; +import java.util.Set; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JPasswordField; +import javax.swing.JTextField; + +/** + * + * @author denis + */ +public class AuthorizationFrame extends JFrame{ + + + + public AuthorizationFrame(){ + init(); + setTitle("Authorization"); + setLocationRelativeTo(null); + setSize(400, 250); + //pack(); + setResizable(false); + + setVisible(true); + } + + private void init(){ + // Создаём верхнюю метку "Autorization" и размещаем её в панели "northPanel" + JPanel northPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 40, 20)); + JLabel authLabel = new JLabel("Authorization"); + northPanel.add(authLabel); + + GridBagLayout gridLayout = new GridBagLayout(); + GridBagConstraints constraints = new GridBagConstraints(); + JPanel centerPanel = new JPanel(gridLayout); + JLabel usernameLabel = new JLabel("username"); + JTextField usernameField = new JTextField(30); + JLabel passwordLabel = new JLabel("password"); + JPasswordField passwordField = new JPasswordField(30); + constraints.gridx = 0; + constraints.gridy = 0; + centerPanel.add(usernameLabel, constraints); + constraints.gridx = 1; + constraints.gridy = 0; + centerPanel.add(usernameField, constraints); + constraints.gridx = 0; + constraints.gridy = 1; + centerPanel.add(passwordLabel, constraints); + constraints.gridx = 1; + constraints.gridy = 1; + centerPanel.add(passwordField, constraints); + + //Создаём две кнопки "SingIn" и "Cancel" и размещаем их в панели "southPanel" + JButton singinButton = new JButton("SingIn"); + singinButton.addActionListener(e -> { + Set persons = PersonStore.getPersonStore().getPersons(); + persons.forEach(person -> { + if(usernameField.getText().equals(person.getUsername()) && + passwordField.getText().equals(person.getPassword())){ + new MainFrame(); + } + }); + }); + JButton cancelButton = new JButton("Cancel"); + cancelButton.addActionListener(e -> { + System.exit(0); + }); + JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 40, 20)); + southPanel.add(singinButton); + southPanel.add(cancelButton); + + + //Помещаем панели в главном контейнере + getContentPane().setLayout(new BorderLayout()); + getContentPane().add(northPanel, BorderLayout.NORTH); + getContentPane().add(centerPanel, BorderLayout.CENTER); + getContentPane().add(southPanel, BorderLayout.SOUTH); + setDefaultCloseOperation(DISPOSE_ON_CLOSE); + } + + + +} diff --git a/java/samples/properties/swing1/MainFrame.java b/java/samples/properties/swing1/MainFrame.java new file mode 100644 index 0000000..675ebb7 --- /dev/null +++ b/java/samples/properties/swing1/MainFrame.java @@ -0,0 +1,124 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package propertiesswing; + +import java.awt.Container; +import java.awt.FlowLayout; +import java.awt.GridLayout; +import java.awt.Label; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Properties; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.JButton; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; + +/** + * + * @author denis + */ +public class MainFrame extends JFrame{ + + private File file; + private Properties properties; + private JTextField currentField = new JTextField(50); + private JTextField powerField = new JTextField(50); + private JTextField frecField = new JTextField(50); + + public MainFrame(){ + setTitle("Propetries"); + setSize(600, 600); + Container container = getContentPane(); + GridLayout layout = new GridLayout(0, 1); + container.setLayout(layout); + container.add(initManageButtons()); + container.add(initFields("Current: ", currentField)); + container.add(initFields("Power: ", powerField)); + container.add(initFields("Frec: ", frecField)); + + setLocationRelativeTo(null); + setDefaultCloseOperation(DISPOSE_ON_CLOSE); + pack(); + setVisible(true); + } + + private JPanel initFields(String textLabel, JTextField field){ + JPanel panel = new JPanel(new FlowLayout()); + JLabel label = new JLabel(textLabel); + panel.add(label); + panel.add(field); + return panel; + } + + private void initFileChooser(){ + JFileChooser chooser = new JFileChooser(); + chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + int result = chooser.showOpenDialog(this); + if(result == JFileChooser.APPROVE_OPTION){ + file = chooser.getSelectedFile(); + } + } + + private JPanel initManageButtons(){ + JPanel panel = new JPanel(new FlowLayout(10, 20, 20)); + JButton openButton = new JButton("Open file"); + panel.add(openButton); + openButton.addActionListener(e -> { + initFileChooser(); + if(file!=null && file.exists() && file.canRead()){ + loadProperties(); + if(properties!=null) { + if(currentField!=null) currentField.setText(properties.getProperty("Current")); + if(powerField!=null) powerField.setText(properties.getProperty("Power")); + if(frecField!=null) frecField.setText(properties.getProperty("Frec")); + } + } + }); + JButton saveButton = new JButton("Save file"); + panel.add(saveButton); + saveButton.addActionListener(e -> { + if(file!=null && properties!=null){ + properties.put("Current", currentField.getText()); + properties.put("Power", powerField.getText()); + properties.put("Frec", frecField.getText()); + saveProperties(); + } + }); + return panel; + } + + + + private void loadProperties(){ + properties = new Properties(); + try { + properties.load(new FileReader(file)); + } catch (FileNotFoundException ex) { + Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); + } catch (IOException ex) { + Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); + } + } + + private void saveProperties(){ + if(properties!=null){ + try { + properties.store(new FileWriter(file), null); + } catch (IOException ex) { + Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); + } + } + } + +} diff --git a/java/samples/properties/swing1/Person.java b/java/samples/properties/swing1/Person.java new file mode 100644 index 0000000..24fb5e3 --- /dev/null +++ b/java/samples/properties/swing1/Person.java @@ -0,0 +1,74 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package propertiesswing; + +import java.io.Serializable; +import java.util.Objects; + +/** + * + * @author denis + */ +public class Person implements Serializable{ + + + + private String username; + private String password; + + public Person(String username, String password) { + this.username = username; + this.password = password; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + @Override + public String toString() { + return "Person{" + "username=" + username + ", password=" + password + '}'; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 67 * hash + Objects.hashCode(this.username); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Person other = (Person) obj; + if (!Objects.equals(this.username, other.username) && hashCode()!=Objects.hashCode(obj)) { + return false; + } + return true; + } + + +} diff --git a/java/samples/properties/swing1/PersonStore.java b/java/samples/properties/swing1/PersonStore.java new file mode 100644 index 0000000..5ad3cca --- /dev/null +++ b/java/samples/properties/swing1/PersonStore.java @@ -0,0 +1,76 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package propertiesswing; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author denis + */ +public final class PersonStore { + private static Set persons = new HashSet<>(); + private static PersonStore personStore; + private File file; + + private PersonStore(){ + file = new File("persons.txt"); + if(!file.exists()) try { + file.createNewFile(); + } catch (IOException ex) { + Logger.getLogger(PropertiesSwing.class.getName()).log(Level.SEVERE, null, ex); + } + readStore(); + } + + public static PersonStore getPersonStore(){ + if (personStore == null) personStore = new PersonStore(); + return personStore; + } + + public void addPerson(Person person){ + persons.add(person); + saveStore(); + } + + public HashSet getPersons(){ + return new HashSet<>(persons); + } + + private void readStore(){ + if(file==null || !file.canRead()) return; + try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))) { + Object result = ois.readObject(); + persons = result!=null ? (HashSet)result : new HashSet<>(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + private void saveStore(){ + if(file==null || !file.canRead()) return; + try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file))) { + oos.writeObject(persons); + } catch (FileNotFoundException ex) { + Logger.getLogger(PropertiesSwing.class.getName()).log(Level.SEVERE, null, ex); + } catch (IOException ex) { + Logger.getLogger(PropertiesSwing.class.getName()).log(Level.SEVERE, null, ex); + } + } +} diff --git a/java/samples/properties/swing1/PropertiesSwing.java b/java/samples/properties/swing1/PropertiesSwing.java new file mode 100644 index 0000000..19f2411 --- /dev/null +++ b/java/samples/properties/swing1/PropertiesSwing.java @@ -0,0 +1,31 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package propertiesswing; + +/** + * + * @author denis + */ +public class PropertiesSwing { + + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + +// PersonStore personStore = PersonStore.getPersonStore(); +// personStore.addPerson(new Person("Andrey", "Andrey")); + javax.swing.SwingUtilities.invokeLater(new Runnable() { + public void run() { + new AuthorizationFrame(); + } + }); + //new AuthorizationFrame(); + } + + +} diff --git a/java/samples/properties/swing2/AuthenticationFrame.java b/java/samples/properties/swing2/AuthenticationFrame.java new file mode 100644 index 0000000..14daae8 --- /dev/null +++ b/java/samples/properties/swing2/AuthenticationFrame.java @@ -0,0 +1,104 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package propertiesswing2; + +import java.awt.Container; +import java.awt.FlowLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.HeadlessException; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JPanel; +import javax.swing.JPasswordField; +import javax.swing.JTextField; + +/** + * + * @author denis + */ +public class AuthenticationFrame extends JFrame{ + + public AuthenticationFrame() { + + setTitle("Authentication"); + setDefaultCloseOperation(DISPOSE_ON_CLOSE); + init(); + setSize(500, 200); + setResizable(false); + setLocationRelativeTo(null); + //pack(); + setVisible(true); + } + + private void init() { + JMenuBar bar = new JMenuBar(); + setJMenuBar(bar); + JMenu menu = new JMenu("File"); + bar.add(menu); + JMenuItem openItem = new JMenuItem("Open"); + JMenuItem closeItem = new JMenuItem("Close"); + menu.add(openItem); + menu.add(closeItem); + closeItem.addActionListener(e -> { + System.exit(0); + }); + + + + GridBagLayout gbl = new GridBagLayout(); + GridBagConstraints constraints = new GridBagConstraints(); + Container container = getContentPane(); + container.setLayout(gbl); + + + constraints.gridx = 1; + constraints.gridy = 0; + JLabel authLabel = new JLabel("Authorization"); + container.add(authLabel, constraints); + + JLabel usernameLanbel = new JLabel("username"); + JTextField usernameText = new JTextField(30); + constraints.gridx = 0; + constraints.gridy = 1; + container.add(usernameLanbel, constraints); + constraints.gridx = 1; + constraints.gridy = 1; + container.add(usernameText, constraints); + + JLabel passwordLanbel = new JLabel("password"); + JPasswordField passwordText = new JPasswordField(30); + constraints.gridx = 0; + constraints.gridy = 2; + container.add(passwordLanbel, constraints); + constraints.gridx = 1; + constraints.gridy = 2; + container.add(passwordText, constraints); + + JButton singIn = new JButton("SingIn"); + JButton cancel = new JButton("Cancel"); + JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 30, 5)); + constraints.gridx = 1; + constraints.gridy = 3; + container.add(panel, constraints); + panel.add(singIn); + panel.add(cancel); + + singIn.addActionListener(e -> { + UserCheck check = new UserCheck(); + if(check.check(usernameText.getText(), passwordText.getText())) System.out.println("Авторизация успешна"); + else System.out.println("Имя пользователя или пароль не верны"); + }); + + cancel.addActionListener(e -> { + System.exit(0); + }); + } +} diff --git a/java/samples/properties/swing2/MainFrame.java b/java/samples/properties/swing2/MainFrame.java new file mode 100644 index 0000000..97a7e1f --- /dev/null +++ b/java/samples/properties/swing2/MainFrame.java @@ -0,0 +1,162 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package propertiesswing2; + +import java.awt.*; +import java.awt.event.ActionListener; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Properties; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; + +/** + * + * @author denis + */ +public class MainFrame extends JFrame{ + private Properties property; + private File file; + private JTextField urlField; + private JTextField usernameField; + private JTextField passwordField; + + public MainFrame(){ + setTitle("Properties"); + Container root = getContentPane(); + root.setLayout(new BorderLayout(20, 20)); + + //Добавляем группу кнопок + root.add(createButtons(), BorderLayout.NORTH); + //Добавляем группу меток и текстовых полей + root.add(createDataArea()); + + + setSize(800, 300); + setDefaultCloseOperation(DISPOSE_ON_CLOSE); + setLocationRelativeTo(null); + setResizable(false); + setVisible(true); + } + + private JPanel createButtons(){ + JPanel panel = new JPanel(new FlowLayout()); + JButton loadButton = new JButton("LOAD"); + JButton saveButton = new JButton("SAVE"); + panel.add(loadButton); + panel.add(saveButton); + + loadButton.addActionListener(e -> { + loadProperties(); + if(property!=null){ + if (urlField!=null) urlField.setText(property.getProperty("URL", "")); + if (usernameField!=null) usernameField.setText(property.getProperty("username", "")); + if (passwordField!=null) passwordField.setText(property.getProperty("password", "")); + } + }); + + saveButton.addActionListener(e -> { + String url = urlField!=null ? urlField.getText() : ""; + String username = usernameField!=null ? usernameField.getText() : ""; + String password = passwordField!=null ? passwordField.getText() : ""; + if(property!=null){ + property.put("URL", url); + property.put("username", username); + property.put("password", password); + } + saveProperties(); + }); + + return panel; + } + + private JPanel createDataArea(){ + JPanel panel = new JPanel(new GridBagLayout()); + GridBagConstraints constraints = new GridBagConstraints(); + + JLabel urlLabel = new JLabel("URL:"); + urlField = new JTextField(50); + + constraints.gridx = 0; + constraints.gridy = 0; + panel.add(urlLabel, constraints); + + constraints.gridx = 1; + constraints.gridy = 0; + panel.add(urlField, constraints); + + JLabel usernameLabel = new JLabel("username:"); + usernameField = new JTextField(50); + + constraints.gridx = 0; + constraints.gridy = 1; + panel.add(usernameLabel, constraints); + + constraints.gridx = 1; + constraints.gridy = 1; + panel.add(usernameField, constraints); + + JLabel passwordLabel = new JLabel("password:"); + passwordField = new JTextField(50); + + constraints.gridx = 0; + constraints.gridy = 2; + panel.add(passwordLabel, constraints); + + constraints.gridx = 1; + constraints.gridy = 2; + panel.add(passwordField, constraints); + + return panel; + } + + private void loadProperties(){ + property = new Properties(); + if(file==null) file = new File("C:\\PropDir\\prop2.properties"); + //Проверяем существование файла + if(!file.exists()) { + try { + file.createNewFile(); + } catch (IOException ex) { + Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); + } + } else { + if(file.canRead()){ + try (FileReader reader = new FileReader(file)) { + property.load(reader); + } catch (FileNotFoundException ex) { + Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); + } catch (IOException ex) { + Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); + } + } + } + } + + private void saveProperties(){ + if(file==null) file = new File("C:\\PropDir\\prop2.properties"); + if(!file.exists()) try { + file.createNewFile(); + } catch (IOException ex) { + Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); + } + if(file.canWrite()){ + try (FileWriter writer = new FileWriter(file)) { + property.store(writer, null); + } catch (IOException ex) { + Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); + } + } + } +} diff --git a/java/samples/properties/swing2/PersonStore.java b/java/samples/properties/swing2/PersonStore.java new file mode 100644 index 0000000..60c9054 --- /dev/null +++ b/java/samples/properties/swing2/PersonStore.java @@ -0,0 +1,72 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package propertiesswing2; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.HashSet; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author denis + */ +public class PersonStore { + private static Set persons = new HashSet<>(); + private static PersonStore personStore; + private File file; + + private PersonStore(){ + file = new File("persons.txt"); + if(!file.exists()) try { + file.createNewFile(); + } catch (IOException ex) { + ex.printStackTrace(); + }else readStore(); + } + + public static PersonStore getPersonStore(){ + if (personStore == null) personStore = new PersonStore(); + return personStore; + } + + public void addUser(User user){ + persons.add(user); + saveStore(); + } + + public HashSet getPersons(){ + return new HashSet<>(persons); + } + + private void readStore(){ + if(file==null || !file.canRead()) return; + try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))) { + Object result = ois.readObject(); + persons = result!=null ? (HashSet)result : new HashSet<>(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + private void saveStore(){ + if(file==null || !file.canRead()) return; + try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file))) { + oos.writeObject(persons); + } catch (FileNotFoundException ex) { + ex.printStackTrace(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } +} diff --git a/java/samples/properties/swing2/PropertiesSwing2.java b/java/samples/properties/swing2/PropertiesSwing2.java new file mode 100644 index 0000000..e84c61f --- /dev/null +++ b/java/samples/properties/swing2/PropertiesSwing2.java @@ -0,0 +1,25 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package propertiesswing2; + +/** + * + * @author denis + */ +public class PropertiesSwing2 { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + PersonStore store = PersonStore.getPersonStore(); + store.getPersons().forEach(System.out::println); + //new MainFrame(); + + new AuthenticationFrame(); + } + +} diff --git a/java/samples/properties/swing2/User.java b/java/samples/properties/swing2/User.java new file mode 100644 index 0000000..afdc345 --- /dev/null +++ b/java/samples/properties/swing2/User.java @@ -0,0 +1,67 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package propertiesswing2; + +import java.io.Serializable; +import java.util.Objects; + +/** + * + * @author denis + */ +public class User implements Serializable{ + private String username; + private String password; + + public User(String username, String password) { + this.username = username; + this.password = password; + } + + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 53 * hash + Objects.hashCode(this.username); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final User other = (User) obj; + if (!Objects.equals(this.username, other.username)) { + return false; + } + if (!Objects.equals(this.hashCode(), other.hashCode()) ) { + return false; + } + return true; + } + + @Override + public String toString() { + return "User{" + "username=" + username + ", password=" + password + '}'; + } + + + +} diff --git a/java/samples/properties/swing2/UserCheck.java b/java/samples/properties/swing2/UserCheck.java new file mode 100644 index 0000000..4b57841 --- /dev/null +++ b/java/samples/properties/swing2/UserCheck.java @@ -0,0 +1,21 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package propertiesswing2; + +/** + * + * @author denis + */ +public class UserCheck { + + public boolean check(String username, String password){ + if(username==null || username.isEmpty() || password == null || password.isEmpty()) return false; + for (User user : PersonStore.getPersonStore().getPersons()){ + if(user.getUsername().equals(username) && user.getPassword().equals(password)) return true; + } + return false; + } +} diff --git a/java/samples/swing/dev_j2022_2/Dev_j2022_2.java b/java/samples/swing/dev_j2022_2/Dev_j2022_2.java new file mode 100644 index 0000000..a26e813 --- /dev/null +++ b/java/samples/swing/dev_j2022_2/Dev_j2022_2.java @@ -0,0 +1,34 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package dev_j2022_2; + +/** + * + * @author denis + */ +public class Dev_j2022_2 { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + Device[] devices = new Device[5]; + String line = " Hello"; + devices[0]=new ElectronicDevice(); + devices[1]=new MechanicalDevice(); + devices[2]=new ElectronicDevice(); + devices[3]=new MechanicalDevice(); + devices[4]=new Device(); + + for(int i=0 ; i0) this.length = length; + else throw new IllegalArgumentException("Значение length должно быть больше 0"); + } + + public int getWidth() { + return width; + } + + public void setWidth(int width) { + this.width = width; + } + + public int getHeight() { + return height; + } + + public void setHeight(int height) { + this.height = height; + } + + public void print(){ + System.out.println("Device: demention=" + length + "/" + width + "/" + height); + } + + public void printAll(Device[] devices){ + for(int i=0 ; i