Skip to content
This repository was archived by the owner on Dec 28, 2024. It is now read-only.

Commit e3a06fd

Browse files
committed
Практические №15-20
1 parent 3405201 commit e3a06fd

File tree

28 files changed

+921
-0
lines changed

28 files changed

+921
-0
lines changed

students/23K0112/23K0112-p15/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<artifactId>23K0112</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0112-p15</artifactId>
12+
<description>Классы</description>
13+
</project>
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
package ru.mirea.practice.s28k0112;
2+
3+
import java.awt.FlowLayout;
4+
import java.awt.Font;
5+
import java.awt.event.ActionListener;
6+
import java.awt.event.ActionEvent;
7+
import javax.swing.JFrame;
8+
import javax.swing.JTextField;
9+
import javax.swing.JButton;
10+
import javax.swing.JLabel;
11+
import javax.swing.JOptionPane;
12+
13+
class Calculator extends JFrame {
14+
JTextField jta1 = new JTextField(10);
15+
JTextField jta2 = new JTextField(10);
16+
JButton buttonAdd = new JButton("Add them up");
17+
JButton buttonSub = new JButton("Subtract");
18+
JButton buttonDiv = new JButton("Division");
19+
JButton buttonMul = new JButton("Multiply");
20+
21+
Font fnt = new Font("Times New Roman", Font.BOLD, 20);
22+
23+
// Конструктор класса Calculator
24+
Calculator() {
25+
setLayout(new FlowLayout());
26+
setSize(250, 150);
27+
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Закрытие приложения при нажатии на кнопку закрытия
28+
29+
// Создаем надпись 1
30+
add(new JLabel("1st Number"));
31+
// Добавляем текстовое поле jta1
32+
add(jta1);
33+
// Создаем надпись 2
34+
add(new JLabel("2nd Number"));
35+
// Добавляем текстовое поле jta2
36+
add(jta2);
37+
// Добавляем кнопку
38+
add(buttonAdd);
39+
add(buttonSub);
40+
add(buttonDiv);
41+
add(buttonMul);
42+
43+
44+
// Добавляем слушателя к кнопке buttonAdd
45+
buttonAdd.addActionListener(new ActionListener() {
46+
public void actionPerformed(ActionEvent ae) {
47+
try {
48+
// Переменная для хранения ввода в текстовое поле 1
49+
double x1 = Double.parseDouble(jta1.getText().trim());
50+
// Переменная для хранения ввода в текстовое поле 2
51+
double x2 = Double.parseDouble(jta2.getText().trim());
52+
// Создаем всплывающее окно INFORMATION_MESSAGE
53+
JOptionPane.showMessageDialog(null, "Result = " + (x1 + x2), "Alert", JOptionPane.INFORMATION_MESSAGE);
54+
} catch (Exception e) {
55+
// Создаем всплывающее окно ERROR_MESSAGE
56+
JOptionPane.showMessageDialog(null, "Error in Numbers!", "Alert", JOptionPane.ERROR_MESSAGE);
57+
}
58+
}
59+
}); // Конец buttonAdd.addActionListener()
60+
61+
buttonSub.addActionListener(new ActionListener() {
62+
public void actionPerformed(ActionEvent ae) {
63+
try {
64+
// Переменная для хранения ввода в текстовое поле 1
65+
double x1 = Double.parseDouble(jta1.getText().trim());
66+
// Переменная для хранения ввода в текстовое поле 2
67+
double x2 = Double.parseDouble(jta2.getText().trim());
68+
// Создаем всплывающее окно INFORMATION_MESSAGE
69+
JOptionPane.showMessageDialog(null, "Result = " + (x1 - x2), "Alert", JOptionPane.INFORMATION_MESSAGE);
70+
} catch (Exception e) {
71+
// Создаем всплывающее окно ERROR_MESSAGE
72+
JOptionPane.showMessageDialog(null, "Error in Numbers!", "Alert", JOptionPane.ERROR_MESSAGE);
73+
}
74+
}
75+
});
76+
77+
setVisible(true); // Делаем окно видимым
78+
79+
buttonDiv.addActionListener(new ActionListener() {
80+
public void actionPerformed(ActionEvent ae) {
81+
try {
82+
// Переменная для хранения ввода в текстовое поле 1
83+
double x1 = Double.parseDouble(jta1.getText().trim());
84+
// Переменная для хранения ввода в текстовое поле 2
85+
double x2 = Double.parseDouble(jta2.getText().trim());
86+
// Создаем всплывающее окно INFORMATION_MESSAGE
87+
JOptionPane.showMessageDialog(null, "Result = " + (x1 / x2), "Alert", JOptionPane.INFORMATION_MESSAGE);
88+
} catch (Exception e) {
89+
// Создаем всплывающее окно ERROR_MESSAGE
90+
JOptionPane.showMessageDialog(null, "Error in Numbers!", "Alert", JOptionPane.ERROR_MESSAGE);
91+
}
92+
}
93+
});
94+
95+
buttonMul.addActionListener(new ActionListener() {
96+
public void actionPerformed(ActionEvent ae) {
97+
try {
98+
// Переменная для хранения ввода в текстовое поле 1
99+
double x1 = Double.parseDouble(jta1.getText().trim());
100+
// Переменная для хранения ввода в текстовое поле 2
101+
double x2 = Double.parseDouble(jta2.getText().trim());
102+
// Создаем всплывающее окно INFORMATION_MESSAGE
103+
JOptionPane.showMessageDialog(null, "Result = " + (x1 * x2), "Alert", JOptionPane.INFORMATION_MESSAGE);
104+
} catch (Exception e) {
105+
// Создаем всплывающее окно ERROR_MESSAGE
106+
JOptionPane.showMessageDialog(null, "Error in Numbers!", "Alert", JOptionPane.ERROR_MESSAGE);
107+
}
108+
}
109+
});
110+
111+
setVisible(true); // Делаем окно видимым
112+
}
113+
114+
public static void main(String[] args) {
115+
new Calculator(); // Создаем экземпляр калькулятора
116+
} // Конец main()
117+
} // Конец класса Calculator
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package ru.mirea.practice.s28k0112;
2+
3+
import javax.swing.JFrame;
4+
import javax.swing.JComboBox;
5+
import javax.swing.JTextArea;
6+
import javax.swing.SwingUtilities;
7+
import javax.swing.JScrollPane;
8+
import java.awt.FlowLayout;
9+
import java.awt.event.ActionEvent;
10+
import java.awt.event.ActionListener;
11+
12+
public class CountrySelector extends JFrame {
13+
private JComboBox<String> countryComboBox;
14+
private JTextArea infoArea;
15+
16+
public CountrySelector() {
17+
setTitle("Выбор страны");
18+
setSize(400, 300);
19+
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
20+
setLayout(new FlowLayout());
21+
22+
String[] countries = {"США", "Канада", "Германия", "Франция", "Италия"};
23+
countryComboBox = new JComboBox<>(countries);
24+
25+
infoArea = new JTextArea(10, 30);
26+
infoArea.setEditable(false);
27+
28+
countryComboBox.addActionListener(new ActionListener() {
29+
@Override
30+
public void actionPerformed(ActionEvent e) {
31+
String selectedCountry = (String) countryComboBox.getSelectedItem();
32+
showCountryInfo(selectedCountry);
33+
}
34+
});
35+
36+
add(countryComboBox);
37+
add(new JScrollPane(infoArea));
38+
}
39+
40+
private void showCountryInfo(String country) {
41+
String info;
42+
switch (country) {
43+
case "США":
44+
info = "Соединенные Штаты Америки (США) — это страна, расположенная в основном в Северной Америке.";
45+
break;
46+
case "Канада":
47+
info = "Канада — это страна в Северной Америке, простирающаяся от Атлантического океана до Тихого и на север в Арктический океан.";
48+
break;
49+
case "Германия":
50+
info = "Германия — это страна в Центральной Европе, известная своей богатой историей и культурным наследием.";
51+
break;
52+
case "Франция":
53+
info = "Франция — это страна в Западной Европе, известная своим искусством, модой и кухней.";
54+
break;
55+
case "Италия":
56+
info = "Италия — это европейская страна, известная своими историческими памятниками, искусством и вкусной кухней.";
57+
break;
58+
default:
59+
info = "Информация недоступна.";
60+
break;
61+
}
62+
infoArea.setText(info);
63+
}
64+
65+
public static void main(String[] args) {
66+
SwingUtilities.invokeLater(() -> {
67+
CountrySelector selector = new CountrySelector();
68+
selector.setVisible(true);
69+
});
70+
}
71+
}

students/23K0112/23K0112-p16/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<artifactId>23K0112</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0112-p16</artifactId>
12+
<description>Обработка событий мыши и клавиатуры программах на Джава</description>
13+
</project>
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package ru.mirea.practice.s28k0112;
2+
3+
import javax.swing.JFrame;
4+
import javax.swing.JTextArea;
5+
import javax.swing.JComboBox;
6+
import javax.swing.JLabel;
7+
import javax.swing.JScrollPane;
8+
import javax.swing.JPanel;
9+
import javax.swing.SwingUtilities;
10+
import java.awt.BorderLayout;
11+
import java.awt.FlowLayout;
12+
import java.awt.Color;
13+
import java.awt.event.ActionEvent;
14+
import java.awt.event.ActionListener;
15+
import java.awt.Font;
16+
17+
public class TextEditor extends JFrame {
18+
private JTextArea textArea;
19+
private JComboBox<String> colorComboBox;
20+
private JComboBox<String> fontComboBox;
21+
22+
public TextEditor() {
23+
setTitle("Text Editor");
24+
setSize(400, 300);
25+
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
26+
setLayout(new BorderLayout());
27+
28+
textArea = new JTextArea();
29+
textArea.setLineWrap(true);
30+
textArea.setWrapStyleWord(true);
31+
add(new JScrollPane(textArea), BorderLayout.CENTER);
32+
33+
JPanel panel = new JPanel();
34+
panel.setLayout(new FlowLayout());
35+
36+
// Создание JComboBox для выбора цвета
37+
colorComboBox = new JComboBox<>();
38+
colorComboBox.addItem("Синий");
39+
colorComboBox.addItem("Красный");
40+
colorComboBox.addItem("Черный");
41+
42+
colorComboBox.addActionListener(new ActionListener() {
43+
@Override
44+
public void actionPerformed(ActionEvent e) {
45+
changeTextColor((String) colorComboBox.getSelectedItem());
46+
}
47+
});
48+
49+
// Создание JComboBox для выбора шрифта
50+
fontComboBox = new JComboBox<>();
51+
fontComboBox.addItem("Times New Roman");
52+
fontComboBox.addItem("MS Sans Serif");
53+
fontComboBox.addItem("Courier New");
54+
55+
fontComboBox.addActionListener(new ActionListener() {
56+
@Override
57+
public void actionPerformed(ActionEvent e) {
58+
changeFont((String) fontComboBox.getSelectedItem());
59+
}
60+
});
61+
62+
panel.add(new JLabel("Цвет:"));
63+
panel.add(colorComboBox);
64+
panel.add(new JLabel("Шрифт:"));
65+
panel.add(fontComboBox);
66+
67+
add(panel, BorderLayout.NORTH);
68+
}
69+
70+
private void changeTextColor(String color) {
71+
switch (color) {
72+
case "Синий":
73+
textArea.setForeground(Color.BLUE);
74+
break;
75+
case "Красный":
76+
textArea.setForeground(Color.RED);
77+
break;
78+
case "Черный":
79+
textArea.setForeground(Color.BLACK);
80+
break;
81+
default:
82+
break;
83+
}
84+
}
85+
86+
private void changeFont(String font) {
87+
switch (font) {
88+
case "Times New Roman":
89+
textArea.setFont(new Font("Times New Roman", Font.PLAIN, 12));
90+
break;
91+
case "MS Sans Serif":
92+
textArea.setFont(new Font("MS Sans Serif", Font.PLAIN, 12));
93+
break;
94+
case "Courier New":
95+
textArea.setFont(new Font("Courier New", Font.PLAIN, 12));
96+
break;
97+
default:
98+
break;
99+
}
100+
}
101+
102+
public static void main(String[] args) {
103+
SwingUtilities.invokeLater(() -> {
104+
TextEditor editor = new TextEditor();
105+
editor.setVisible(true);
106+
});
107+
}
108+
}

students/23K0112/23K0112-p17/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<artifactId>23K0112</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0112-p17</artifactId>
12+
<description>Исключения и работа с ними</description>
13+
</project>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package ru.mirea.practice.s28k0112;
2+
3+
// Задание с СДО. Варинат №6
4+
5+
public class DoublyLinkedList {
6+
private Node head;
7+
8+
public DoublyLinkedList() {
9+
this.head = null;
10+
}
11+
12+
public void add(String data) {
13+
Node newNode = new Node(data);
14+
15+
if (head == null) { // Если список пуст
16+
head = newNode;
17+
newNode.next = newNode;
18+
newNode.prev = newNode;
19+
} else {
20+
Node current = head;
21+
22+
do {
23+
if (data.length() < current.data.length()
24+
|| data.length() == current.data.length() && data.compareTo(current.data) < 0) {
25+
break;
26+
}
27+
current = current.next;
28+
} while (current != head);
29+
30+
newNode.prev = current.prev;
31+
newNode.next = current;
32+
33+
current.prev.next = newNode;
34+
current.prev = newNode;
35+
36+
if (current == head
37+
&& (data.length() < head.data.length()
38+
|| data.length() == head.data.length() && data.compareTo(head.data) < 0)) {
39+
head = newNode;
40+
}
41+
}
42+
}
43+
44+
public void display() {
45+
if (head == null) {
46+
System.out.println("Список пуст.");
47+
return;
48+
}
49+
50+
Node current = head;
51+
do {
52+
System.out.println(current.data);
53+
current = current.next;
54+
} while (current != head);
55+
}
56+
}

0 commit comments

Comments
 (0)