diff --git a/.idea/artifacts/SwingApp_jar.xml b/.idea/artifacts/SwingApp_jar.xml
new file mode 100644
index 0000000..60bea21
--- /dev/null
+++ b/.idea/artifacts/SwingApp_jar.xml
@@ -0,0 +1,8 @@
+
+
+ $PROJECT_DIR$/out/artifacts/SwingApp_jar
+
+
+
+
+
\ No newline at end of file
diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..45f2883
--- /dev/null
+++ b/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: lesson8.examples.Example2
+
diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..45f2883
--- /dev/null
+++ b/src/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: lesson8.examples.Example2
+
diff --git a/src/lesson8/borderlayout/BorderLayout1.java b/src/lesson8/borderlayout/BorderLayout1.java
new file mode 100644
index 0000000..e2acdb4
--- /dev/null
+++ b/src/lesson8/borderlayout/BorderLayout1.java
@@ -0,0 +1,42 @@
+package lesson8.borderlayout;
+
+import javax.swing.*;
+import java.awt.*;
+
+public class BorderLayout1 {
+
+ static class MyWindow extends JFrame {
+ public MyWindow() {
+ setTitle("Test Window");
+ setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+ setSize(800, 800);
+ setLocationRelativeTo(null);
+
+ JButton button = new JButton("Button 1 (PAGE_START)");
+ add(button, BorderLayout.NORTH);
+
+ button = new JButton("Button 2 (CENTER)");
+ add(button, BorderLayout.CENTER);
+
+ button = new JButton("Button 3 (LINE_START)");
+// button.setSize(new Dimension(200, 200));
+ button.setSize(200, 200);
+// add(button, BorderLayout.LINE_START);
+ add(button, BorderLayout.WEST);
+
+ button = new JButton("Long-Named Button 4 (PAGE_END)");
+ add(button, BorderLayout.EAST);
+
+ button = new JButton("5 (LINE_END)");
+// add(button, BorderLayout.LINE_END);
+ add(button, BorderLayout.SOUTH);
+
+ setVisible(true);
+ }
+ }
+
+ public static void main(String[] args) {
+ new MyWindow();
+ }
+
+}
\ No newline at end of file
diff --git a/src/lesson8/borderlayout/BorderLayout2.java b/src/lesson8/borderlayout/BorderLayout2.java
new file mode 100644
index 0000000..795ce3c
--- /dev/null
+++ b/src/lesson8/borderlayout/BorderLayout2.java
@@ -0,0 +1,29 @@
+package lesson8.borderlayout;
+
+import javax.swing.*;
+import java.awt.*;
+
+public class BorderLayout2 {
+
+ static public class MyWindow extends JFrame {
+ public MyWindow() {
+ setBounds(500,500,500,300);
+ setTitle("BoxLayoutDemo");
+ setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+ JButton[] jbs = new JButton[10];
+// setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); // одну из строк надо закомментировать
+ setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS)); // одну из строк надо закомментировать
+ for (int i = 0; i < jbs.length; i++) {
+ jbs[i] = new JButton("#" + i);
+ jbs[i].setAlignmentY(Component.TOP_ALIGNMENT);
+ add(jbs[i]);
+ }
+ setVisible(true);
+ }
+ }
+
+ public static void main(String[] args) {
+ new MyWindow();
+ }
+
+}
\ No newline at end of file
diff --git a/src/lesson8/borderlayout/BorderLayout3.java b/src/lesson8/borderlayout/BorderLayout3.java
new file mode 100644
index 0000000..64e9252
--- /dev/null
+++ b/src/lesson8/borderlayout/BorderLayout3.java
@@ -0,0 +1,27 @@
+package lesson8.borderlayout;
+
+import javax.swing.*;
+import java.awt.*;
+
+public class BorderLayout3 {
+
+ static public class MyWindow extends JFrame {
+ public MyWindow() {
+ setBounds(500, 500, 400, 300);
+ setTitle("FlowLayoutDemo");
+ setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+ JButton[] jbs = new JButton[10];
+ setLayout(new FlowLayout());
+ for (int i = 0; i < jbs.length; i++) {
+ jbs[i] = new JButton("#" + i);
+ add(jbs[i]);
+ }
+ setVisible(true);
+ }
+ }
+
+ public static void main(String[] args) {
+ new MyWindow();
+ }
+
+}
\ No newline at end of file
diff --git a/src/lesson8/borderlayout/BorderLayout4.java b/src/lesson8/borderlayout/BorderLayout4.java
new file mode 100644
index 0000000..93db817
--- /dev/null
+++ b/src/lesson8/borderlayout/BorderLayout4.java
@@ -0,0 +1,27 @@
+package lesson8.borderlayout;
+
+import javax.swing.*;
+import java.awt.*;
+
+public class BorderLayout4 {
+
+ static public class MyWindow extends JFrame {
+ public MyWindow() {
+ setBounds(500,500,400,300);
+ setTitle("GridLayoutDemo");
+ setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+ JButton[] jbs = new JButton[10];
+ setLayout(new GridLayout(4, 3));
+ for (int i = 0; i < jbs.length; i++) {
+ jbs[i] = new JButton("#" + i);
+ add(jbs[i]);
+ }
+ setVisible(true);
+ }
+ }
+
+ public static void main(String[] args) {
+ new MyWindow();
+ }
+
+}
\ No newline at end of file
diff --git a/src/lesson8/events/KeyboardExample.java b/src/lesson8/events/KeyboardExample.java
new file mode 100644
index 0000000..1ab2932
--- /dev/null
+++ b/src/lesson8/events/KeyboardExample.java
@@ -0,0 +1,57 @@
+package lesson8.events;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+
+public class KeyboardExample {
+
+ static public class MyWindow extends JFrame {
+ public MyWindow() {
+ setBounds(500, 500, 400, 300);
+ setTitle("Demo");
+ setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+
+ JLabel text = new JLabel("");
+ add(text, BorderLayout.NORTH);
+
+ JTextField field = new JTextField();
+ add(field, BorderLayout.CENTER);
+ field.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ System.out.println("Your message: " + field.getText());
+ text.setText(((JTextField)e.getSource()).getText());
+ field.setText(null);
+ }
+ });
+
+ field.addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyTyped(KeyEvent e) {
+ if (e.isShiftDown()) {
+ System.out.println("Shift down");
+ }
+ System.out.println(e.getKeyChar() + " down");
+
+ }
+ });
+
+ JButton button = new JButton("Execute");
+ add(button, BorderLayout.SOUTH);
+ button.addActionListener(e -> {
+ text.setText(field.getText());
+ field.setText(null);
+ });
+
+ setVisible(true);
+ }
+
+ }
+
+
+ public static void main(String[] args) {
+ new MyWindow();
+ }
+
+}
\ No newline at end of file
diff --git a/src/lesson8/events/MouseEventExample.java b/src/lesson8/events/MouseEventExample.java
new file mode 100644
index 0000000..95121b9
--- /dev/null
+++ b/src/lesson8/events/MouseEventExample.java
@@ -0,0 +1,39 @@
+package lesson8.events;
+
+import javax.swing.*;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+public class MouseEventExample {
+
+ static public class MyWindow extends JFrame {
+ public MyWindow() {
+ setBounds(500, 500, 400, 300);
+ setTitle("Demo");
+ setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+ JPanel pan = new JPanel();
+ add(pan);
+ pan.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseReleased(MouseEvent e) {
+ System.out.println("MousePos: " + e.getX() + " " + e.getY());
+ }
+
+ @Override
+ public void mouseExited(MouseEvent e) {
+ System.out.println("Exited!");
+ }
+ });
+
+
+
+ setVisible(true);
+ }
+ }
+
+
+ public static void main(String[] args) {
+ new MyWindow();
+ }
+
+}
\ No newline at end of file
diff --git a/src/lesson8/examples/Example1.java b/src/lesson8/examples/Example1.java
new file mode 100644
index 0000000..7a8d13a
--- /dev/null
+++ b/src/lesson8/examples/Example1.java
@@ -0,0 +1,36 @@
+package lesson8.examples;
+
+import javax.swing.*;
+import java.awt.*;
+
+public class Example1 {
+
+ static class MyWindow extends JFrame {
+ public MyWindow() {
+ setTitle("Test Window");
+ setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+// setLocationRelativeTo(null);
+ setSize(400, 400);
+ setLocation(300, 300);
+// setBounds(2400, 300, 400, 400);
+ setVisible(true);
+ }
+ }
+
+ private static class WindowRunnable implements /* extends */ Runnable {
+
+ @Override
+ public void run() {
+ new MyWindow();
+ }
+ }
+
+ public static void main(String[] args) {
+ new MyWindow();
+// EventQueue.invokeLater(new WindowRunnable());
+// EventQueue.invokeLater(MyWindow::new);
+
+ }
+
+
+}
diff --git a/src/lesson8/examples/Example2.java b/src/lesson8/examples/Example2.java
new file mode 100644
index 0000000..d714109
--- /dev/null
+++ b/src/lesson8/examples/Example2.java
@@ -0,0 +1,40 @@
+package lesson8.examples;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+public class Example2 {
+
+ static class MyWindow extends JFrame {
+ public MyWindow() {
+ setTitle("Test Window");
+ setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+ setBounds(300, 300, 400, 400);
+
+ JButton[] jbs = new JButton[5];
+ for (int i = 0; i < 5; i++) {
+ jbs[i] = new JButton("#" + i);
+ jbs[i].addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ System.out.println(((JButton)e.getSource()).getText() + " was pressed");
+ }
+ });
+ }
+ setLayout(new BorderLayout()); // выбор компоновщика элементов
+ add(jbs[0], BorderLayout.EAST); // добавление кнопки на форму
+ add(jbs[1], BorderLayout.WEST);
+ add(jbs[2], BorderLayout.SOUTH);
+ add(jbs[3], BorderLayout.NORTH);
+ add(jbs[4], BorderLayout.CENTER);
+ setVisible(true);
+ }
+ }
+
+ public static void main(String[] args) {
+ new MyWindow();
+ }
+
+}
diff --git a/src/lesson8/graphics/ButtonDrawExample.java b/src/lesson8/graphics/ButtonDrawExample.java
new file mode 100644
index 0000000..ed5ef21
--- /dev/null
+++ b/src/lesson8/graphics/ButtonDrawExample.java
@@ -0,0 +1,69 @@
+package lesson8.graphics;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+public class ButtonDrawExample {
+ static class MyWindow extends JFrame {
+
+ private static final String DRAW_X = "DRAW_X";
+ private static final String DRAW_O = "DRAW_O";
+
+ public MyWindow() {
+ setSize(800,300);
+ setDefaultCloseOperation(EXIT_ON_CLOSE);
+ setLocationRelativeTo(null);
+
+ setLayout(new GridLayout(1, 3));
+ add(createButton());
+ add(createButton());
+ add(createButton());
+
+ setVisible(true);
+ }
+
+ private JButton createButton() {
+ return new JButton() {
+
+ {
+ setActionCommand(DRAW_O);
+ addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ String action = getActionCommand().equals(DRAW_O) ? DRAW_X : DRAW_O;
+ setActionCommand(action);
+ }
+ });
+ }
+
+ @Override
+ public void paint(Graphics graphics) {
+ super.paint(graphics);
+
+ if (getActionCommand().equals(DRAW_O)) {
+ graphics.drawOval(0, this.getHeight() / 4, getWidth(), getWidth());
+ graphics.setColor(Color.RED);
+ graphics.fillOval(0, this.getHeight() / 4, getWidth(), getWidth());
+ }
+ else {
+ Graphics2D g2d = (Graphics2D) graphics;
+ g2d.setStroke(new BasicStroke(10));
+ g2d.setColor(Color.BLUE);
+ g2d.drawLine(0, 0, this.getWidth(), this.getHeight());
+ g2d.drawLine(this.getWidth(), 0, 0, this.getHeight());
+ }
+ }
+ };
+
+ }
+
+ }
+
+
+ public static void main(String[] args){
+ new MyWindow();
+ }
+
+}
diff --git a/src/lesson8/graphics/DrawingExample.java b/src/lesson8/graphics/DrawingExample.java
new file mode 100644
index 0000000..6b4f9e0
--- /dev/null
+++ b/src/lesson8/graphics/DrawingExample.java
@@ -0,0 +1,50 @@
+package lesson8.graphics;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+public class DrawingExample extends JFrame {
+
+ public DrawingExample() {
+ super("Lines Drawing Demo");
+
+ setSize(680, 600);
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ setLocationRelativeTo(null);
+ setAlwaysOnTop(true);
+ addMouseListener(new MouseAdapter() {
+ @Override
+ public void mousePressed(MouseEvent e) {
+ System.out.println("MousePos: " + e.getX() + " " + e.getY());
+ }});
+ }
+
+ @Override
+ public void paint(Graphics g) {
+ super.paint(g);
+ simpleDrawLines(g);
+ }
+
+ private void simpleDrawLines(Graphics g2d) {
+ g2d.drawLine(120, 50, 360, 50);
+ g2d.setColor(Color.RED);
+ g2d.drawRect(150, 150, 150, 150);
+
+ g2d.setColor(Color.GREEN);
+// g2d.fillPolygon(new int[] {400}, new int[] {400}, 10);
+ g2d.fillRect(151, 151, 149, 75);
+
+// g2d.drawLine(350, 50, 350, 550);
+// g2d.drawLine(250, 150, 550, 150);
+ g2d.drawOval(350, 150, 150, 150);
+ g2d.setColor(Color.RED);
+ g2d.fillOval(351, 151, 149, 149);
+// g2d.clearRect(350, 150, 75, 75);
+ }
+
+ public static void main(String[] args) {
+ new DrawingExample().setVisible(true);
+ }
+}
\ No newline at end of file