diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f26e9d9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +nbproject/private/ +build/ +dist/ \ No newline at end of file diff --git a/nbproject/project.properties b/nbproject/project.properties index 0ad604d..e99a9eb 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -53,7 +53,7 @@ javadoc.splitindex=true javadoc.use=true javadoc.version=false javadoc.windowtitle= -main.class=com.nummethods.lr4.LR_4 +main.class=Main manifest.file=manifest.mf meta.inf.dir=${src.dir}/META-INF mkdist.disabled=false diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..4201daa --- /dev/null +++ b/src/Main.java @@ -0,0 +1,80 @@ + +import java.awt.EventQueue; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.lang.reflect.Method; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.UIManager; +import javax.swing.WindowConstants; +import javax.swing.border.EmptyBorder; + +/** + * Класс меню, запускающий лабораторные работы. + * @author aNNiMON + */ +public class Main extends JFrame { + + private static final int NUM_OF_LABS = 4; + + public static void main(String[] args) { + try { + for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (Exception ex) { } + + EventQueue.invokeLater(new Runnable() { + + @Override + public void run() { + new Main().setVisible(true); + } + }); + + } + + public Main() { + setTitle("Численные методы"); + setResizable(false); + setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + + JPanel panel = new JPanel(); + initPanel(panel); + + getContentPane().add(panel); + pack(); + setLocationRelativeTo(null); + } + + private void initPanel(JPanel panel) { + panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS)); + for (int i = 1; i <= NUM_OF_LABS; i++) { + panel.add(createButton("Лабораторная работа №"+i, i)); + } + panel.setBorder(new EmptyBorder(10, 10, 10, 10)); + } + + private JButton createButton(final String text, final int num) { + JButton button = new JButton(); + button.setText(text); + button.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + try { + // Вызов метода main динамически. + Class cls = Class.forName("com.nummethods.lr"+num+".LR_"+num); + Method meth = cls.getMethod("main", String[].class); + meth.invoke(null, (Object) null); + } catch (Exception cne) {} + } + }); + return button; + } +} diff --git a/src/com/nummethods/lr3/LR_3.java b/src/com/nummethods/lr3/LR_3.java index 902e0dc..5355aec 100644 --- a/src/com/nummethods/lr3/LR_3.java +++ b/src/com/nummethods/lr3/LR_3.java @@ -3,7 +3,6 @@ package com.nummethods.lr3; import java.awt.Dimension; import java.awt.geom.Point2D; import javax.swing.JFrame; -import static javax.swing.JFrame.EXIT_ON_CLOSE; /** * @author aNNiMON @@ -17,7 +16,7 @@ public class LR_3 extends JFrame { public LR_3() { super("LR_3"); setBounds(300, 120, 0, 0); - setDefaultCloseOperation(EXIT_ON_CLOSE); + setDefaultCloseOperation(DISPOSE_ON_CLOSE); Point2D[] input = new Point2D[] { new Point2D.Double(1, 2.0), diff --git a/src/com/nummethods/lr4/LR_4.java b/src/com/nummethods/lr4/LR_4.java index 5252e57..22f83a3 100644 --- a/src/com/nummethods/lr4/LR_4.java +++ b/src/com/nummethods/lr4/LR_4.java @@ -44,7 +44,7 @@ public class LR_4 extends JFrame { public LR_4() { super("LR_4"); setBounds(300, 120, 0, 0); - setDefaultCloseOperation(EXIT_ON_CLOSE); + setDefaultCloseOperation(DISPOSE_ON_CLOSE); SimpsonIntegrate simpson = new SimpsonIntegrate(var10); System.out.println( simpson.calculate(6) );