diff --git a/robots/.idea/.gitignore b/robots/.idea/.gitignore new file mode 100644 index 000000000..26d33521a --- /dev/null +++ b/robots/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/robots/.idea/codeStyles/Project.xml b/robots/.idea/codeStyles/Project.xml new file mode 100644 index 000000000..919ce1f1f --- /dev/null +++ b/robots/.idea/codeStyles/Project.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/robots/.idea/codeStyles/codeStyleConfig.xml b/robots/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 000000000..a55e7a179 --- /dev/null +++ b/robots/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/robots/.idea/encodings.xml b/robots/.idea/encodings.xml new file mode 100644 index 000000000..c09273c51 --- /dev/null +++ b/robots/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/robots/.idea/google-java-format.xml b/robots/.idea/google-java-format.xml new file mode 100644 index 000000000..2aa056da3 --- /dev/null +++ b/robots/.idea/google-java-format.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/robots/.idea/misc.xml b/robots/.idea/misc.xml new file mode 100644 index 000000000..0a9fe95b2 --- /dev/null +++ b/robots/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/robots/.idea/modules.xml b/robots/.idea/modules.xml new file mode 100644 index 000000000..f913d90b3 --- /dev/null +++ b/robots/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/robots/.idea/vcs.xml b/robots/.idea/vcs.xml new file mode 100644 index 000000000..6c0b86358 --- /dev/null +++ b/robots/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/robots/Robots.iml b/robots/Robots.iml new file mode 100644 index 000000000..a569b4ae7 --- /dev/null +++ b/robots/Robots.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/robots/resources/text.properties b/robots/resources/text.properties new file mode 100644 index 000000000..7752a6cae --- /dev/null +++ b/robots/resources/text.properties @@ -0,0 +1 @@ +topic = Style \ No newline at end of file diff --git a/robots/resources/text_ru_RU.properties b/robots/resources/text_ru_RU.properties new file mode 100644 index 000000000..cbbdcd86d --- /dev/null +++ b/robots/resources/text_ru_RU.properties @@ -0,0 +1 @@ +topic = Как это Звать? \ No newline at end of file diff --git a/robots/src/gui/GameDataModel.java b/robots/src/gui/GameDataModel.java new file mode 100644 index 000000000..7f81e0952 --- /dev/null +++ b/robots/src/gui/GameDataModel.java @@ -0,0 +1,151 @@ +package gui; + +import java.awt.*; +import java.util.Observable; + +public class GameDataModel extends Observable { + double angularVelocity = 0; + int counter = 0; + private volatile double m_robotPositionX = 100; + public static String KEY_COORDINATE_ROBOT = "robot changed"; + public static String KEY_COORDINATE_TARGET = "target changed"; + private volatile double m_robotPositionY = 100; + private volatile double m_robotDirection = 0; + + private volatile int m_targetPositionX = 250; + private volatile int m_targetPositionY = 100; + + private static final double maxVelocity = 0.1; + private static final double maxAngularVelocity = 0.001; + + public double getM_robotPositionX() { + return m_robotPositionX; + } + + public double getM_robotPositionY() { + return m_robotPositionY; + } + + public double getM_robotDirection() { + return m_robotDirection; + } + + public int getM_targetPositionX() { + return m_targetPositionX; + } + + public int getM_targetPositionY() { + return m_targetPositionY; + } + + + protected void setTargetPosition(Point p) { + m_targetPositionX = p.x; + m_targetPositionY = p.y; + setChanged(); + notifyObservers(KEY_COORDINATE_TARGET); + clearChanged(); + } + + + private static double distance(double x1, double y1, double x2, double y2) { + double diffX = x1 - x2; + double diffY = y1 - y2; + return Math.sqrt(diffX * diffX + diffY * diffY); + } + + private static double angleTo(double fromX, double fromY, double toX, double toY) { + double diffX = toX - fromX; + double diffY = toY - fromY; + return asNormalizedRadians(Math.atan2(diffY, diffX)); + } + + protected void onModelUpdateEvent() { + + double distance = distance(m_targetPositionX, m_targetPositionY, + m_robotPositionX, m_robotPositionY); + if (distance < 0.5) { + counter = 0; + return; + } + double velocity = maxVelocity; + double angleToTarget = angleTo(m_robotPositionX, m_robotPositionY, m_targetPositionX, m_targetPositionY); + + +// System.out.println(); + System.out.println(counter); + if (distance>=angularVelocity*maxVelocity&&angleToTarget!=m_robotDirection) { + if (counter<2) { + if (angleToTarget > m_robotDirection && angularVelocity != maxAngularVelocity) { + counter++; + angularVelocity = maxAngularVelocity; + } + if (angleToTarget < m_robotDirection && angularVelocity != -maxAngularVelocity) { + counter++; + angularVelocity = -maxAngularVelocity; + } + }else { + if (Math.abs(angleToTarget - m_robotDirection)<0.1) { + angularVelocity = 0; + if (angleToTarget > m_robotDirection) + angularVelocity = maxAngularVelocity; + if (angleToTarget < m_robotDirection) + angularVelocity = -maxAngularVelocity; + } + } + } + + moveRobot(velocity, angularVelocity, 10); + } + + private static double asNormalizedRadians(double angle) { + + if (angle < 0) { +// System.out.println("<"); + angle += 2 * Math.PI; + } + if (angle >= 2* Math.PI) { +// System.out.println(">"); + angle -= 2 * Math.PI; + } + return angle; + } + + private static double applyLimits(double value, double min, double max) { + if (value < min) + return min; + if (value > max) + return max; + return value; + } + + private void moveRobot(double velocity, double angularVelocity, double duration) { + velocity = applyLimits(velocity, 0, maxVelocity); + angularVelocity = applyLimits(angularVelocity, -maxAngularVelocity, maxAngularVelocity); + double newX = m_robotPositionX + velocity / angularVelocity * + (Math.sin(m_robotDirection + angularVelocity * duration) - + Math.sin(m_robotDirection)); + if (!Double.isFinite(newX)) { + newX = m_robotPositionX + velocity * duration * Math.cos(m_robotDirection); + } + double newY = m_robotPositionY - velocity / angularVelocity * + (Math.cos(m_robotDirection + angularVelocity * duration) - + Math.cos(m_robotDirection)); + if (!Double.isFinite(newY)) { + newY = m_robotPositionY + velocity * duration * Math.sin(m_robotDirection); + } + m_robotPositionX = newX; + m_robotPositionY = newY; + double newDirection = asNormalizedRadians(m_robotDirection + angularVelocity * duration ); + m_robotDirection = newDirection; + setChanged(); + notifyObservers(KEY_COORDINATE_ROBOT); + clearChanged(); + } + + + + static int round(double value) { + return (int) (value + 0.5); + } +} diff --git a/robots/src/gui/GameVisualizer.java b/robots/src/gui/GameVisualizer.java index f82cfd8f8..4f6614c1a 100644 --- a/robots/src/gui/GameVisualizer.java +++ b/robots/src/gui/GameVisualizer.java @@ -1,210 +1,138 @@ package gui; -import java.awt.Color; -import java.awt.EventQueue; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Point; +import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.geom.AffineTransform; +import java.util.Observable; +import java.util.Observer; import java.util.Timer; import java.util.TimerTask; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import javax.swing.*; -import javax.swing.JPanel; +import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE; -public class GameVisualizer extends JPanel -{ +public class GameVisualizer extends JPanel implements Observer { + private volatile double m_robotPositionX = 100; + private volatile double m_robotPositionY = 100; + private volatile double m_robotDirection = 0; + private volatile int m_targetPositionX = 250; + private volatile int m_targetPositionY = 100; + private GameDataModel d_model = new GameDataModel(); private final Timer m_timer = initTimer(); - - private static Timer initTimer() - { + + private static Timer initTimer() { Timer timer = new Timer("events generator", true); return timer; } - - private volatile double m_robotPositionX = 100; - private volatile double m_robotPositionY = 100; - private volatile double m_robotDirection = 0; - private volatile int m_targetPositionX = 150; - private volatile int m_targetPositionY = 100; - - private static final double maxVelocity = 0.1; - private static final double maxAngularVelocity = 0.001; - - public GameVisualizer() - { - m_timer.schedule(new TimerTask() - { + public static class Helpers { + public static boolean areEqual(Object o1, Object o2) { + if (o1 == null) + return o2 == null; + return o1.equals(o2); + } + } + + public GameVisualizer() { + d_model.addObserver(this); + + JInternalFrame dialog = new JInternalFrame(); + dialog.setSize(480, 200); + JLabel coordinate = new JLabel("Robot: x=" + m_robotPositionX + " y=" + m_robotPositionY); + dialog.add(coordinate); + dialog.setVisible(true); + ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); + executor.scheduleWithFixedDelay(() -> { + String now = "Robot: x=" + Math.ceil(m_robotPositionX) + " y=" + Math.ceil(m_robotPositionY); + SwingUtilities.invokeLater(() -> coordinate.setText(now)); + }, 0, 1, TimeUnit.MILLISECONDS); + this.add(dialog); + m_timer.schedule(new TimerTask() { @Override - public void run() - { + public void run() { onRedrawEvent(); } }, 0, 50); - m_timer.schedule(new TimerTask() - { + m_timer.schedule(new TimerTask() { @Override - public void run() - { - onModelUpdateEvent(); + public void run() { + d_model.onModelUpdateEvent(); } }, 0, 10); - addMouseListener(new MouseAdapter() - { + addMouseListener(new MouseAdapter() { @Override - public void mouseClicked(MouseEvent e) - { - setTargetPosition(e.getPoint()); + public void mouseClicked(MouseEvent e) { + d_model.setTargetPosition(e.getPoint()); repaint(); } }); setDoubleBuffered(true); } - protected void setTargetPosition(Point p) - { - m_targetPositionX = p.x; - m_targetPositionY = p.y; - } - - protected void onRedrawEvent() - { - EventQueue.invokeLater(this::repaint); - } - private static double distance(double x1, double y1, double x2, double y2) - { - double diffX = x1 - x2; - double diffY = y1 - y2; - return Math.sqrt(diffX * diffX + diffY * diffY); - } - - private static double angleTo(double fromX, double fromY, double toX, double toY) - { - double diffX = toX - fromX; - double diffY = toY - fromY; - - return asNormalizedRadians(Math.atan2(diffY, diffX)); - } - - protected void onModelUpdateEvent() - { - double distance = distance(m_targetPositionX, m_targetPositionY, - m_robotPositionX, m_robotPositionY); - if (distance < 0.5) - { - return; - } - double velocity = maxVelocity; - double angleToTarget = angleTo(m_robotPositionX, m_robotPositionY, m_targetPositionX, m_targetPositionY); - double angularVelocity = 0; - if (angleToTarget > m_robotDirection) - { - angularVelocity = maxAngularVelocity; - } - if (angleToTarget < m_robotDirection) - { - angularVelocity = -maxAngularVelocity; - } - - moveRobot(velocity, angularVelocity, 10); - } - - private static double applyLimits(double value, double min, double max) - { - if (value < min) - return min; - if (value > max) - return max; - return value; - } - - private void moveRobot(double velocity, double angularVelocity, double duration) - { - velocity = applyLimits(velocity, 0, maxVelocity); - angularVelocity = applyLimits(angularVelocity, -maxAngularVelocity, maxAngularVelocity); - double newX = m_robotPositionX + velocity / angularVelocity * - (Math.sin(m_robotDirection + angularVelocity * duration) - - Math.sin(m_robotDirection)); - if (!Double.isFinite(newX)) - { - newX = m_robotPositionX + velocity * duration * Math.cos(m_robotDirection); - } - double newY = m_robotPositionY - velocity / angularVelocity * - (Math.cos(m_robotDirection + angularVelocity * duration) - - Math.cos(m_robotDirection)); - if (!Double.isFinite(newY)) - { - newY = m_robotPositionY + velocity * duration * Math.sin(m_robotDirection); - } - m_robotPositionX = newX; - m_robotPositionY = newY; - double newDirection = asNormalizedRadians(m_robotDirection + angularVelocity * duration); - m_robotDirection = newDirection; + protected void onRedrawEvent() { + EventQueue.invokeLater(this::repaint); } - private static double asNormalizedRadians(double angle) - { - while (angle < 0) - { - angle += 2*Math.PI; - } - while (angle >= 2*Math.PI) - { - angle -= 2*Math.PI; - } - return angle; - } - - private static int round(double value) - { - return (int)(value + 0.5); - } - @Override - public void paint(Graphics g) - { + public void paint(Graphics g) { super.paint(g); - Graphics2D g2d = (Graphics2D)g; - drawRobot(g2d, round(m_robotPositionX), round(m_robotPositionY), m_robotDirection); + Graphics2D g2d = (Graphics2D) g; + drawRobot(g2d, GameDataModel.round(m_robotPositionX), GameDataModel.round(m_robotPositionY), m_robotDirection); drawTarget(g2d, m_targetPositionX, m_targetPositionY); } - - private static void fillOval(Graphics g, int centerX, int centerY, int diam1, int diam2) - { + + private static void fillOval(Graphics g, int centerX, int centerY, int diam1, int diam2) { g.fillOval(centerX - diam1 / 2, centerY - diam2 / 2, diam1, diam2); } - - private static void drawOval(Graphics g, int centerX, int centerY, int diam1, int diam2) - { + + private static void drawOval(Graphics g, int centerX, int centerY, int diam1, int diam2) { g.drawOval(centerX - diam1 / 2, centerY - diam2 / 2, diam1, diam2); } - - private void drawRobot(Graphics2D g, int x, int y, double direction) - { - int robotCenterX = round(m_robotPositionX); - int robotCenterY = round(m_robotPositionY); - AffineTransform t = AffineTransform.getRotateInstance(direction, robotCenterX, robotCenterY); + + private void drawRobot(Graphics2D g, int x, int y, double direction) { + int robotCenterX = GameDataModel.round(m_robotPositionX); + int robotCenterY = GameDataModel.round(m_robotPositionY); + AffineTransform t = AffineTransform.getRotateInstance(direction, robotCenterX, robotCenterY); g.setTransform(t); g.setColor(Color.MAGENTA); fillOval(g, robotCenterX, robotCenterY, 30, 10); g.setColor(Color.BLACK); drawOval(g, robotCenterX, robotCenterY, 30, 10); g.setColor(Color.WHITE); - fillOval(g, robotCenterX + 10, robotCenterY, 5, 5); + fillOval(g, robotCenterX + 10, robotCenterY, 5, 5); g.setColor(Color.BLACK); - drawOval(g, robotCenterX + 10, robotCenterY, 5, 5); + drawOval(g, robotCenterX + 10, robotCenterY, 5, 5); } - - private void drawTarget(Graphics2D g, int x, int y) - { - AffineTransform t = AffineTransform.getRotateInstance(0, 0, 0); + + private void drawTarget(Graphics2D g, int x, int y) { + AffineTransform t = AffineTransform.getRotateInstance(0, 0, 0); g.setTransform(t); g.setColor(Color.GREEN); fillOval(g, x, y, 5, 5); g.setColor(Color.BLACK); drawOval(g, x, y, 5, 5); } + + @Override + public void update(Observable o, Object key) { + if (Helpers.areEqual(d_model, o)) + { + if (Helpers.areEqual(GameDataModel.KEY_COORDINATE_ROBOT, key)) + { + m_robotPositionX = d_model.getM_robotPositionX(); + m_robotPositionY = d_model.getM_robotPositionY(); + m_robotDirection = d_model.getM_robotDirection(); + } + if (Helpers.areEqual(GameDataModel.KEY_COORDINATE_TARGET, key)) + { + m_targetPositionX = d_model.getM_targetPositionX(); + m_targetPositionY = d_model.getM_targetPositionY(); + } + } + } } diff --git a/robots/src/gui/GameWindow.java b/robots/src/gui/GameWindow.java index ecb63c00f..aebd8f753 100644 --- a/robots/src/gui/GameWindow.java +++ b/robots/src/gui/GameWindow.java @@ -2,14 +2,14 @@ import java.awt.BorderLayout; -import javax.swing.JInternalFrame; -import javax.swing.JPanel; +import javax.swing.*; public class GameWindow extends JInternalFrame { private final GameVisualizer m_visualizer; public GameWindow() { + super("Игровое поле", true, true, true, true); m_visualizer = new GameVisualizer(); JPanel panel = new JPanel(new BorderLayout()); diff --git a/robots/src/gui/MainApplicationFrame.java b/robots/src/gui/MainApplicationFrame.java index 62e943ee1..35fe51a2e 100644 --- a/robots/src/gui/MainApplicationFrame.java +++ b/robots/src/gui/MainApplicationFrame.java @@ -1,79 +1,114 @@ package gui; -import java.awt.Dimension; -import java.awt.Toolkit; +import java.awt.*; import java.awt.event.KeyEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.beans.PropertyVetoException; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Locale; +import java.util.ResourceBundle; -import javax.swing.JDesktopPane; -import javax.swing.JFrame; -import javax.swing.JInternalFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.SwingUtilities; -import javax.swing.UIManager; -import javax.swing.UnsupportedLookAndFeelException; +import javax.swing.*; import log.Logger; /** * Что требуется сделать: - * 1. Метод создания меню перегружен функционалом и трудно читается. + * 1. Метод создания меню перегружен функционалом и трудно читается. * Следует разделить его на серию более простых методов (или вообще выделить отдельный класс). - * */ -public class MainApplicationFrame extends JFrame -{ +public class MainApplicationFrame extends JFrame { private final JDesktopPane desktopPane = new JDesktopPane(); - + public MainApplicationFrame() { //Make the big window be indented 50 pixels from each edge //of the screen. - int inset = 50; + int inset = 50; Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setBounds(inset, inset, - screenSize.width - inset*2, - screenSize.height - inset*2); + screenSize.width - inset * 2, + screenSize.height - inset * 2); setContentPane(desktopPane); - - + Rectangle logRec = new Rectangle(10, 10, 300, 800); + Rectangle gameRec = new Rectangle(0, 0, 400, 400); + HashMap mapCheck = new HashMap<>(); + mapCheck.put("\"Протокол работы\"", logRec); + mapCheck.put("\"Игровое поле\"", gameRec); LogWindow logWindow = createLogWindow(); + GameWindow gameWindow = new GameWindow(); + setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); + try { + String string = readUsingFiles(System.getenv("USERPROFILE") + "\\setting.txt"); + String[] arr = string.split("\n"); + if (arr[0].equals("1")) { + for (String strSave : arr) { + String[] temp1 = strSave.split("(?<=[\"\\d]) "); + if (mapCheck.containsKey(temp1[0])) { + Rectangle tempRectangle = mapCheck.get(temp1[0]); + tempRectangle.x = Integer.parseInt(temp1[2].substring(2)); + tempRectangle.y = Integer.parseInt(temp1[3].substring(2)); + tempRectangle.width = Integer.parseInt(temp1[4].substring(6)); + tempRectangle.height = Integer.parseInt(temp1[5].substring(7)); + } + } + } + } catch (IOException ignored) { + } + logWindow.setBounds(logRec); addWindow(logWindow); - GameWindow gameWindow = new GameWindow(); - gameWindow.setSize(400, 400); - addWindow(gameWindow); + gameWindow.setBounds(gameRec); + addWindow(gameWindow); setJMenuBar(generateMenuBar()); - setDefaultCloseOperation(EXIT_ON_CLOSE); + addWindowListener(new WindowAdapter() + { + @Override + public void windowClosing(WindowEvent e) + { + System.out.println("Closed"); + try { + exit(); + } catch (IOException ex) { + throw new RuntimeException(ex); + } + } + }); } - - protected LogWindow createLogWindow() - { + + protected LogWindow createLogWindow() { LogWindow logWindow = new LogWindow(Logger.getDefaultLogSource()); - logWindow.setLocation(10,10); - logWindow.setSize(300, 800); setMinimumSize(logWindow.getSize()); logWindow.pack(); Logger.debug("Протокол работает"); return logWindow; } - - protected void addWindow(JInternalFrame frame) - { + + private static String readUsingFiles(String fileName) throws IOException { + return new String(Files.readAllBytes(Paths.get(fileName))); + } + + protected void addWindow(JInternalFrame frame) { desktopPane.add(frame); frame.setVisible(true); } - + // protected JMenuBar createMenuBar() { // JMenuBar menuBar = new JMenuBar(); -// +// // //Set up the lone menu. // JMenu menu = new JMenu("Document"); // menu.setMnemonic(KeyEvent.VK_D); // menuBar.add(menu); -// +// // //Set up the first menu item. // JMenuItem menuItem = new JMenuItem("New"); // menuItem.setMnemonic(KeyEvent.VK_N); @@ -82,7 +117,7 @@ protected void addWindow(JInternalFrame frame) // menuItem.setActionCommand("new"); //// menuItem.addActionListener(this); // menu.add(menuItem); -// +// // //Set up the second menu item. // menuItem = new JMenuItem("Quit"); // menuItem.setMnemonic(KeyEvent.VK_Q); @@ -91,19 +126,21 @@ protected void addWindow(JInternalFrame frame) // menuItem.setActionCommand("quit"); //// menuItem.addActionListener(this); // menu.add(menuItem); -// +// // return menuBar; // } - - private JMenuBar generateMenuBar() - { + + private JMenuBar generateMenuBar() { + Locale current = new Locale("ru", "RU"); + ResourceBundle myResources = + ResourceBundle.getBundle("text", current); JMenuBar menuBar = new JMenuBar(); - + JMenu lookAndFeelMenu = new JMenu("Режим отображения"); lookAndFeelMenu.setMnemonic(KeyEvent.VK_V); lookAndFeelMenu.getAccessibleContext().setAccessibleDescription( "Управление режимом отображения приложения"); - + { JMenuItem systemLookAndFeel = new JMenuItem("Системная схема", KeyEvent.VK_S); systemLookAndFeel.addActionListener((event) -> { @@ -126,7 +163,7 @@ private JMenuBar generateMenuBar() testMenu.setMnemonic(KeyEvent.VK_T); testMenu.getAccessibleContext().setAccessibleDescription( "Тестовые команды"); - + { JMenuItem addLogMessageItem = new JMenuItem("Сообщение в лог", KeyEvent.VK_S); addLogMessageItem.addActionListener((event) -> { @@ -134,23 +171,60 @@ private JMenuBar generateMenuBar() }); testMenu.add(addLogMessageItem); } + { + JMenuItem standartExit = new JMenuItem("Выход", KeyEvent.VK_T); + standartExit.addActionListener((event) -> { + try { + exit(); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + testMenu.add(standartExit); + } menuBar.add(lookAndFeelMenu); menuBar.add(testMenu); return menuBar; } - - private void setLookAndFeel(String className) - { - try - { + + private void exit() throws IOException { + Object[] options = {"Да", + "Нет"}; + int s = JOptionPane.showOptionDialog(null, "Вы уверены что хотите выйти?", "Уведомление", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); + if (s == 0) { + File file = new File(System.getenv("USERPROFILE") + "\\setting.txt"); + if (file.createNewFile()) { + System.out.println("File is created!"); + } else { + System.out.println("File already exists."); + } + FileWriter writer = new FileWriter(file); + writer.write("1\n"); + writer.write("Test data:\n"); + JInternalFrame[] arr = desktopPane.getAllFrames(); + for (JInternalFrame var : arr) { + writer.write("\"" + var.getTitle() + "\" "); + if (var.isIcon()) + writer.write("\"Не Свёрнуто\" "); + else + writer.write("\"Свёрнуто\" "); + Rectangle a = var.getBounds(); + writer.write("x=" + a.x + " y=" + a.y + " width=" + a.width + " "); + writer.write("height=" + a.height + "\n"); + } + writer.close(); + System.exit(0); + } + } + + private void setLookAndFeel(String className) { + try { UIManager.setLookAndFeel(className); SwingUtilities.updateComponentTreeUI(this); - } - catch (ClassNotFoundException | InstantiationException - | IllegalAccessException | UnsupportedLookAndFeelException e) - { + } catch (ClassNotFoundException | InstantiationException + | IllegalAccessException | UnsupportedLookAndFeelException e) { // just ignore } } -} +} \ No newline at end of file