diff --git a/cs-115-test/.gitignore b/cs-115-test/.gitignore
new file mode 100644
index 0000000..f68d109
--- /dev/null
+++ b/cs-115-test/.gitignore
@@ -0,0 +1,29 @@
+### IntelliJ IDEA ###
+out/
+!**/src/main/**/out/
+!**/src/test/**/out/
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+bin/
+!**/src/main/**/bin/
+!**/src/test/**/bin/
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store
\ No newline at end of file
diff --git a/cs-115-test/.idea/.gitignore b/cs-115-test/.idea/.gitignore
new file mode 100644
index 0000000..a0ccf77
--- /dev/null
+++ b/cs-115-test/.idea/.gitignore
@@ -0,0 +1,5 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Environment-dependent path to Maven home directory
+/mavenHomeManager.xml
diff --git a/cs-115-test/.idea/misc.xml b/cs-115-test/.idea/misc.xml
new file mode 100644
index 0000000..a9182a4
--- /dev/null
+++ b/cs-115-test/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit." + + " Duis rutrum arcu mauris, et vulputate arcu laoreet vitae.
"); + + myFrame.setContentPane(latinPane); + myFrame.setVisible(true); + } +} diff --git a/cs-115-test/src/ExceptionsDemo.java b/cs-115-test/src/ExceptionsDemo.java new file mode 100644 index 0000000..e6f92d3 --- /dev/null +++ b/cs-115-test/src/ExceptionsDemo.java @@ -0,0 +1,28 @@ +import javax.swing.*; +import java.util.InputMismatchException; + +public class ExceptionsDemo { + public static void main(String[] args) { + int numerator = 0; + int denominator = 0; + int result; + + String inputString; + + try { + inputString = JOptionPane.showInputDialog(null, "Enter a number to be divided"); + numerator = Integer.parseInt(inputString); + inputString = JOptionPane.showInputDialog(null, "Enter a number to divide into the first number"); + denominator = Integer.parseInt(inputString); + result = numerator / denominator; + + JOptionPane.showMessageDialog(null, numerator + " / " + denominator + "\nResult is " + result); + } catch (ArithmeticException exception) { + JOptionPane.showMessageDialog(null, exception.getMessage()); + result = 0; + } catch (NumberFormatException exception) { + JOptionPane.showMessageDialog(null, "Please enter only Integers!"); + result = 0; + } + } +} diff --git a/cs-115-test/src/Files.java b/cs-115-test/src/Files.java new file mode 100644 index 0000000..d0fb6a8 --- /dev/null +++ b/cs-115-test/src/Files.java @@ -0,0 +1,73 @@ +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.*; +import javax.swing.JEditorPane; + +public class Files extends JFrame implements ActionListener { + + JTextArea textArea; + JMenuItem open; + JEditorPane latinPane; + + public static void main(String[] args) { + Files filePicker = new Files(); + filePicker.setSize(600, 600); + filePicker.setLayout(null); + filePicker.setVisible(true); + filePicker.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + } + + public Files() { + JMenuBar menuBar = new JMenuBar(); + JMenu file = new JMenu("File"); + latinPane = new JEditorPane(); + open = new JMenuItem("Open File"); + open.addActionListener(this); + textArea = new JTextArea(600, 600); + JEditorPane latinPane = new JEditorPane(); + + latinPane.setContentType("text/plain"); + file.add(open); + menuBar.setBounds(0, 0, 600, 20); + menuBar.add(file); + textArea.setBounds(0, 20, 600, 600); + add(menuBar); + add(latinPane); + + latinPane.setContentType("text/plain"); + add(latinPane); + add(textArea); + } + + public void actionPerformed(ActionEvent event) { + if (event.getSource() == open) { + JFileChooser fileChooser = new JFileChooser(); + int i = fileChooser.showOpenDialog(this); + + if (i == JFileChooser.APPROVE_OPTION) { + File file = fileChooser.getSelectedFile(); + String filePath = file.getPath(); + + try { + BufferedReader bufferedReader = new BufferedReader(new FileReader(filePath)); + String s1 = ""; + String s2 = ""; + while ( (s1 = bufferedReader.readLine()) != null ) { + s2 += s1 + "\n"; + } + + latinPane.setText(s2); + //textArea.setText(s2); + bufferedReader.close(); + } catch (FileNotFoundException exception) { + System.out.println("FUCK"); + } catch (IOException exception) { + System.out.println("SHIT"); + } catch (Exception exception) { + exception.printStackTrace(); + } + } + } + } +} diff --git a/cs-115-test/src/GUIOutput.java b/cs-115-test/src/GUIOutput.java new file mode 100644 index 0000000..9221922 --- /dev/null +++ b/cs-115-test/src/GUIOutput.java @@ -0,0 +1,46 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class GUIOutput { + public static void main(String[] args) { + new GUIOutput(); + } + + public GUIOutput() { + JFrame guiFrame = new JFrame(); + guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + guiFrame.setTitle("My Gui App"); + guiFrame.setSize(1920, 1080); + guiFrame.setLocationRelativeTo(null); + + String[] northAmerican = {"USA", "Canada"}; + String[] westernEurope = {"United Kingdom", "France", "Germany"}; + + final JPanel comboPanel = new JPanel(); + JLabel comboLbl = new JLabel("North American Countries:"); + JComboBox namerica = new JComboBox(northAmerican); + comboPanel.add(comboLbl); + comboPanel.add(namerica); + + final JPanel listPanel = new JPanel(); + listPanel.setVisible(false); + + JLabel listLbl = new JLabel("Western Europe Countries:"); + JList westerneu = new JList(westernEurope); + westerneu.setLayoutOrientation(JList.HORIZONTAL_WRAP); + listPanel.add(listLbl); + listPanel.add(westerneu); + JButton ameEuBut = new JButton(((ActionListener) event -> { + listPanel.setVisible(!listPanel.isVisible()); + comboPanel.setVisible(!comboPanel.isVisible()); + }).toString()); + + guiFrame.add(comboPanel, BorderLayout.NORTH); + guiFrame.add(listPanel, BorderLayout.CENTER); + guiFrame.add(ameEuBut, BorderLayout.SOUTH); + + guiFrame.setVisible(true); + } +} diff --git a/cs-115-test/src/List.java b/cs-115-test/src/List.java new file mode 100644 index 0000000..c916c27 --- /dev/null +++ b/cs-115-test/src/List.java @@ -0,0 +1,36 @@ +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class List { + public static void main(String[] args) { + JFrame frame = new JFrame(); + String[] trees = { "Maple", "Larch", "Spruce", "Balsam" }; + JList treeList = new JList(trees); + JPanel panel = new JPanel(); + + JLabel label = new JLabel("Select a Tree"); + + treeList.add(panel); + + JButton button = new JButton("Show Me"); + button.setBounds(10, 150, 230, 30); + + button.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String data = ""; + if (treeList.getSelectedIndex() != -1) { + data = "Trees: " + treeList.getSelectedValue(); + button.setText(data); + } + } + }); + + frame.add(button); + frame.add(treeList); + frame.setSize(250, 250); + frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + frame.setVisible(true); + } +} diff --git a/cs-115-test/src/Main.java b/cs-115-test/src/Main.java new file mode 100644 index 0000000..f46d48d --- /dev/null +++ b/cs-115-test/src/Main.java @@ -0,0 +1,135 @@ +import java.util.Arrays; +import java.util.Scanner; + +class Rectangle { + private double height; + private double width; + + public Rectangle(double h, double w) { + height = h; + width = w; + } + + public double Perimeter() { + return 2.0 * (height + width); + } + + public double Area() { + return height * width; + } +} + +enum DayOfWeek { + SUNDAY(0), + MONDAY(1), + TUESDAY(2), + WEDNESDAY(3), + THURSDAY(4), + FRIDAY(5), + SATURDAY(6); + + private int value; + + private DayOfWeek(int value) { + this.value = value; + } + + public int getDayOfWeekValue() { + return this.value; + } +} + +public class Main { + public static void main(String[] args) { + } + + public static void showMsg(String... vars) { + for (String s: vars) { + System.out.println("Arg = " + s); + } + } + + public static void multiplyMatrix() { + int[][] myMatrixA = { + {3, 5, 7}, + {9, 17, 12}, + {32, 21, 5} + }; + + int[][] myMatrixB = { + {1, 3, 5}, + {7, 9, 11}, + {13, 15, 17} + }; + + int rowsA = myMatrixA.length; + int colsA = myMatrixA[0].length; + int rowsB = myMatrixB.length; + int colsB = myMatrixB[0].length; + + int[][] myMatrixC = new int [rowsA][colsB]; + + System.out.println(Arrays.deepToString(myMatrixC)); + + for (int i = 0; i < rowsA; i++) { + for (int j = 0; j < colsB; j++) { + for (int k = 0; k < colsA; k++) { + myMatrixC[i][j] += myMatrixA[i][k] * myMatrixB[k][j]; + } + } + } + + System.out.println("Multiplying A and B equals: "); + for (int m = 0; m < myMatrixC.length; m++) { + for (int n = 0; n < myMatrixC[0].length; n++) { + System.out.print(myMatrixC[m][n] + " "); + } + System.out.println(); + } + } + + public static void randomChapter() { + double r = 0.0; + int priceCategory = 0; + int revenue = 0; + int firstClassPassengerCount = 0; + int businessClassPassengerCount = 0; + + r = Math.random(); + priceCategory = (int)(3.0 * r) + 1; + + if (priceCategory == 1) { + firstClassPassengerCount++; + + if (firstClassPassengerCount <= 25) { + revenue += 250; + } + } else if (priceCategory == 2) { + businessClassPassengerCount++; + + if (businessClassPassengerCount <= 25) { + revenue += 170; + } + } else if (priceCategory == 3) { + revenue += 100; + } + + System.out.println(revenue); + } + + public static void usingScanner() { + int firstNum, secondNum, sum, diff, avg; + Scanner input = new Scanner(System.in); + System.out.println("Please enter an integer: "); + firstNum = input.nextInt(); + System.out.println("Please enter another integer: "); + secondNum = input.nextInt(); + sum = firstNum + secondNum; + diff = firstNum - secondNum; + avg = sum / 2; + System.out.println("The Sum " + firstNum + " + " + secondNum + " = " + sum); + System.out.println("The Difference " + firstNum + " - " + secondNum + " = " + diff); + System.out.println("The Average " + sum + " / " + "2" + " = " + avg); + input.close(); + } +} \ No newline at end of file diff --git a/cs-115-test/src/MenuBar.java b/cs-115-test/src/MenuBar.java new file mode 100644 index 0000000..1cf288b --- /dev/null +++ b/cs-115-test/src/MenuBar.java @@ -0,0 +1,36 @@ +import javax.swing.*; + +public class MenuBar { + JMenu menu, subMenu; + JMenuItem i1, i2, i3, i4, i5, i6; + + public MenuBar() { + JFrame frame = new JFrame(); + + JMenuBar menuBar = new JMenuBar(); + + menu = new JMenu("Options"); + subMenu = new JMenu("Pan Types"); + + i1 = new JMenuItem("Spatula"); + i2 = new JMenuItem("Stove"); + i3 = new JMenuItem("Broiler"); + i4 = new JMenuItem("Frying Pan"); + i5 = new JMenuItem("Skillet"); + i6 = new JCheckBoxMenuItem("Hey Check Me!"); + menu.add(i1); menu.add(i2); menu.add(i3); + subMenu.add(i4); subMenu.add(i5); subMenu.add(i6); + menu.add(subMenu); + menu.add(subMenu); + menuBar.add(menu); + frame.setJMenuBar(menuBar); + frame.setSize(1920, 1080); + frame.setLayout(null); + frame.setVisible(true); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + } + + public static void main(String[] args) { + new MenuBar(); + } +} diff --git a/cs-115-test/src/Reflection.java b/cs-115-test/src/Reflection.java new file mode 100644 index 0000000..89022c9 --- /dev/null +++ b/cs-115-test/src/Reflection.java @@ -0,0 +1,20 @@ +import java.lang.Class; +import java.lang.reflect.Method; + +public class Reflection { + public static void main(String[] args) { + Reflection b = new Reflection(); + Class extends Reflection> showMe = b.getClass(); + System.out.println(showMe); + Class extends Reflection> dClass = Reflection.class; + Method[] methods = dClass.getDeclaredMethods(); + + for(Method method: methods) { + System.out.println("Method name = " + method.getName()); + } + } + + void display() { + System.out.println("This is a Message!"); + } +} diff --git a/cs-115-test/src/Slider.java b/cs-115-test/src/Slider.java new file mode 100644 index 0000000..de71cf0 --- /dev/null +++ b/cs-115-test/src/Slider.java @@ -0,0 +1,44 @@ +import javax.swing.*; +import java.awt.*; +import java.util.Hashtable; + +public class Slider extends JPanel { + public Slider() { + initializeUI(); + } + + public static void main(String[] args) { + Slider.showFrame(); + } + + private void initializeUI() { + setLayout(new BorderLayout()); + setPreferredSize(new Dimension(500, 200)); + JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 35, 0); + slider.setMinorTickSpacing(1); + slider.setMajorTickSpacing(5); + slider.setPaintTicks(true); + + Hashtable