commit afacff8476d1d3962ae55bd9c9c33fd789564023 Author: René Knipschild Date: Thu Jun 2 16:16:04 2022 +0200 init commit diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..217af47 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/.idea/description.html b/.idea/description.html new file mode 100644 index 0000000..db5f129 --- /dev/null +++ b/.idea/description.html @@ -0,0 +1 @@ +Simple Java application that includes a class with main() method \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..1b10d94 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..0c33d9e --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/HowToJava.iml b/HowToJava.iml new file mode 100644 index 0000000..d5c0743 --- /dev/null +++ b/HowToJava.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/Main2.java b/src/Main2.java new file mode 100644 index 0000000..3778360 --- /dev/null +++ b/src/Main2.java @@ -0,0 +1,30 @@ +import com.rkcsd.apps.demo.gui.MainWindow; + +public class Main2 { + + public static void main(String[] args) { + + MainWindow w = new MainWindow(); + + } + + public static void main2(String[] args) { + + MyApp abc = new MyApp("Hello World", 0); + abc.appVersion = 6; + abc.setAppName("Test"); + + System.out.println("MyStaticApp.getAppName()" + MyStaticApp.getAppName()); + + MyApp xyz = new MyApp("zweite App", 5); + xyz.setAppName("hkjhkjh"); + + System.out.println(abc.getAppName()); + System.out.println(xyz.getAppName()); + + MyStaticApp.appVersion = 4; + //MyStaticApp.setAppName("static rulez!"); + + System.out.println("MyStaticApp.getAppName()" + MyStaticApp.getAppName()); + } +} diff --git a/src/MyApp.java b/src/MyApp.java new file mode 100644 index 0000000..90d2fcf --- /dev/null +++ b/src/MyApp.java @@ -0,0 +1,18 @@ +public class MyApp { + private String appName = "Test"; + public int appVersion = 6; + + public MyApp(String appName, int appVersion) { + } + + public void setAppName(String appName) { + MyStaticApp.setAppName(appName); + this.appName = appName + "!"; + } + + public String getAppName() { + return appName; + } +} + + diff --git a/src/MyStaticApp.java b/src/MyStaticApp.java new file mode 100644 index 0000000..dc051c5 --- /dev/null +++ b/src/MyStaticApp.java @@ -0,0 +1,12 @@ +public class MyStaticApp { + private static String appName = "Test"; + public static int appVersion = 6; + + public static void setAppName(String appName) { + MyStaticApp.appName = appName + "!"; + } + + public static String getAppName() { + return appName; + } +} diff --git a/src/com/rkcsd/apps/demo/gui/MainWindow.java b/src/com/rkcsd/apps/demo/gui/MainWindow.java new file mode 100644 index 0000000..6bbe981 --- /dev/null +++ b/src/com/rkcsd/apps/demo/gui/MainWindow.java @@ -0,0 +1,94 @@ +package com.rkcsd.apps.demo.gui; + +import com.rkcsd.apps.demo.main.Calculator; +import com.rkcsd.apps.demo.main.Main; +import com.rkcsd.apps.demo.main.StringToNumberConverter; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JTextField; + +public class MainWindow extends JFrame { + + private JTextField input1; + private JTextField input2; + + private JLabel text; + + private JButton btnPrinterList; + private JButton btnAdminPanel; + private JButton btnExit; + + private JComboBox cbx; + + public MainWindow() { + super("Meine Anwendung"); + this.setSize(1000, 500); + + this.setLayout(null); + + btnPrinterList = new JButton("DL Anzeigen"); + btnPrinterList.setBounds(10, 210, 500, 20); + btnPrinterList.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + + PrinterListWindow secondWindow = new PrinterListWindow(MainWindow.this); + + } + + }); + this.add(btnPrinterList); + + btnAdminPanel = new JButton("Admin Panel öffnen"); + btnAdminPanel.setBounds(10, 105, 500, 20); + btnAdminPanel.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + + MainWindow second = new MainWindow(); + + } + + }); + this.add(btnAdminPanel); + + btnExit = new JButton("Beenden"); + btnExit.setBounds(500, 315, 500, 20); + btnExit.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + + System.exit(0); + + } + + }); + this.add(btnExit); + + this.setVisible(true); + } + + private void doAction() { + StringToNumberConverter stnc1 = new StringToNumberConverter(input1.getText()); + StringToNumberConverter stnc2 = new StringToNumberConverter(input2.getText()); + + double d1 = stnc1.doConversion(); + double d2 = stnc2.doConversion(); + + if (stnc1.hasError() || stnc2.hasError()) { + JOptionPane.showMessageDialog(MainWindow.this, + "Da ging wohl was schief"); + } else { + Calculator calc = new Calculator(d1, d2); + if (cbx.getSelectedItem().equals("+")) { + calc.doAdd(); + } else if (cbx.getSelectedItem().equals("-")) { + calc.doSubtract(); + } + JOptionPane.showMessageDialog(MainWindow.this, + "Das Ergebnis lautet: " + calc.getResult()); + } + } +} diff --git a/src/com/rkcsd/apps/demo/gui/MainWindowOld.java b/src/com/rkcsd/apps/demo/gui/MainWindowOld.java new file mode 100644 index 0000000..6e66c7e --- /dev/null +++ b/src/com/rkcsd/apps/demo/gui/MainWindowOld.java @@ -0,0 +1,87 @@ +package com.rkcsd.apps.demo.gui; + +import com.rkcsd.apps.demo.main.Calculator; +import com.rkcsd.apps.demo.main.StringToNumberConverter; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JTextField; + +public class MainWindowOld extends JFrame { + + private JTextField input1; + private JTextField input2; + + private JLabel text; + + private JButton action; + + private JComboBox cbx; + + public MainWindowOld() { + super("Meine Anwendung"); + this.setSize(1000, 500); + + this.setLayout(null); + + text = new JLabel("Bitte geben Sie etwas ein:"); + text.setBounds(10, 10, 500, 20); + this.add(text); + + input1 = new JTextField(); + input1.setBounds(10, 60, 500, 20); + this.add(input1); + + input2 = new JTextField(); + input2.setBounds(10, 110, 500, 20); + this.add(input2); + + cbx = new JComboBox(); + cbx.setBounds(10, 160, 500, 20); + cbx.addItem("+"); + cbx.addItem("-"); + this.add(cbx); + + action = new JButton("Beschriftung"); + action.setBounds(10, 210, 500, 20); + action.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + + MainWindowOld.this.doAction(); + + } + + }); + this.add(action); + + + + this.setVisible(true); + } + + private void doAction() { + StringToNumberConverter stnc1 = new StringToNumberConverter(input1.getText()); + StringToNumberConverter stnc2 = new StringToNumberConverter(input2.getText()); + + double d1 = stnc1.doConversion(); + double d2 = stnc2.doConversion(); + + if (stnc1.hasError() || stnc2.hasError()) { + JOptionPane.showMessageDialog(MainWindowOld.this, + "Da ging wohl was schief"); + } else { + Calculator calc = new Calculator(d1, d2); + if (cbx.getSelectedItem().equals("+")) { + calc.doAdd(); + } else if (cbx.getSelectedItem().equals("-")) { + calc.doSubtract(); + } + JOptionPane.showMessageDialog(MainWindowOld.this, + "Das Ergebnis lautet: " + calc.getResult()); + } + } +} diff --git a/src/com/rkcsd/apps/demo/gui/PrinterListWindow.java b/src/com/rkcsd/apps/demo/gui/PrinterListWindow.java new file mode 100644 index 0000000..8e42e4e --- /dev/null +++ b/src/com/rkcsd/apps/demo/gui/PrinterListWindow.java @@ -0,0 +1,19 @@ +package com.rkcsd.apps.demo.gui; + +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JTable; + +public class PrinterListWindow extends JDialog { + public PrinterListWindow(JFrame mainWindow) { + super(mainWindow); + setLayout(null); + setSize(800, 600); + + JTable t = new JTable(); + t.setBounds(10, 10, 700, 500); + this.add(t); + + setVisible(true); + } +} diff --git a/src/com/rkcsd/apps/demo/main/Calculator.java b/src/com/rkcsd/apps/demo/main/Calculator.java new file mode 100644 index 0000000..e65e84d --- /dev/null +++ b/src/com/rkcsd/apps/demo/main/Calculator.java @@ -0,0 +1,32 @@ +package com.rkcsd.apps.demo.main; + +public class Calculator { + private double value1; + private double value2; + private double result; + + public Calculator(double value1, double value2) { + setValue1(value1); + setValue2(value2); + } + + public void setValue1(double value1) { + this.value1 = value1; + } + + public void setValue2(double value2) { + this.value2 = value2; + } + + public void doAdd() { + result = value1 + value2; + } + + public void doSubtract(){ + result = value1 - value2; + } + + public double getResult() { + return result; + } +} diff --git a/src/com/rkcsd/apps/demo/main/Main.java b/src/com/rkcsd/apps/demo/main/Main.java new file mode 100644 index 0000000..eb23868 --- /dev/null +++ b/src/com/rkcsd/apps/demo/main/Main.java @@ -0,0 +1,14 @@ +package com.rkcsd.apps.demo.main; + +import com.rkcsd.apps.demo.gui.MainWindow; + +public class Main { + + public static void main(String[] args) { + + MainWindow w = new MainWindow(); + + } + + +} \ No newline at end of file diff --git a/src/com/rkcsd/apps/demo/main/StringToNumberConverter.java b/src/com/rkcsd/apps/demo/main/StringToNumberConverter.java new file mode 100644 index 0000000..8a06f7b --- /dev/null +++ b/src/com/rkcsd/apps/demo/main/StringToNumberConverter.java @@ -0,0 +1,22 @@ +package com.rkcsd.apps.demo.main; + +public class StringToNumberConverter { + private String s; + private double n; + private boolean error; + public StringToNumberConverter(String s) { + this.s = s; + } + public double doConversion() { + this.error = false; + try { + n = Double.parseDouble(s); + } catch (NumberFormatException e) { + this.error = true; + } + return n; + } + public boolean hasError() { + return error; + } +}