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 @@ + + + + + + \ No newline at end of file diff --git a/cs-115-test/.idea/modules.xml b/cs-115-test/.idea/modules.xml new file mode 100644 index 0000000..fdaf302 --- /dev/null +++ b/cs-115-test/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/cs-115-test/cs-115-test.iml b/cs-115-test/cs-115-test.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/cs-115-test/cs-115-test.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/cs-115-test/src/Advance.java b/cs-115-test/src/Advance.java new file mode 100644 index 0000000..94c65a9 --- /dev/null +++ b/cs-115-test/src/Advance.java @@ -0,0 +1,3 @@ +public interface Advance { + void advance(int increment); +} diff --git a/cs-115-test/src/AppletOne.java b/cs-115-test/src/AppletOne.java new file mode 100644 index 0000000..7293ac0 --- /dev/null +++ b/cs-115-test/src/AppletOne.java @@ -0,0 +1,85 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; + +public class AppletOne extends JFrame implements ItemListener { + + final int WEEKEND_PREMIUM = 100; + final int BREAKFAST_PREMIUM = 20; + final int GOLF_PREMIUM = 75; + final int BASE_PRICE = 200; + int totalPrice = BASE_PRICE; + + JCheckBox weekendBox = new JCheckBox("Weekend Premium $" + WEEKEND_PREMIUM, false); + JCheckBox breakfastBox = new JCheckBox("Breakfast Premium $" + BREAKFAST_PREMIUM, false); + JCheckBox golfBox = new JCheckBox("Golf Premium $" + GOLF_PREMIUM, false); + + JLabel resortLabel = new JLabel("Resort Price Calculator"); + JLabel priceLabel = new JLabel("The price for your stay is"); + + Font newFont = new Font("SansSerif", Font.BOLD, 20); + JTextField totPrice = new JTextField(4); + + JLabel optionExplainLabel = new JLabel("Base price for a room is $" + BASE_PRICE + "."); + JLabel optionExplainLabel2 = new JLabel("Check the options you want."); + + public AppletOne() { + super("Resort Price Estimator"); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setLayout(new GridLayout(8, 2)); + resortLabel.setForeground(Color.ORANGE); + optionExplainLabel.setForeground(Color.ORANGE); + optionExplainLabel2.setForeground(Color.ORANGE); + priceLabel.setForeground(Color.ORANGE); + totPrice.setFont(newFont); + add(resortLabel); + add(optionExplainLabel); + add(optionExplainLabel2); + add(weekendBox); + add(breakfastBox); + add(golfBox); + add(priceLabel); + add(totPrice); + + totPrice.setText("$" + totalPrice); + weekendBox.addItemListener(this); + breakfastBox.addItemListener(this); + golfBox.addItemListener(this); + } + + public static void main(String[] args) { + AppletOne j = new AppletOne(); + j.getContentPane().setBackground(Color.DARK_GRAY); + j.setBackground(Color.BLACK); + j.setVisible(true); + j.setSize(750, 650); + } + + public void itemStateChanged(ItemEvent event) { + Object source = event.getSource(); + int select = event.getStateChange(); + + if(source == weekendBox) { + if(select == ItemEvent.SELECTED) { + totalPrice += WEEKEND_PREMIUM; + } else { + totalPrice -= WEEKEND_PREMIUM; + } + } else if (source == breakfastBox) { + if (select == ItemEvent.SELECTED) { + totalPrice += BREAKFAST_PREMIUM; + } else { + totalPrice -= BREAKFAST_PREMIUM; + } + } else if (source == golfBox) { + if(select == ItemEvent.SELECTED) { + totalPrice += GOLF_PREMIUM; + } else { + totalPrice -= GOLF_PREMIUM; + } + } + + totPrice.setText("$" + totalPrice); + } +} diff --git a/cs-115-test/src/Calendar.java b/cs-115-test/src/Calendar.java new file mode 100644 index 0000000..2c4e759 --- /dev/null +++ b/cs-115-test/src/Calendar.java @@ -0,0 +1,8 @@ +public class Calendar implements Advance { + public static void main(String[] args) { + + } + public void advance(int increment) { + System.out.println("Advancing " + increment + " Day(s)"); + } +} diff --git a/cs-115-test/src/Clock.java b/cs-115-test/src/Clock.java new file mode 100644 index 0000000..1967482 --- /dev/null +++ b/cs-115-test/src/Clock.java @@ -0,0 +1,9 @@ +public class Clock implements Advance { + public static void main(String[] args) { + + } + + public void advance(int increment) { + System.out.println("Advancing " + increment + " Second(s)"); + } +} diff --git a/cs-115-test/src/ClockCalendar.java b/cs-115-test/src/ClockCalendar.java new file mode 100644 index 0000000..c2896a7 --- /dev/null +++ b/cs-115-test/src/ClockCalendar.java @@ -0,0 +1,2 @@ +public class ClockCalendar { +} diff --git a/cs-115-test/src/DialogExample.java b/cs-115-test/src/DialogExample.java new file mode 100644 index 0000000..373946a --- /dev/null +++ b/cs-115-test/src/DialogExample.java @@ -0,0 +1,34 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class DialogExample { + private static JDialog dialog; + + public DialogExample() { + JFrame frame = new JFrame(); + frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + + dialog = new JDialog(frame, "New Dialog Box", true); + dialog.setLayout(new FlowLayout()); + dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); + + JButton button = new JButton("OK"); + button.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + DialogExample.dialog.setVisible(false); + } + }); + + dialog.add(new JLabel("Click OK to Agree")); + dialog.add(button); + dialog.setSize(250, 250); + dialog.setVisible(true); + } + + public static void main(String[] args) { + new DialogExample(); + } +} diff --git a/cs-115-test/src/Editor.java b/cs-115-test/src/Editor.java new file mode 100644 index 0000000..3978399 --- /dev/null +++ b/cs-115-test/src/Editor.java @@ -0,0 +1,24 @@ +import javax.swing.*; + +public class Editor { + JFrame myFrame = null; + + public static void main(String[] args) { + (new Editor()).showPane(); + } + + private void showPane() { + myFrame = new JFrame("JEditorPane Test"); + myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + myFrame.setSize(500, 225); + + JEditorPane latinPane = new JEditorPane(); + latinPane.setContentType("text/html"); + latinPane.setText("

Latin Text!" + + "

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 showMe = b.getClass(); + System.out.println(showMe); + Class 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 labels = new Hashtable(); + labels.put(0, new JLabel("$10,000")); + labels.put(10, new JLabel("$20,000")); + labels.put(20, new JLabel("$30,000")); + labels.put(30, new JLabel("$40,000")); + + slider.setLabelTable(labels); + slider.setPaintLabels(true); + add(slider, BorderLayout.NORTH); + } + + public static void showFrame() { + JPanel panel = new Slider(); + JFrame frame = new JFrame("JSlider Car Price Picker"); + SpinnerModel value = new SpinnerNumberModel(25, 25, 100, 10); + JSpinner spinner = new JSpinner(value); + frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + frame.setContentPane(panel); + frame.pack(); + frame.add(spinner); + frame.setVisible(true); + } +} diff --git a/cs-115-test/src/SwingTree.java b/cs-115-test/src/SwingTree.java new file mode 100644 index 0000000..7731f54 --- /dev/null +++ b/cs-115-test/src/SwingTree.java @@ -0,0 +1,41 @@ +import javax.swing.*; +import javax.swing.tree.DefaultMutableTreeNode; + +public class SwingTree { + public SwingTree() { + JFrame frame = new JFrame(); + + DefaultMutableTreeNode style = new DefaultMutableTreeNode("Trees"); + DefaultMutableTreeNode deciduous = new DefaultMutableTreeNode("Deciduous"); + DefaultMutableTreeNode evergreen = new DefaultMutableTreeNode("Evergreen"); + + style.add(deciduous); + style.add(evergreen); + + DefaultMutableTreeNode maple = new DefaultMutableTreeNode("Maple"); + DefaultMutableTreeNode oak = new DefaultMutableTreeNode("Oak"); + DefaultMutableTreeNode linden = new DefaultMutableTreeNode("Linden"); + + deciduous.add(maple); + deciduous.add(oak); + deciduous.add(linden); + + DefaultMutableTreeNode pine = new DefaultMutableTreeNode("Pine"); + DefaultMutableTreeNode balsam = new DefaultMutableTreeNode("Balsam"); + DefaultMutableTreeNode spruce = new DefaultMutableTreeNode("Spruce"); + + evergreen.add(pine); + evergreen.add(balsam); + evergreen.add(spruce); + + JTree tree = new JTree(style); + frame.add(tree); + frame.setSize(1920, 1080); + frame.setVisible(true); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + } + + public static void main(String[] args) { + new SwingTree(); + } +} diff --git a/cs-115-test/src/Table.java b/cs-115-test/src/Table.java new file mode 100644 index 0000000..96fcff2 --- /dev/null +++ b/cs-115-test/src/Table.java @@ -0,0 +1,25 @@ +import javax.swing.*; + +public class Table { + public static void main(String[] args) { + JFrame frame = new JFrame("JTable Example"); + JPanel panel = new JPanel(); + String[][] data = { + {"1101", "Los Angeles", "6700"}, + {"1102", "Chicago", "830000"}, + {"1104", "New York", "92500"}, + }; + + String[] column = { "Person ID", "Location", "Balance" }; + JTable table = new JTable(data, column); + + JScrollPane pane = new JScrollPane(table); + + panel.add(pane); + frame.add(panel); + frame.add(table); + frame.setSize(300, 200); + frame.setVisible(true); + frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + } +}