diff --git a/Lesson18/.classpath b/Lesson18/.classpath index fb50116..11768b4 100644 --- a/Lesson18/.classpath +++ b/Lesson18/.classpath @@ -2,5 +2,6 @@ + diff --git a/Lesson18/resources/images/calculatoryellow.png b/Lesson18/resources/images/calculatoryellow.png new file mode 100644 index 0000000..dbd791b Binary files /dev/null and b/Lesson18/resources/images/calculatoryellow.png differ diff --git a/Lesson18/src/application/.classpath b/Lesson18/src/application/.classpath new file mode 100644 index 0000000..f8985c6 --- /dev/null +++ b/Lesson18/src/application/.classpath @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/Lesson26/.gitignore b/Lesson18/src/application/.gitignore similarity index 100% rename from Lesson26/.gitignore rename to Lesson18/src/application/.gitignore diff --git a/Lesson26/.project b/Lesson18/src/application/.project similarity index 97% rename from Lesson26/.project rename to Lesson18/src/application/.project index 7043bf7..8cbd6c3 100644 --- a/Lesson26/.project +++ b/Lesson18/src/application/.project @@ -1,6 +1,6 @@ - Lesson26 + Lesson30 diff --git a/Lesson26/.settings/.jsdtscope b/Lesson18/src/application/.settings/.jsdtscope similarity index 100% rename from Lesson26/.settings/.jsdtscope rename to Lesson18/src/application/.settings/.jsdtscope diff --git a/Lesson26/.settings/org.eclipse.jdt.core.prefs b/Lesson18/src/application/.settings/org.eclipse.jdt.core.prefs similarity index 100% rename from Lesson26/.settings/org.eclipse.jdt.core.prefs rename to Lesson18/src/application/.settings/org.eclipse.jdt.core.prefs diff --git a/Lesson26/.settings/org.eclipse.wst.common.component b/Lesson18/src/application/.settings/org.eclipse.wst.common.component similarity index 65% rename from Lesson26/.settings/org.eclipse.wst.common.component rename to Lesson18/src/application/.settings/org.eclipse.wst.common.component index 084c5f3..e0bd65a 100644 --- a/Lesson26/.settings/org.eclipse.wst.common.component +++ b/Lesson18/src/application/.settings/org.eclipse.wst.common.component @@ -1,8 +1,8 @@ - + - - + + diff --git a/Lesson18/src/application/.settings/org.eclipse.wst.common.project.facet.core.xml b/Lesson18/src/application/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..0dfc63c --- /dev/null +++ b/Lesson18/src/application/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/Lesson26/.settings/org.eclipse.wst.jsdt.ui.superType.container b/Lesson18/src/application/.settings/org.eclipse.wst.jsdt.ui.superType.container similarity index 100% rename from Lesson26/.settings/org.eclipse.wst.jsdt.ui.superType.container rename to Lesson18/src/application/.settings/org.eclipse.wst.jsdt.ui.superType.container diff --git a/Lesson26/.settings/org.eclipse.wst.jsdt.ui.superType.name b/Lesson18/src/application/.settings/org.eclipse.wst.jsdt.ui.superType.name similarity index 100% rename from Lesson26/.settings/org.eclipse.wst.jsdt.ui.superType.name rename to Lesson18/src/application/.settings/org.eclipse.wst.jsdt.ui.superType.name diff --git a/Lesson18/src/application/CalculatorEngine.java b/Lesson18/src/application/CalculatorEngine.java new file mode 100644 index 0000000..21a6f9f --- /dev/null +++ b/Lesson18/src/application/CalculatorEngine.java @@ -0,0 +1,8 @@ +package application; + +import javafx.event.ActionEvent; + +@FunctionalInterface +public interface CalculatorEngine { + void processEvent(ActionEvent e, CalculatorPane parent); +} diff --git a/Lesson18/src/application/CalculatorPane.java b/Lesson18/src/application/CalculatorPane.java new file mode 100644 index 0000000..937cc37 --- /dev/null +++ b/Lesson18/src/application/CalculatorPane.java @@ -0,0 +1,204 @@ +package application; + +import javafx.scene.control.Button; +import javafx.scene.control.TextField; +import javafx.scene.layout.StackPane; + +public abstract class CalculatorPane extends StackPane{ + + private String firstNumber; + private String operator; // selected action + private double result; + private String previouslyPressedButton = ""; + + public void handle(CalculatorEngine engine) { + button0.setOnAction((e) -> + engine.processEvent(e,this)); + button1.setOnAction((e) -> + engine.processEvent(e,this)); + button2.setOnAction((e) -> + engine.processEvent(e,this)); + button3.setOnAction((e) -> + engine.processEvent(e,this)); + button4.setOnAction((e) -> + engine.processEvent(e,this)); + button5.setOnAction((e) -> + engine.processEvent(e,this)); + button6.setOnAction((e) -> + engine.processEvent(e,this)); + button7.setOnAction((e) -> + engine.processEvent(e,this)); + button8.setOnAction((e) -> + engine.processEvent(e,this)); + button9.setOnAction((e) -> + engine.processEvent(e,this)); + + buttonPoint.setOnAction((e) -> + engine.processEvent(e,this)); + buttonEqual.setOnAction((e) -> + engine.processEvent(e,this)); + buttonPlus.setOnAction((e) -> + engine.processEvent(e,this)); + buttonMinus.setOnAction((e) -> + engine.processEvent(e,this)); + buttonMult.setOnAction((e) -> + engine.processEvent(e,this)); + buttonDiv.setOnAction((e) -> + engine.processEvent(e,this)); + + buttonSQRT.setOnAction((e) -> + engine.processEvent(e,this)); + buttonMOD.setOnAction((e) -> + engine.processEvent(e,this)); + buttonINV.setOnAction((e) -> + engine.processEvent(e,this)); + buttonOPP.setOnAction((e) -> + engine.processEvent(e,this)); + + buttonBackspace.setOnAction((e) -> + engine.processEvent(e,this)); + buttonCE.setOnAction((e) -> + engine.processEvent(e,this)); + buttonC.setOnAction((e) -> + engine.processEvent(e,this)); + + buttonMC.setOnAction((e) -> + engine.processEvent(e,this)); + buttonMR.setOnAction((e) -> + engine.processEvent(e,this)); + buttonMS.setOnAction((e) -> + engine.processEvent(e,this)); + buttonMPlus.setOnAction((e) -> + engine.processEvent(e,this)); + } + + // Declare all calculator's components. + protected TextField displayField; + + protected Button button0; + protected Button button1; + protected Button button2; + protected Button button3; + protected Button button4; + protected Button button5; + protected Button button6; + protected Button button7; + protected Button button8; + protected Button button9; + protected Button buttonPoint; + protected Button buttonEqual; + protected Button buttonPlus; + protected Button buttonMinus; + protected Button buttonMult; + protected Button buttonDiv; + + protected Button buttonSQRT; + protected Button buttonMOD; + protected Button buttonINV; + protected Button buttonOPP; + + protected Button buttonBackspace; + protected Button buttonCE; + protected Button buttonC; + + protected Button buttonMC; + protected Button buttonMR; + protected Button buttonMS; + protected Button buttonMPlus; + + // Constructor + public CalculatorPane(){ + super(); + String backgroundStyle = "-fx-background-color: lightblue;" + + "-fx-background-radius: 30%;" + + "-fx-background-inset: 5px;"; + super.setStyle(backgroundStyle); + setStyle(backgroundStyle); + } + + // Define getter and setters + + public String getDisplayValue() { + return displayField.getText(); + } + + public void setDisplayValue(String val){ + String textColor = " -fx-text-fill: black"; + displayField.setStyle(textColor); + displayField.setText(val); + } + + public void setDisplayValue(String val, String color){ + String textColor = " -fx-text-fill: " + color; + displayField.setStyle(textColor); + displayField.setText(val); + } + + public String getFirstNumber() { + return firstNumber; + } + + public void setFirstNumber(String firstNumber) { + this.firstNumber = firstNumber; + } + + public String getOperator() { + return operator; + } + + public void setOperator(String operator) { + this.operator = operator; + } + + public double getResult() { + return result; + } + + public void setResult(double result) { + this.result = result; + } + + public String getPreviouslyPressedButton() { + return previouslyPressedButton; + } + + public void setPreviouslyPressedButton(String previouslyPressedButton) { + this.previouslyPressedButton = previouslyPressedButton; + } + + protected void setButtonStyles(String style){ + button0.setId(style); + button1.setId(style); + button2.setId(style); + button3.setId(style); + button4.setId(style); + button5.setId(style); + button6.setId(style); + button7.setId(style); + button8.setId(style); + button9.setId(style); + + buttonPoint.setId(style); + buttonEqual.setId(style); + buttonPlus.setId(style); + buttonMinus.setId(style); + buttonMult.setId(style); + buttonDiv.setId(style); + + buttonSQRT.setId(style); + buttonMOD.setId(style); + buttonINV.setId(style); + buttonOPP.setId(style); + + buttonBackspace.setId(style); + buttonCE.setId(style); + buttonC.setId(style); + + buttonMC.setId(style); + buttonMR.setId(style); + buttonMS.setId(style); + buttonMPlus.setId(style); + + } + +} diff --git a/Lesson18/src/application/FancyCalculatorPane.java b/Lesson18/src/application/FancyCalculatorPane.java new file mode 100644 index 0000000..dcd6190 --- /dev/null +++ b/Lesson18/src/application/FancyCalculatorPane.java @@ -0,0 +1,24 @@ +package application; + +public class FancyCalculatorPane extends StandardCalculatorPane { + + public FancyCalculatorPane(){ + super(); +/* + setStyle( " -fx-background-color: grey; " + + "-fx-text-fill: white;" + + "-fx-font-family: \"Times New Roman\";" + + "-fx-font-size: 18px;"); +*/ + setStyle( "-fx-border-radius: 30;"+ + "-fx-border-width:5;"+ + "-fx-border-color:blue;"); + + // Set button styles + + setButtonStyles("chocolat"); + + + } + +} diff --git a/Lesson18/src/application/Main.java b/Lesson18/src/application/Main.java index 18e8cc3..9917004 100644 --- a/Lesson18/src/application/Main.java +++ b/Lesson18/src/application/Main.java @@ -1,6 +1,305 @@ package application; import javafx.application.Application; +<<<<<<< HEAD +import javafx.event.ActionEvent; +import javafx.event.EventHandler; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.control.Menu; +import javafx.scene.control.MenuBar; +import javafx.scene.control.RadioMenuItem; +import javafx.scene.image.Image; +import javafx.scene.layout.GridPane; +import javafx.scene.paint.Color; +import javafx.stage.Stage; +import javafx.stage.StageStyle; + +public class Main extends Application { + + private static SimpleCalculatorPane simpleCalculatorPane = new SimpleCalculatorPane(); + private static StandardCalculatorPane standardCalculatorPane = new StandardCalculatorPane(); + private static FancyCalculatorPane fancyCalculatorPane = new FancyCalculatorPane(); + + public static void main(String[] args) { + + // Define the calculator engine as a lambda expression and store it in a variable + CalculatorEngine calculatorEngine = (ActionEvent e, + CalculatorPane parent) -> { + + // Get the source of this action + Button clickedButton = (Button) e.getSource(); + + switch(clickedButton.getText()){ + case "1": + case "2": + case "3": + case "4": + case "5": + case "6": + case "7": + case "8": + case "9": + case "0": + case ".": + parent.setPreviouslyPressedButton(clickedButton.getText()); + // displayDigit(clickedButton); + // Get the existing text from the Calculator's display field + String dispFieldText = parent.getDisplayValue(); + // Get the button's label + String clickedButtonLabel = clickedButton.getText(); + parent.setDisplayValue(dispFieldText + clickedButtonLabel); + break; + case "+": + case "-": + case "/": + case "*": + case "%": + // Store the first number and the operator in corresponding variables + parent.setFirstNumber(parent.getDisplayValue()); + parent.setOperator(clickedButton.getText()); + parent.setPreviouslyPressedButton(parent.getOperator()); + // Erase the number from the display + parent.setDisplayValue(""); + break; + case "=": + + // do nothing if previously pressed button was the equal sign, + // a unary operator or dot + if ("=".equals(parent.getPreviouslyPressedButton()) || + "sqrt".equals(parent.getPreviouslyPressedButton()) || + "+/-".equals(parent.getPreviouslyPressedButton()) || + "1/x".equals(parent.getPreviouslyPressedButton()) || + "C".equals(parent.getPreviouslyPressedButton()) || + "Backspace".equals(parent.getPreviouslyPressedButton()) || + ".".equals(parent.getPreviouslyPressedButton())) break; + + try{ + // Perform the selected action + if ("+".equals(parent.getOperator())) { + parent.setResult(Double.parseDouble(parent.getDisplayValue()) + Double.parseDouble(parent.getFirstNumber())); + } + if ("-".equals(parent.getOperator())) { + parent.setResult(Double.parseDouble(parent.getFirstNumber()) - Double.parseDouble(parent.getDisplayValue())); + } + if ("*".equals(parent.getOperator())) { + parent.setResult(Double.parseDouble(parent.getFirstNumber()) * Double.parseDouble(parent.getDisplayValue())); + } + if ("/".equals(parent.getOperator())) { + //validate input + if (Double.parseDouble(parent.getDisplayValue()) == 0){ + // Display error message in red if user attempts to divide by zero + parent.setDisplayValue("You cannot divide by zero!", "red"); + break; + } + else + parent.setResult(Double.parseDouble(parent.getFirstNumber()) / Double.parseDouble(parent.getDisplayValue())); + } + if ("%".equals(parent.getOperator())) { + parent.setResult(Double.parseDouble(parent.getFirstNumber()) % Double.parseDouble(parent.getDisplayValue())); + } + } + catch(NumberFormatException exception){ + parent.setDisplayValue("Operand is not a number!", "red"); + break; + } + + // Store the result in firstNumber + parent.setFirstNumber(String.valueOf(parent.getResult())); + // Display the result + parent.setDisplayValue(parent.getFirstNumber()); + parent.setPreviouslyPressedButton("="); + break; + + case "C": + // erase the number or message from the display + parent.setDisplayValue(""); + parent.setPreviouslyPressedButton(clickedButton.getText()); + break; + + case "sqrt": + //store result in firstNumber + parent.setFirstNumber(String.valueOf(Math.sqrt(Double.parseDouble(parent.getDisplayValue())))); + //display the result + parent.setDisplayValue(parent.getFirstNumber()); + parent.setPreviouslyPressedButton(clickedButton.getText()); + break; + + case "1/x": + if (Double.parseDouble(parent.getDisplayValue()) == 0){ + // Display error message in red if user attempts to divide by zero + parent.setDisplayValue("You cannot divide by zero!", "red"); + parent.setPreviouslyPressedButton(clickedButton.getText()); + break; + } + else{ + //store result in firstNumber + parent.setFirstNumber(String.valueOf(1/(Double.parseDouble(parent.getDisplayValue())))); + //display the result + parent.setDisplayValue(parent.getFirstNumber()); + } + parent.setPreviouslyPressedButton(clickedButton.getText()); + break; + + case "+/-": + //store result in firstNumber + parent.setFirstNumber(String.valueOf(0.0-(Double.parseDouble(parent.getDisplayValue())))); + //display the result + parent.setDisplayValue(parent.getFirstNumber()); + parent.setPreviouslyPressedButton(clickedButton.getText()); + break; + + case "Backspace": + if((parent.getDisplayValue().length()) != 0) { + parent.setDisplayValue(parent.getDisplayValue().substring(0,parent.getDisplayValue().length()-1)); + } + parent.setPreviouslyPressedButton(clickedButton.getText()); + break; + + default: + parent.setDisplayValue("Undefined action"); + + } + }; + + + // set handler code for calculator components + fancyCalculatorPane.handle(calculatorEngine); + simpleCalculatorPane.handle(calculatorEngine); + standardCalculatorPane.handle(calculatorEngine); + + launch(args); + } + + @Override + public void start(Stage primaryStage) throws Exception { + primaryStage.setTitle("Calculator"); + // Window is not maximizable + //primaryStage.setResizable(false); + primaryStage.initStyle(StageStyle.TRANSPARENT); + //primaryStage.initModality(Modality.NONE); + // Set the application icon + primaryStage.getIcons().add(new Image("file:resources/images/calculatoryellow.png")); + + // Create the menu bar + MenuBar menuBar = new MenuBar(); + Menu viewMenu = new Menu("View"); + RadioMenuItem simpleCalculatorMenuItem = new RadioMenuItem("Simple"); + RadioMenuItem standardCalculatorMenuItem = new RadioMenuItem("Standard"); + RadioMenuItem fancyCalculatorMenuItem = new RadioMenuItem("Fancy"); + // Set fancy calculator as default view + fancyCalculatorMenuItem.setSelected(true); + viewMenu.getItems().addAll(simpleCalculatorMenuItem, + standardCalculatorMenuItem, + fancyCalculatorMenuItem); + + menuBar.getMenus().add(viewMenu); + + // Create a GridPane as the root layout node + GridPane window = new GridPane(); + // Create the scene and set its style + Scene scene = new Scene(window, 500, 350, Color.GREY); + scene.getStylesheets() + .add(getClass().getResource("calculator.css") + .toExternalForm()); + + // Add the menu bar to the window + window.add(menuBar, 0, 0); + + // At the beginning add to the window a fancy calculator pane + + window.add(fancyCalculatorPane, 0, 1); + + // Set the scene and display the window + primaryStage.setScene(scene); + primaryStage.show(); + + // Handler code for menu items + standardCalculatorMenuItem.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent t) { + // if selected, add + if (standardCalculatorMenuItem.isSelected() && + (window.getChildren().contains(simpleCalculatorPane))){ + simpleCalculatorMenuItem.setSelected(false); + window.getChildren().remove(simpleCalculatorPane); + window.add(standardCalculatorPane, 0, 1); + } + if (standardCalculatorMenuItem.isSelected() && + (window.getChildren().contains(fancyCalculatorPane))){ + fancyCalculatorMenuItem.setSelected(false); + window.getChildren().remove(fancyCalculatorPane); + window.add(standardCalculatorPane, 0, 1); + } + // if unselected, remove + if (!standardCalculatorMenuItem.isSelected()){ + if (window.getChildren().contains(standardCalculatorPane)){ + window.getChildren().remove(standardCalculatorPane); + } + window.add(simpleCalculatorPane, 0, 1); + simpleCalculatorMenuItem.setSelected(true); + } + } + }); + + simpleCalculatorMenuItem.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent t) { + // if selected, add + if (simpleCalculatorMenuItem.isSelected() && + (window.getChildren().contains(standardCalculatorPane))){ + standardCalculatorMenuItem.setSelected(false); + window.getChildren().remove(standardCalculatorPane); + window.add(simpleCalculatorPane, 0, 1); + } + if (simpleCalculatorMenuItem.isSelected() && + (window.getChildren().contains(fancyCalculatorPane))){ + fancyCalculatorMenuItem.setSelected(false); + window.getChildren().remove(fancyCalculatorPane); + window.add(simpleCalculatorPane, 0, 1); + } + // if unselected, remove + if (!simpleCalculatorMenuItem.isSelected()){ + if (window.getChildren().contains(simpleCalculatorPane)){ + window.getChildren().remove(simpleCalculatorPane); + } + window.add(standardCalculatorPane, 0, 1); + standardCalculatorMenuItem.setSelected(true); + } + } + }); + + //Handler code for fancyCalculatorMenuItem, using lambda expression + + fancyCalculatorMenuItem.setOnAction(t -> { + // if selected, add + if (fancyCalculatorMenuItem.isSelected() && + (window.getChildren().contains(standardCalculatorPane))){ + standardCalculatorMenuItem.setSelected(false); + window.getChildren().remove(standardCalculatorPane); + window.add(fancyCalculatorPane, 0, 1); + } + if (fancyCalculatorMenuItem.isSelected() && + (window.getChildren().contains(simpleCalculatorPane))){ + simpleCalculatorMenuItem.setSelected(false); + window.getChildren().remove(simpleCalculatorPane); + window.add(fancyCalculatorPane, 0, 1); + } + // if unselected, remove + if (!fancyCalculatorMenuItem.isSelected()){ + if (window.getChildren().contains(fancyCalculatorPane)){ + window.getChildren().remove(fancyCalculatorPane); + } + window.add(standardCalculatorPane, 0, 1); + standardCalculatorMenuItem.setSelected(true); + } + }); + + } + +} + +======= import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.layout.BorderPane; @@ -25,3 +324,4 @@ public static void main(String[] args) { launch(args); } } +>>>>>>> upstream/master diff --git a/Lesson18/src/application/MainCristina.java b/Lesson18/src/application/MainCristina.java new file mode 100644 index 0000000..c17ed00 --- /dev/null +++ b/Lesson18/src/application/MainCristina.java @@ -0,0 +1,300 @@ +package application; + +import javafx.application.Application; +import javafx.event.ActionEvent; +import javafx.event.EventHandler; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.control.Menu; +import javafx.scene.control.MenuBar; +import javafx.scene.control.RadioMenuItem; +import javafx.scene.image.Image; +import javafx.scene.layout.GridPane; +import javafx.scene.paint.Color; +import javafx.stage.Stage; +import javafx.stage.StageStyle; + +public class Main extends Application { + + private static SimpleCalculatorPane simpleCalculatorPane = new SimpleCalculatorPane(); + private static StandardCalculatorPane standardCalculatorPane = new StandardCalculatorPane(); + private static FancyCalculatorPane fancyCalculatorPane = new FancyCalculatorPane(); + + public static void main(String[] args) { + + // Define the calculator engine as a lambda expression and store it in a variable + CalculatorEngine calculatorEngine = (ActionEvent e, + CalculatorPane parent) -> { + + // Get the source of this action + Button clickedButton = (Button) e.getSource(); + + switch(clickedButton.getText()){ + case "1": + case "2": + case "3": + case "4": + case "5": + case "6": + case "7": + case "8": + case "9": + case "0": + case ".": + parent.setPreviouslyPressedButton(clickedButton.getText()); + // displayDigit(clickedButton); + // Get the existing text from the Calculator's display field + String dispFieldText = parent.getDisplayValue(); + // Get the button's label + String clickedButtonLabel = clickedButton.getText(); + parent.setDisplayValue(dispFieldText + clickedButtonLabel); + break; + case "+": + case "-": + case "/": + case "*": + case "%": + // Store the first number and the operator in corresponding variables + parent.setFirstNumber(parent.getDisplayValue()); + parent.setOperator(clickedButton.getText()); + parent.setPreviouslyPressedButton(parent.getOperator()); + // Erase the number from the display + parent.setDisplayValue(""); + break; + case "=": + + // do nothing if previously pressed button was the equal sign, + // a unary operator or dot + if ("=".equals(parent.getPreviouslyPressedButton()) || + "sqrt".equals(parent.getPreviouslyPressedButton()) || + "+/-".equals(parent.getPreviouslyPressedButton()) || + "1/x".equals(parent.getPreviouslyPressedButton()) || + "C".equals(parent.getPreviouslyPressedButton()) || + "Backspace".equals(parent.getPreviouslyPressedButton()) || + ".".equals(parent.getPreviouslyPressedButton())) break; + + try{ + // Perform the selected action + if ("+".equals(parent.getOperator())) { + parent.setResult(Double.parseDouble(parent.getDisplayValue()) + Double.parseDouble(parent.getFirstNumber())); + } + if ("-".equals(parent.getOperator())) { + parent.setResult(Double.parseDouble(parent.getFirstNumber()) - Double.parseDouble(parent.getDisplayValue())); + } + if ("*".equals(parent.getOperator())) { + parent.setResult(Double.parseDouble(parent.getFirstNumber()) * Double.parseDouble(parent.getDisplayValue())); + } + if ("/".equals(parent.getOperator())) { + //validate input + if (Double.parseDouble(parent.getDisplayValue()) == 0){ + // Display error message in red if user attempts to divide by zero + parent.setDisplayValue("You cannot divide by zero!", "red"); + break; + } + else + parent.setResult(Double.parseDouble(parent.getFirstNumber()) / Double.parseDouble(parent.getDisplayValue())); + } + if ("%".equals(parent.getOperator())) { + parent.setResult(Double.parseDouble(parent.getFirstNumber()) % Double.parseDouble(parent.getDisplayValue())); + } + } + catch(NumberFormatException exception){ + parent.setDisplayValue("Operand is not a number!", "red"); + break; + } + + // Store the result in firstNumber + parent.setFirstNumber(String.valueOf(parent.getResult())); + // Display the result + parent.setDisplayValue(parent.getFirstNumber()); + parent.setPreviouslyPressedButton("="); + break; + + case "C": + // erase the number or message from the display + parent.setDisplayValue(""); + parent.setPreviouslyPressedButton(clickedButton.getText()); + break; + + case "sqrt": + //store result in firstNumber + parent.setFirstNumber(String.valueOf(Math.sqrt(Double.parseDouble(parent.getDisplayValue())))); + //display the result + parent.setDisplayValue(parent.getFirstNumber()); + parent.setPreviouslyPressedButton(clickedButton.getText()); + break; + + case "1/x": + if (Double.parseDouble(parent.getDisplayValue()) == 0){ + // Display error message in red if user attempts to divide by zero + parent.setDisplayValue("You cannot divide by zero!", "red"); + parent.setPreviouslyPressedButton(clickedButton.getText()); + break; + } + else{ + //store result in firstNumber + parent.setFirstNumber(String.valueOf(1/(Double.parseDouble(parent.getDisplayValue())))); + //display the result + parent.setDisplayValue(parent.getFirstNumber()); + } + parent.setPreviouslyPressedButton(clickedButton.getText()); + break; + + case "+/-": + //store result in firstNumber + parent.setFirstNumber(String.valueOf(0.0-(Double.parseDouble(parent.getDisplayValue())))); + //display the result + parent.setDisplayValue(parent.getFirstNumber()); + parent.setPreviouslyPressedButton(clickedButton.getText()); + break; + + case "Backspace": + if((parent.getDisplayValue().length()) != 0) { + parent.setDisplayValue(parent.getDisplayValue().substring(0,parent.getDisplayValue().length()-1)); + } + parent.setPreviouslyPressedButton(clickedButton.getText()); + break; + + default: + parent.setDisplayValue("Undefined action"); + + } + }; + + + // set handler code for calculator components + fancyCalculatorPane.handle(calculatorEngine); + simpleCalculatorPane.handle(calculatorEngine); + standardCalculatorPane.handle(calculatorEngine); + + launch(args); + } + + @Override + public void start(Stage primaryStage) throws Exception { + primaryStage.setTitle("Calculator"); + // Window is not maximizable + //primaryStage.setResizable(false); + primaryStage.initStyle(StageStyle.TRANSPARENT); + //primaryStage.initModality(Modality.NONE); + // Set the application icon + primaryStage.getIcons().add(new Image("file:resources/images/calculatoryellow.png")); + + // Create the menu bar + MenuBar menuBar = new MenuBar(); + Menu viewMenu = new Menu("View"); + RadioMenuItem simpleCalculatorMenuItem = new RadioMenuItem("Simple"); + RadioMenuItem standardCalculatorMenuItem = new RadioMenuItem("Standard"); + RadioMenuItem fancyCalculatorMenuItem = new RadioMenuItem("Fancy"); + // Set fancy calculator as default view + fancyCalculatorMenuItem.setSelected(true); + viewMenu.getItems().addAll(simpleCalculatorMenuItem, + standardCalculatorMenuItem, + fancyCalculatorMenuItem); + + menuBar.getMenus().add(viewMenu); + + // Create a GridPane as the root layout node + GridPane window = new GridPane(); + // Create the scene and set its style + Scene scene = new Scene(window, 500, 350, Color.TRANSPARENT); + scene.getStylesheets() + .add(getClass().getResource("calculator.css") + .toExternalForm()); + + // Add the menu bar to the window + window.add(menuBar, 0, 0); + + // At the beginning add to the window a fancy calculator pane + + window.add(fancyCalculatorPane, 0, 1); + + // Set the scene and display the window + primaryStage.setScene(scene); + primaryStage.show(); + + // Handler code for menu items + standardCalculatorMenuItem.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent t) { + // if selected, add + if (standardCalculatorMenuItem.isSelected() && + (window.getChildren().contains(simpleCalculatorPane))){ + simpleCalculatorMenuItem.setSelected(false); + window.getChildren().remove(simpleCalculatorPane); + window.add(standardCalculatorPane, 0, 1); + } + if (standardCalculatorMenuItem.isSelected() && + (window.getChildren().contains(fancyCalculatorPane))){ + fancyCalculatorMenuItem.setSelected(false); + window.getChildren().remove(fancyCalculatorPane); + window.add(standardCalculatorPane, 0, 1); + } + // if unselected, remove + if (!standardCalculatorMenuItem.isSelected()){ + if (window.getChildren().contains(standardCalculatorPane)){ + window.getChildren().remove(standardCalculatorPane); + } + window.add(simpleCalculatorPane, 0, 1); + simpleCalculatorMenuItem.setSelected(true); + } + } + }); + + simpleCalculatorMenuItem.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent t) { + // if selected, add + if (simpleCalculatorMenuItem.isSelected() && + (window.getChildren().contains(standardCalculatorPane))){ + standardCalculatorMenuItem.setSelected(false); + window.getChildren().remove(standardCalculatorPane); + window.add(simpleCalculatorPane, 0, 1); + } + if (simpleCalculatorMenuItem.isSelected() && + (window.getChildren().contains(fancyCalculatorPane))){ + fancyCalculatorMenuItem.setSelected(false); + window.getChildren().remove(fancyCalculatorPane); + window.add(simpleCalculatorPane, 0, 1); + } + // if unselected, remove + if (!simpleCalculatorMenuItem.isSelected()){ + if (window.getChildren().contains(simpleCalculatorPane)){ + window.getChildren().remove(simpleCalculatorPane); + } + window.add(standardCalculatorPane, 0, 1); + standardCalculatorMenuItem.setSelected(true); + } + } + }); + + //Handler code for fancyCalculatorMenuItem, using lambda expression + + fancyCalculatorMenuItem.setOnAction(t -> { + // if selected, add + if (fancyCalculatorMenuItem.isSelected() && + (window.getChildren().contains(standardCalculatorPane))){ + standardCalculatorMenuItem.setSelected(false); + window.getChildren().remove(standardCalculatorPane); + window.add(fancyCalculatorPane, 0, 1); + } + if (fancyCalculatorMenuItem.isSelected() && + (window.getChildren().contains(simpleCalculatorPane))){ + simpleCalculatorMenuItem.setSelected(false); + window.getChildren().remove(simpleCalculatorPane); + window.add(fancyCalculatorPane, 0, 1); + } + // if unselected, remove + if (!fancyCalculatorMenuItem.isSelected()){ + if (window.getChildren().contains(fancyCalculatorPane)){ + window.getChildren().remove(fancyCalculatorPane); + } + window.add(standardCalculatorPane, 0, 1); + standardCalculatorMenuItem.setSelected(true); + } + }); + + } + +} + diff --git a/Lesson18/src/application/SimpleCalculatorPane.java b/Lesson18/src/application/SimpleCalculatorPane.java new file mode 100644 index 0000000..b7d1b2b --- /dev/null +++ b/Lesson18/src/application/SimpleCalculatorPane.java @@ -0,0 +1,122 @@ +package application; + +import javafx.geometry.Insets; +import javafx.geometry.Pos; +import javafx.scene.control.Button; +import javafx.scene.control.TextField; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.VBox; + +public class SimpleCalculatorPane extends CalculatorPane{ + + public SimpleCalculatorPane(){ + super(); + + // Create a GridPane as the root layout node + GridPane window = new GridPane(); + window.setPadding(new Insets(5)); + window.setHgap(5); + window.setVgap(5); + + // Create a BorderPane for the calculator + BorderPane windowContent = new BorderPane(); + + // Create the display field and place it at the Top area of the window + displayField = new TextField(); + displayField.setAlignment(Pos.BASELINE_RIGHT); + windowContent.setTop(displayField); + + // Create the components + button0 = new Button("0"); + button1 = new Button("1"); + button2 = new Button("2"); + button3 = new Button("3"); + button4 = new Button("4"); + button5 = new Button("5"); + button6 = new Button("6"); + button7 = new Button("7"); + button8 = new Button("8"); + button9 = new Button("9"); + buttonPoint = new Button("."); + buttonEqual = new Button("="); + + buttonPlus = new Button("+"); + buttonMinus = new Button("-"); + buttonMult = new Button("*"); + buttonDiv = new Button("/"); + + buttonSQRT = new Button("sqrt"); + buttonMOD = new Button("%"); + buttonINV = new Button("1/x"); + buttonOPP = new Button("+/-"); + + buttonBackspace = new Button("Backspace"); + buttonCE = new Button("CE"); + buttonC = new Button("C"); + + buttonMC = new Button("MC"); + buttonMR = new Button("MR"); + buttonMS = new Button("MS"); + buttonMPlus = new Button("M+"); + + // Set a large preferred size of the buttons, so that they fill the whole space + //in their container + button0.setPrefSize(800, 800); + button1.setPrefSize(800, 800); + button2.setPrefSize(800, 800); + button3.setPrefSize(800, 800); + button4.setPrefSize(800, 800); + button5.setPrefSize(800, 800); + button6.setPrefSize(800, 800); + button7.setPrefSize(800, 800); + button8.setPrefSize(800, 800); + button9.setPrefSize(800, 800); + buttonPoint.setPrefSize(800, 800); + buttonEqual.setPrefSize(800, 800); + + buttonPlus.setPrefSize(80, 800); + buttonMinus.setPrefSize(80, 800); + buttonMult.setPrefSize(80, 800); + buttonDiv.setPrefSize(80, 800); + + // Create a GridPane node to hold 12 buttons – + //10 numeric ones, period, and the equal sign + GridPane gridPane = new GridPane(); + + // Add buttons to the gridPane + gridPane.add(button0,0,0); + gridPane.add(button1,1,0); + gridPane.add(button2,2,0); + gridPane.add(button3,0,1); + gridPane.add(button4,1,1); + gridPane.add(button5,2,1); + gridPane.add(button6,0,2); + gridPane.add(button7,1,2); + gridPane.add(button8,2,2); + gridPane.add(button9,0,3); + gridPane.add(buttonPoint,1,3); + gridPane.add(buttonEqual,2,3); + + // Create a VBox and add Plus, Minus, Mult, Div buttons to it + VBox operations = new VBox(); + operations.getChildren().add(buttonPlus); + operations.getChildren().add(buttonMinus); + operations.getChildren().add(buttonMult); + operations.getChildren().add(buttonDiv); + + // Place the gridPane with buttons at the Center of the window(BorderPane) + windowContent.setCenter(gridPane); + + // Place the VBox with operation buttons (Plus, Minus, Div, Mult) + //at the Right area of the border pane + windowContent.setRight(operations); + + window.add(windowContent, 0, 1); + + getChildren().add(window); + + } + +} + diff --git a/Lesson18/src/application/StandardCalculatorPane.java b/Lesson18/src/application/StandardCalculatorPane.java new file mode 100644 index 0000000..abce1ea --- /dev/null +++ b/Lesson18/src/application/StandardCalculatorPane.java @@ -0,0 +1,180 @@ +package application; + +import javafx.geometry.HPos; +import javafx.geometry.Insets; +import javafx.geometry.Pos; +import javafx.geometry.VPos; +import javafx.scene.control.Button; +import javafx.scene.control.TextField; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.Priority; + +public class StandardCalculatorPane extends CalculatorPane{ + + private final double BUTTON_PREF_WIDTH = 800; + private final double BUTTON_PREF_HEIGHT = 800; + + public StandardCalculatorPane(){ + super(); + + // Create a GridPane as the root layout node + GridPane windowContent = new GridPane(); + windowContent.setPadding(new Insets(5)); + windowContent.setHgap(5); + windowContent.setVgap(5); + + String backgroundStyle = "-fx-background-color: lightblue;" + + "-fx-background-radius: 30%;" + + "-fx-background-inset: 5px;"; + windowContent.setStyle(backgroundStyle); + + // Create the display field and set the corresponding constraints + displayField = new TextField(); + displayField.setAlignment(Pos.BASELINE_RIGHT);; + GridPane.setColumnSpan(displayField, 6); // this cell is as wide as 6 other ones + GridPane.setRowSpan(displayField, 1); // this cell has the same height as other cells + GridPane.setFillHeight(displayField, true); + GridPane.setFillWidth(displayField, true); // fill all space in the cell + GridPane.setHalignment(displayField, HPos.CENTER); + GridPane.setValignment(displayField, VPos.CENTER); // position within the cell + GridPane.setHgrow(displayField, Priority.ALWAYS); + GridPane.setVgrow(displayField, Priority.ALWAYS); // grow larger than the preferred size if there is space + + // Add the display field to the window + windowContent.add(displayField, 0, 1); + + // Create the buttons + button0 = new Button("0"); + button1 = new Button("1"); + button2 =new Button("2"); + button3 = new Button("3"); + button4 = new Button("4"); + button5 = new Button("5"); + button6 = new Button("6"); + button7 = new Button("7"); + button8 = new Button("8"); + button9 = new Button("9"); + buttonPoint = new Button("."); + buttonEqual = new Button("="); + + buttonPlus = new Button("+"); + buttonMinus = new Button("-"); + buttonMult = new Button("*"); + buttonDiv = new Button("/"); + + buttonSQRT = new Button("sqrt"); + buttonMOD = new Button("%"); + buttonINV = new Button("1/x"); + buttonOPP = new Button("+/-"); + + buttonBackspace = new Button("Backspace"); + buttonCE = new Button("CE"); + buttonC = new Button("C"); + + buttonMC = new Button("MC"); + buttonMR = new Button("MR"); + buttonMS = new Button("MS"); + buttonMPlus = new Button("M+"); + + // Set a large preferred size of the buttons, + // so that they fill the whole space + // in their container + button0.setPrefSize(BUTTON_PREF_WIDTH, BUTTON_PREF_HEIGHT); + button1.setPrefSize(BUTTON_PREF_WIDTH, BUTTON_PREF_HEIGHT); + button2.setPrefSize(BUTTON_PREF_WIDTH, BUTTON_PREF_HEIGHT); + button3.setPrefSize(BUTTON_PREF_WIDTH, BUTTON_PREF_HEIGHT); + button4.setPrefSize(BUTTON_PREF_WIDTH, BUTTON_PREF_HEIGHT); + button5.setPrefSize(BUTTON_PREF_WIDTH, BUTTON_PREF_HEIGHT); + button6.setPrefSize(BUTTON_PREF_WIDTH, BUTTON_PREF_HEIGHT); + button7.setPrefSize(BUTTON_PREF_WIDTH, BUTTON_PREF_HEIGHT); + button8.setPrefSize(BUTTON_PREF_WIDTH, BUTTON_PREF_HEIGHT); + button9.setPrefSize(BUTTON_PREF_WIDTH, BUTTON_PREF_HEIGHT); + buttonPoint.setPrefSize(BUTTON_PREF_WIDTH, BUTTON_PREF_HEIGHT); + buttonEqual.setPrefSize(BUTTON_PREF_WIDTH, BUTTON_PREF_HEIGHT); + + buttonPlus.setPrefSize(BUTTON_PREF_WIDTH, BUTTON_PREF_HEIGHT); + buttonMinus.setPrefSize(BUTTON_PREF_WIDTH, BUTTON_PREF_HEIGHT); + buttonMult.setPrefSize(BUTTON_PREF_WIDTH, BUTTON_PREF_HEIGHT); + buttonDiv.setPrefSize(BUTTON_PREF_WIDTH, BUTTON_PREF_HEIGHT); + + buttonMC.setPrefSize(BUTTON_PREF_WIDTH, BUTTON_PREF_HEIGHT); + buttonMR.setPrefSize(BUTTON_PREF_WIDTH, BUTTON_PREF_HEIGHT); + buttonMS.setPrefSize(BUTTON_PREF_WIDTH, BUTTON_PREF_HEIGHT); + buttonMPlus.setPrefSize(BUTTON_PREF_WIDTH, BUTTON_PREF_HEIGHT); + + buttonSQRT.setPrefSize(BUTTON_PREF_WIDTH, BUTTON_PREF_HEIGHT); + buttonMOD.setPrefSize(BUTTON_PREF_WIDTH, BUTTON_PREF_HEIGHT); + buttonINV.setPrefSize(BUTTON_PREF_WIDTH, BUTTON_PREF_HEIGHT); + buttonOPP.setPrefSize(BUTTON_PREF_WIDTH, BUTTON_PREF_HEIGHT); + + buttonBackspace.setPrefSize(200, 800); + buttonCE.setPrefSize(200, 800); + buttonC.setPrefSize(200, 800); + + // Add the buttons to the window + windowContent.add(button0,1,6); + windowContent.add(button1,1,5); + windowContent.add(button2,2,5); + windowContent.add(button3,3,5); + windowContent.add(button4,1,4); + windowContent.add(button5,2,4); + windowContent.add(button6,3,4); + windowContent.add(button7,1,3); + windowContent.add(button8,2,3); + windowContent.add(button9,3,3); + windowContent.add(buttonPoint,3,6); + windowContent.add(buttonSQRT,5,3); + windowContent.add(buttonMOD,5,4); + windowContent.add(buttonINV,5,5); + windowContent.add(buttonEqual,5,6); + windowContent.add(buttonOPP,2,6); + + GridPane.setRowIndex(buttonPlus, 6); + GridPane.setColumnIndex(buttonPlus, 4); + GridPane.setRowIndex(buttonMinus, 5); + GridPane.setColumnIndex(buttonMinus, 4); + GridPane.setRowIndex(buttonMult, 4); + GridPane.setColumnIndex(buttonMult, 4); + GridPane.setRowIndex(buttonDiv, 3); + GridPane.setColumnIndex(buttonDiv, 4); + windowContent.getChildren().addAll(buttonPlus, buttonMinus, buttonMult, buttonDiv); + + // First column + GridPane.setRowIndex(buttonMC, 3); + GridPane.setColumnIndex(buttonMC, 0); + buttonMC.setPrefSize(BUTTON_PREF_WIDTH, BUTTON_PREF_HEIGHT); + + GridPane.setRowIndex(buttonMR, 4); + GridPane.setColumnIndex(buttonMR, 0); + GridPane.setRowIndex(buttonMS, 5); + GridPane.setColumnIndex(buttonMS, 0); + GridPane.setRowIndex(buttonMPlus, 6); + GridPane.setColumnIndex(buttonMPlus, 0); + + windowContent.getChildren().addAll(buttonMC, buttonMR, buttonMS, buttonMPlus); + + // First row + GridPane.setHalignment(buttonBackspace, HPos.LEFT); + GridPane.setColumnSpan(buttonBackspace, 2); + GridPane.setFillHeight(buttonBackspace, true); + GridPane.setFillWidth(buttonBackspace, true); // fill all space in the cell + GridPane.setHgrow(buttonBackspace, Priority.ALWAYS); + GridPane.setVgrow(buttonBackspace, Priority.ALWAYS); + GridPane.setMargin(buttonBackspace, new Insets(2,40,2,2)); + windowContent.add(buttonBackspace, 1, 2); + + GridPane.setHalignment(buttonCE, HPos.CENTER); + GridPane.setColumnSpan(buttonCE, 3); + GridPane.setMargin(buttonCE, new Insets(2,40,2,40)); + windowContent.add(buttonCE, 2, 2); + + GridPane.setHalignment(buttonC, HPos.RIGHT); + GridPane.setColumnSpan(buttonC, 2); + GridPane.setMargin(buttonC, new Insets(2,2,2,40)); + windowContent.add(buttonC, 4, 2); + + getChildren().add(windowContent); + + } + +} diff --git a/Lesson26/WebContent/META-INF/MANIFEST.MF b/Lesson18/src/application/WebContent/META-INF/MANIFEST.MF similarity index 100% rename from Lesson26/WebContent/META-INF/MANIFEST.MF rename to Lesson18/src/application/WebContent/META-INF/MANIFEST.MF diff --git a/Lesson18/src/application/WebContent/WEB-INF/glassfish-web.xml b/Lesson18/src/application/WebContent/WEB-INF/glassfish-web.xml new file mode 100644 index 0000000..ed6200c --- /dev/null +++ b/Lesson18/src/application/WebContent/WEB-INF/glassfish-web.xml @@ -0,0 +1,6 @@ + + + + + /Lesson30 + \ No newline at end of file diff --git a/Lesson18/src/application/calculator.css b/Lesson18/src/application/calculator.css new file mode 100644 index 0000000..1113d8b --- /dev/null +++ b/Lesson18/src/application/calculator.css @@ -0,0 +1,100 @@ +@CHARSET "ISO-8859-1"; + +#chocolat { + -fx-background-color: #702510; + -fx-font-family: Helvetica; + -fx-font-size: 18px; + -fx-background-radius: 50; + -fx-text-fill: yellow; +} + +.text-field { + -fx-border-color: transparent; + -fx-background-radius: 50; + -fx-background-color: -fx-shadow-highlight-color, -fx-control-inner-background; +} + + +/* +.root { +-fx-border-radius: 30; +-fx-border-width:5; +-fx-border-color:blue; +} + +*/ + + + + +/* + +.menu { + -fx-background-color: grey; + -fx-font-family: Helvetica; + -fx-font-size: 18px; +} + +.menu-bar { + -fx-background-color: grey; + -fx-font-family: Helvetica; + -fx-font-size: 18px; +} + +.menu-bar .label{ + -fx-background-color: grey; + -fx-text-fill: yellow; + -fx-font-family: Helvetica; + -fx-font-size: 18px; +} + +.context-menu { + -fx-background-color: grey; + -fx-font-family: Helvetica; + -fx-font-size: 18px; +} + +.menu-item { + -fx-background-color: grey; + -fx-font-family: Helvetica; + -fx-font-size: 18px; +} + +*/ + +/* From caspian.css +.button { + -fx-background-color: -fx-shadow-highlight-color, -fx-outer-border, -fx-inner-border, -fx-body-color; + -fx-background-insets: 0 0 -1 0, 0, 1, 2; + -fx-background-radius: 5, 5, 4, 3; + -fx-padding: 0.166667em 0.833333em 0.25em 0.833333em; // 2 10 3 10 + -fx-text-fill: -fx-text-base-color; + -fx-alignment: CENTER; + -fx-content-display: LEFT; +} + +.text-field { + -fx-background-color: -fx-shadow-highlight-color, -fx-text-box-border, -fx-control-inner-background; + -fx-background-insets: 0, 1, 2; + -fx-background-radius: 3, 2, 2; + -fx-padding: 0.25em 0.416667em 0.333333em 0.416667em; // 3 5 4 5 + -fx-text-fill: -fx-text-inner-color; + -fx-prompt-text-fill: derive(-fx-control-inner-background,-30%); + -fx-cursor: text; +} + +.text-field:focused { + -fx-background-color: -fx-focus-color, -fx-text-box-border, -fx-control-inner-background; + -fx-background-insets: -0.4, 1, 2; + -fx-background-radius: 3.4, 2, 2; + -fx-prompt-text-fill: transparent; +} + +.text-field:disabled { + -fx-opacity: -fx-disabled-opacity; +} +*/ + + + + \ No newline at end of file diff --git a/Lesson18/src/application/src/DirectMessageReceiver.java b/Lesson18/src/application/src/DirectMessageReceiver.java new file mode 100644 index 0000000..afe39da --- /dev/null +++ b/Lesson18/src/application/src/DirectMessageReceiver.java @@ -0,0 +1,52 @@ + +import javax.jms.*; + +import com.sun.messaging.ConnectionFactory; +import com.sun.messaging.ConnectionConfiguration; + + +public class DirectMessageReceiver implements MessageListener{ + + ConnectionFactory factory = new com.sun.messaging.ConnectionFactory(); + JMSConsumer consumer; + + DirectMessageReceiver(){ + try( JMSContext context = factory.createContext("admin","admin")){ + factory.setProperty(ConnectionConfiguration.imqAddressList, "mq://127.0.0.1:7676,mq://127.0.0.1:7676"); + + Destination ordersQueue = context.createQueue("TradingOrdersQueue"); + + consumer = context.createConsumer(ordersQueue); + + consumer.setMessageListener(this); + + System.out.println("Listening to the TradingOrdersQueue..."); + + // Keep the program running - wait for messages + Thread.sleep(100000); + + } catch (InterruptedException e){ + System.out.println("Error: " + e.getMessage()); + } + catch (JMSException e){ + System.out.println("Error: " + e.getMessage()); + } + } + + public void onMessage(Message msg){ + + try{ + System.out.println("Got the text message from the TradingOrdersQueue: " + + msg.getBody(String.class)); + + System.out.println("\n === Here's what toString() on the message prints \n" + msg); + + } catch (JMSException e){ + System.err.println("JMSException: " + e.toString()); + } + } + + public static void main(String[] args){ + new DirectMessageReceiver(); + } +} \ No newline at end of file diff --git a/Lesson18/src/application/src/DirectMessageSender.java b/Lesson18/src/application/src/DirectMessageSender.java new file mode 100644 index 0000000..acd8e9b --- /dev/null +++ b/Lesson18/src/application/src/DirectMessageSender.java @@ -0,0 +1,29 @@ + +import javax.jms.*; + +import com.sun.messaging.ConnectionFactory; +import com.sun.messaging.ConnectionConfiguration; + + +public class DirectMessageSender{ + public static void main(String[] args){ + + ConnectionFactory factory; + + factory = new com.sun.messaging.ConnectionFactory(); + + try( JMSContext context = factory.createContext("admin","admin")){ + + factory.setProperty(ConnectionConfiguration.imqAddressList, "mq://127.0.0.1:7676,mq://127.0.0.1:7676"); + Destination ordersQueue = context.createQueue("TradingOrdersQueue"); + JMSProducer producer = context.createProducer(); + + // Send msg to buy 200 shares of IBM at market price + producer.send(ordersQueue,"IBM 200 Mkt"); + + System.out.println("Sucsessfully placed to TradingOrdersQueue an order to purchase 200 shares of IBM"); + } catch (JMSException e){ + System.out.println("Error: " + e.getMessage()); + } + } +} diff --git a/Lesson19/.classpath b/Lesson19/.classpath index ec75874..7c10b7d 100644 --- a/Lesson19/.classpath +++ b/Lesson19/.classpath @@ -1,7 +1,7 @@ - + diff --git a/Lesson26_Old/.classpath b/Lesson26_Old/.classpath new file mode 100644 index 0000000..bb0832d --- /dev/null +++ b/Lesson26_Old/.classpath @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/Lesson26_Old/.gitignore b/Lesson26_Old/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/Lesson26_Old/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/Lesson26_Old/.project b/Lesson26_Old/.project new file mode 100644 index 0000000..234584a --- /dev/null +++ b/Lesson26_Old/.project @@ -0,0 +1,36 @@ + + + Lesson26_Old + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/Lesson26_Old/.settings/.jsdtscope b/Lesson26_Old/.settings/.jsdtscope new file mode 100644 index 0000000..3a28de0 --- /dev/null +++ b/Lesson26_Old/.settings/.jsdtscope @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/Lesson26_Old/.settings/org.eclipse.jdt.core.prefs b/Lesson26_Old/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..a698e59 --- /dev/null +++ b/Lesson26_Old/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/Lesson26_Old/.settings/org.eclipse.wst.common.component b/Lesson26_Old/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..363decd --- /dev/null +++ b/Lesson26_Old/.settings/org.eclipse.wst.common.component @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/Lesson26/.settings/org.eclipse.wst.common.project.facet.core.xml b/Lesson26_Old/.settings/org.eclipse.wst.common.project.facet.core.xml similarity index 86% rename from Lesson26/.settings/org.eclipse.wst.common.project.facet.core.xml rename to Lesson26_Old/.settings/org.eclipse.wst.common.project.facet.core.xml index bec785d..5837e54 100644 --- a/Lesson26/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/Lesson26_Old/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -7,4 +7,5 @@ + diff --git a/Lesson26_Old/.settings/org.eclipse.wst.jsdt.ui.superType.container b/Lesson26_Old/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/Lesson26_Old/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/Lesson26_Old/.settings/org.eclipse.wst.jsdt.ui.superType.name b/Lesson26_Old/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/Lesson26_Old/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/Lesson26_Old/.settings/org.jboss.ide.eclipse.as.core.prefs b/Lesson26_Old/.settings/org.jboss.ide.eclipse.as.core.prefs new file mode 100644 index 0000000..cf3aa3a --- /dev/null +++ b/Lesson26_Old/.settings/org.jboss.ide.eclipse.as.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.jboss.ide.eclipse.as.core.singledeployable.deployableList= diff --git a/Lesson26_Old/WebContent/META-INF/MANIFEST.MF b/Lesson26_Old/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 0000000..254272e --- /dev/null +++ b/Lesson26_Old/WebContent/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/Lesson26_Old/WebContent/WEB-INF/glassfish-web.xml b/Lesson26_Old/WebContent/WEB-INF/glassfish-web.xml new file mode 100644 index 0000000..427b823 --- /dev/null +++ b/Lesson26_Old/WebContent/WEB-INF/glassfish-web.xml @@ -0,0 +1,6 @@ + + + + + /Lesson26 + \ No newline at end of file diff --git a/Lesson26/src/com/practicaljava/lesson26/Book.java b/Lesson26_Old/src/com/practicaljava/lesson26/Book.java similarity index 100% rename from Lesson26/src/com/practicaljava/lesson26/Book.java rename to Lesson26_Old/src/com/practicaljava/lesson26/Book.java diff --git a/Lesson26/src/com/practicaljava/lesson26/FindBooksAsyncServlet.java b/Lesson26_Old/src/com/practicaljava/lesson26/FindBooksAsyncServlet.java similarity index 100% rename from Lesson26/src/com/practicaljava/lesson26/FindBooksAsyncServlet.java rename to Lesson26_Old/src/com/practicaljava/lesson26/FindBooksAsyncServlet.java diff --git a/Lesson26/src/com/practicaljava/lesson26/FindBooksServlet.java b/Lesson26_Old/src/com/practicaljava/lesson26/FindBooksServlet.java similarity index 96% rename from Lesson26/src/com/practicaljava/lesson26/FindBooksServlet.java rename to Lesson26_Old/src/com/practicaljava/lesson26/FindBooksServlet.java index 4448f6a..7ecc0b2 100644 --- a/Lesson26/src/com/practicaljava/lesson26/FindBooksServlet.java +++ b/Lesson26_Old/src/com/practicaljava/lesson26/FindBooksServlet.java @@ -30,7 +30,7 @@ public FindBooksServlet() { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub PrintWriter out = response.getWriter(); - out.println("Hello from FindBooks"); + out.println("Hello from me!"); } diff --git a/Lesson26/src/com/practicaljava/lesson26/ShoppingCartServlet.java b/Lesson26_Old/src/com/practicaljava/lesson26/ShoppingCartServlet.java similarity index 100% rename from Lesson26/src/com/practicaljava/lesson26/ShoppingCartServlet.java rename to Lesson26_Old/src/com/practicaljava/lesson26/ShoppingCartServlet.java diff --git a/Lesson30/.classpath b/Lesson30/.classpath index f8985c6..f1e477e 100644 --- a/Lesson30/.classpath +++ b/Lesson30/.classpath @@ -1,11 +1,6 @@ - - - - - @@ -13,7 +8,7 @@ - - + + diff --git a/Lesson30/.settings/org.eclipse.jdt.core.prefs b/Lesson30/.settings/org.eclipse.jdt.core.prefs index 0c68a61..a698e59 100644 --- a/Lesson30/.settings/org.eclipse.jdt.core.prefs +++ b/Lesson30/.settings/org.eclipse.jdt.core.prefs @@ -1,7 +1,12 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.source=1.8 diff --git a/Lesson30/src/Bid.java b/Lesson30/src/Bid.java new file mode 100644 index 0000000..c43bf0e --- /dev/null +++ b/Lesson30/src/Bid.java @@ -0,0 +1,18 @@ + + +import java.io.Serializable; +import java.math.BigDecimal; +import java.time.LocalDateTime; + +/** + * Created by yfain11 on 4/4/14. + */ +public class Bid implements Serializable { + public int id; + public Product product; + public BigDecimal amount; + public int desiredQuantity; // How many items the user wants + public User user; + public LocalDateTime bidTime; + public boolean isWinning; +} diff --git a/Lesson30/src/DirectMessageReceiver.java b/Lesson30/src/DirectMessageReceiver.java index afe39da..241ed05 100644 --- a/Lesson30/src/DirectMessageReceiver.java +++ b/Lesson30/src/DirectMessageReceiver.java @@ -1,46 +1,98 @@ +import java.util.Properties; + import javax.jms.*; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; -import com.sun.messaging.ConnectionFactory; -import com.sun.messaging.ConnectionConfiguration; +//import com.sun.messaging.ConnectionFactory; +//import com.sun.messaging.ConnectionConfiguration; public class DirectMessageReceiver implements MessageListener{ + + Context namingContext = null; - ConnectionFactory factory = new com.sun.messaging.ConnectionFactory(); +//ConnectionFactory factory = new com.sun.messaging.ConnectionFactory(); + JMSConsumer consumer; DirectMessageReceiver(){ - try( JMSContext context = factory.createContext("admin","admin")){ - factory.setProperty(ConnectionConfiguration.imqAddressList, "mq://127.0.0.1:7676,mq://127.0.0.1:7676"); - - Destination ordersQueue = context.createQueue("TradingOrdersQueue"); - - consumer = context.createConsumer(ordersQueue); - - consumer.setMessageListener(this); - - System.out.println("Listening to the TradingOrdersQueue..."); - - // Keep the program running - wait for messages - Thread.sleep(100000); - - } catch (InterruptedException e){ + try{ + // Set up the namingContext for the JNDI lookup + final Properties env = new Properties(); + env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); + env.put(Context.PROVIDER_URL, System.getProperty(Context.PROVIDER_URL, "http-remoting://127.0.0.1:9080")); + env.put(Context.SECURITY_PRINCIPAL, "quickstartUser"); + env.put(Context.SECURITY_CREDENTIALS, "quickstartPwd1!"); + namingContext = new InitialContext(env); + + ConnectionFactory factory = (ConnectionFactory) namingContext.lookup("jms/RemoteConnectionFactory"); + + try( JMSContext context = factory.createContext("quickstartUser","quickstartPwd1!")){ + //factory.setProperty(ConnectionConfiguration.imqAddressList, "mq://127.0.0.1:7676,mq://127.0.0.1:7676"); + + Destination ordersQueue = context.createQueue("testQueue"); + + consumer = context.createConsumer(ordersQueue); + + consumer.setMessageListener(this); + + System.out.println("Listening to the test queue..."); + + // Keep the program running - wait for messages + Thread.sleep(100000); + + } + + } + catch(NamingException e){ + + } + catch (InterruptedException e){ System.out.println("Error: " + e.getMessage()); } - catch (JMSException e){ - System.out.println("Error: " + e.getMessage()); - } +// catch (JMSException e){ +// System.out.println("Error: " + e.getMessage()); +// } + finally { + if (namingContext != null) { + try { + namingContext.close(); + } catch (NamingException e) { + System.out.println(e.getMessage()); + } + } + + + } + } public void onMessage(Message msg){ try{ - System.out.println("Got the text message from the TradingOrdersQueue: " + - msg.getBody(String.class)); + /* System.out.println("Got the text message from the TradingOrdersQueue: " + + msg.getBody(String.class)); */ + /* + if (msg instanceof ObjectMessage) { + Object object = ((ObjectMessage) msg).getObject(); + Bid myBid = (Bid) object; + + // Bid myBid = (Bid)((ObjectMessage) msg).getObject(); + // System.out.println("Received a bid from " + myBid.user.name); + + System.out.println("\n === Here's what toString() on the message prints \n" + myBid); + } + */ + + Bid myBid = msg.getBody(Bid.class); System.out.println("\n === Here's what toString() on the message prints \n" + msg); + + } catch (JMSException e){ System.err.println("JMSException: " + e.toString()); } diff --git a/Lesson30/src/DirectMessageSender.java b/Lesson30/src/DirectMessageSender.java index d2d9bba..ef678e5 100644 --- a/Lesson30/src/DirectMessageSender.java +++ b/Lesson30/src/DirectMessageSender.java @@ -1,4 +1,4 @@ - +/* import javax.jms.*; import com.sun.messaging.ConnectionFactory; @@ -31,3 +31,4 @@ public static void main(String[] args){ } } } +*/ diff --git a/Lesson30/src/Product.java b/Lesson30/src/Product.java new file mode 100644 index 0000000..b1eea60 --- /dev/null +++ b/Lesson30/src/Product.java @@ -0,0 +1,20 @@ + + +import java.io.Serializable; +import java.math.BigDecimal; +import java.time.LocalDateTime; + +/** + * Created by yfain11 on 4/4/14. + */ +public class Product implements Serializable { + public int id; + public String title; + public String thumb; + public String description; + public int quantity; // How many items the seller has + public LocalDateTime auctionEndTime; + public int watchers; + public BigDecimal minimalPrice; // Don't sell unless the bid is more than min price + public BigDecimal reservedPrice; // If a bidder offers reserved price, the auction is closed +} diff --git a/Lesson30/src/User.java b/Lesson30/src/User.java new file mode 100644 index 0000000..b6c4e3a --- /dev/null +++ b/Lesson30/src/User.java @@ -0,0 +1,13 @@ + + +import java.io.Serializable; + +/** + * Created by yfain11 on 4/4/14. + */ +public class User implements Serializable { + public int id; + public String name; + public String email; + public boolean getOverbidNotifications; +} diff --git a/Lesson31.zip b/Lesson31.zip new file mode 100644 index 0000000..7bddcbd Binary files /dev/null and b/Lesson31.zip differ diff --git a/Lesson31/.classpath b/Lesson31/.classpath new file mode 100644 index 0000000..77022b7 --- /dev/null +++ b/Lesson31/.classpath @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/Lesson31/.gitignore b/Lesson31/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/Lesson31/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/Lesson31/.project b/Lesson31/.project new file mode 100644 index 0000000..8d1bd13 --- /dev/null +++ b/Lesson31/.project @@ -0,0 +1,36 @@ + + + Lesson31 + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/Lesson31/.settings/.jsdtscope b/Lesson31/.settings/.jsdtscope new file mode 100644 index 0000000..3a28de0 --- /dev/null +++ b/Lesson31/.settings/.jsdtscope @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/Lesson31/.settings/org.eclipse.jdt.core.prefs b/Lesson31/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/Lesson31/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/Lesson31/.settings/org.eclipse.wst.common.component b/Lesson31/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..c806d69 --- /dev/null +++ b/Lesson31/.settings/org.eclipse.wst.common.component @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/Lesson31/.settings/org.eclipse.wst.common.project.facet.core.xml b/Lesson31/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..351030d --- /dev/null +++ b/Lesson31/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/Lesson31/.settings/org.eclipse.wst.jsdt.ui.superType.container b/Lesson31/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/Lesson31/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/Lesson31/.settings/org.eclipse.wst.jsdt.ui.superType.name b/Lesson31/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/Lesson31/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/Lesson31/Lesson31.war b/Lesson31/Lesson31.war new file mode 100644 index 0000000..46839d3 Binary files /dev/null and b/Lesson31/Lesson31.war differ diff --git a/Lesson31/WebContent/META-INF/MANIFEST.MF b/Lesson31/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 0000000..254272e --- /dev/null +++ b/Lesson31/WebContent/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/Lesson31/WebContent/WEB-INF/glassfish-web.xml b/Lesson31/WebContent/WEB-INF/glassfish-web.xml new file mode 100644 index 0000000..3e324b9 --- /dev/null +++ b/Lesson31/WebContent/WEB-INF/glassfish-web.xml @@ -0,0 +1,6 @@ + + + + + /Lesson31 + \ No newline at end of file diff --git a/Lesson31/src/lesson31/client/HelloWorldServlet.java b/Lesson31/src/lesson31/client/HelloWorldServlet.java new file mode 100644 index 0000000..d8c97c3 --- /dev/null +++ b/Lesson31/src/lesson31/client/HelloWorldServlet.java @@ -0,0 +1,31 @@ +package lesson31.client; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.ejb.EJB; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import lesson31.ejb.HelloWorldBean; +import lesson31.ejb.HelloWorldLocal; +import lesson31.ejb.StockServerBean; + +@WebServlet(urlPatterns = { "/HelloWorldServlet" }) +public class HelloWorldServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + + //@EJB HelloWorldBean myBean; + @EJB StockServerBean myBean; + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + PrintWriter out = response.getWriter(); + //out.println(myBean.sayHello()); + out.println(myBean.getQuote("AMZN")); + + } + +} diff --git a/Lesson31/src/lesson31/ejb/Authorizable.java b/Lesson31/src/lesson31/ejb/Authorizable.java new file mode 100644 index 0000000..1649e5e --- /dev/null +++ b/Lesson31/src/lesson31/ejb/Authorizable.java @@ -0,0 +1,8 @@ +package lesson31.ejb; + +import javax.ejb.Local; + +@Local +public interface Authorizable { + public String authorize(); +} diff --git a/Lesson31/src/lesson31/ejb/Greeting.java b/Lesson31/src/lesson31/ejb/Greeting.java new file mode 100644 index 0000000..4e26e39 --- /dev/null +++ b/Lesson31/src/lesson31/ejb/Greeting.java @@ -0,0 +1,8 @@ +package lesson31.ejb; + +import javax.ejb.Remote; + +@Remote +public interface Greeting { + public String sayHello(); +} diff --git a/Lesson31/src/lesson31/ejb/HelloWorldBean.java b/Lesson31/src/lesson31/ejb/HelloWorldBean.java new file mode 100644 index 0000000..9a3f1bf --- /dev/null +++ b/Lesson31/src/lesson31/ejb/HelloWorldBean.java @@ -0,0 +1,24 @@ +package lesson31.ejb; + +import javax.ejb.LocalBean; +import javax.ejb.Stateless; + +/** + * Session Bean implementation class HelloWorldBean + */ +@Stateless +@LocalBean +public class HelloWorldBean { + + /** + * Default constructor. + */ + public HelloWorldBean() { + // TODO Auto-generated constructor stub + } + + public String sayHello(){ + return "Hello World!"; + } + +} diff --git a/Lesson31/src/lesson31/ejb/HelloWorldLocal.java b/Lesson31/src/lesson31/ejb/HelloWorldLocal.java new file mode 100644 index 0000000..dfc5339 --- /dev/null +++ b/Lesson31/src/lesson31/ejb/HelloWorldLocal.java @@ -0,0 +1,15 @@ +package lesson31.ejb; + +import javax.ejb.Stateless; + +@Stateless +public class HelloWorldLocal implements Authorizable { + + public String authorize(){ + return "The user is authorized!"; + } + + public String sayHello(){ + return "Hello World!"; + } +} diff --git a/Lesson31/src/lesson31/ejb/HelloWorldLocalRemote.java b/Lesson31/src/lesson31/ejb/HelloWorldLocalRemote.java new file mode 100644 index 0000000..b81770f --- /dev/null +++ b/Lesson31/src/lesson31/ejb/HelloWorldLocalRemote.java @@ -0,0 +1,15 @@ +package lesson31.ejb; + +import javax.ejb.Stateless; + +@Stateless +public class HelloWorldLocalRemote implements Authorizable, Greeting { + + public String authorize(){ + return "The user is authorized!"; + } + + public String sayHello(){ + return "Hello World!"; + } +} diff --git a/Lesson31/src/lesson31/ejb/StockServerBean.java b/Lesson31/src/lesson31/ejb/StockServerBean.java new file mode 100644 index 0000000..6f1b981 --- /dev/null +++ b/Lesson31/src/lesson31/ejb/StockServerBean.java @@ -0,0 +1,29 @@ +package lesson31.ejb; + +import java.util.ArrayList; +import java.util.List; + +import javax.ejb.Stateless; + +@Stateless +public class StockServerBean { + private String price = null; + private List nasdaqSymbols = new ArrayList<>(); + + public StockServerBean(){ + nasdaqSymbols.add("AAPL"); + nasdaqSymbols.add("IBM"); + nasdaqSymbols.add("ORCL"); + nasdaqSymbols.add("AMZN"); + } + + public String getQuote(String symbol){ + + if ((nasdaqSymbols.indexOf(symbol.toUpperCase())) != -1){ + + price = (new Double(Math.random()*100)).toString(); + } + //System.out.println("The price of " + symbol + " is " + price); + return price; + } +} diff --git a/Lesson33.zip b/Lesson33.zip new file mode 100644 index 0000000..5791868 Binary files /dev/null and b/Lesson33.zip differ diff --git a/Lesson33/Lesson33/.classpath b/Lesson33/Lesson33/.classpath new file mode 100644 index 0000000..77022b7 --- /dev/null +++ b/Lesson33/Lesson33/.classpath @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/Lesson33/Lesson33/.gitignore b/Lesson33/Lesson33/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/Lesson33/Lesson33/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/Lesson33/Lesson33/.project b/Lesson33/Lesson33/.project new file mode 100644 index 0000000..eaf15fe --- /dev/null +++ b/Lesson33/Lesson33/.project @@ -0,0 +1,36 @@ + + + Lesson33 + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/Lesson33/Lesson33/.settings/.jsdtscope b/Lesson33/Lesson33/.settings/.jsdtscope new file mode 100644 index 0000000..3a28de0 --- /dev/null +++ b/Lesson33/Lesson33/.settings/.jsdtscope @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/Lesson33/Lesson33/.settings/org.eclipse.jdt.core.prefs b/Lesson33/Lesson33/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/Lesson33/Lesson33/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/Lesson33/Lesson33/.settings/org.eclipse.wst.common.component b/Lesson33/Lesson33/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..424e587 --- /dev/null +++ b/Lesson33/Lesson33/.settings/org.eclipse.wst.common.component @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/Lesson33/Lesson33/.settings/org.eclipse.wst.common.project.facet.core.xml b/Lesson33/Lesson33/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..9e3a61b --- /dev/null +++ b/Lesson33/Lesson33/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/Lesson33/Lesson33/.settings/org.eclipse.wst.jsdt.ui.superType.container b/Lesson33/Lesson33/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/Lesson33/Lesson33/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/Lesson33/Lesson33/.settings/org.eclipse.wst.jsdt.ui.superType.name b/Lesson33/Lesson33/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/Lesson33/Lesson33/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/Lesson33/Lesson33/WebContent/META-INF/MANIFEST.MF b/Lesson33/Lesson33/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 0000000..254272e --- /dev/null +++ b/Lesson33/Lesson33/WebContent/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/Lesson33/Lesson33/WebContent/WEB-INF/glassfish-web.xml b/Lesson33/Lesson33/WebContent/WEB-INF/glassfish-web.xml new file mode 100644 index 0000000..bd888ee --- /dev/null +++ b/Lesson33/Lesson33/WebContent/WEB-INF/glassfish-web.xml @@ -0,0 +1,6 @@ + + + + + /Lesson33 + \ No newline at end of file diff --git a/Lesson33/Lesson33/product_from_object.json b/Lesson33/Lesson33/product_from_object.json new file mode 100644 index 0000000..47cf2ee --- /dev/null +++ b/Lesson33/Lesson33/product_from_object.json @@ -0,0 +1 @@ +{"id":777,"description":"Chanel Handbag","price":1000.0} \ No newline at end of file diff --git a/Lesson33/Lesson33/product_from_stream.json b/Lesson33/Lesson33/product_from_stream.json new file mode 100644 index 0000000..e2606e5 --- /dev/null +++ b/Lesson33/Lesson33/product_from_stream.json @@ -0,0 +1 @@ +{"id":777,"description":"Gucci Handbag","price":1000.0} \ No newline at end of file diff --git a/Lesson33/Lesson33/src/json/JavaToJSONObject.java b/Lesson33/Lesson33/src/json/JavaToJSONObject.java new file mode 100644 index 0000000..f5db64a --- /dev/null +++ b/Lesson33/Lesson33/src/json/JavaToJSONObject.java @@ -0,0 +1,49 @@ +package json; /** + * Created by yfain11 on 4/12/14. + */ + +import javax.json.JsonObject; +import javax.json.Json; +import javax.json.JsonReader; +import javax.json.JsonWriter; +import javax.json.JsonObjectBuilder; + +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.OutputStream; + + +public class JavaToJSONObject { + + public static void main(String[] args) { + + Product prd1 = new Product(777, "Chanel Handbag", 1000.00); + + try (OutputStream fos = new FileOutputStream("product_from_object.json"); + JsonWriter jsonWriter = Json.createWriter(fos);) { + + JsonObjectBuilder prdBuilder = Json.createObjectBuilder(); + + prdBuilder.add("id", prd1.id) + .add("description", prd1.description) + .add("price", prd1.price); + + JsonObject prdJsonObject = prdBuilder.build(); + + System.out.println("prdJsonObject: " + prdJsonObject); + + + jsonWriter.writeObject(prdJsonObject); + + // Read and parse the newly created file back + JsonReader jsonReader = + Json.createReader(new FileReader("product_from_object.json")); + JsonObject jsonObject = jsonReader.readObject(); + System.out.println(jsonObject); + + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/Lesson33/Lesson33/src/json/JavaToJSONStreaming.java b/Lesson33/Lesson33/src/json/JavaToJSONStreaming.java new file mode 100644 index 0000000..65b65a0 --- /dev/null +++ b/Lesson33/Lesson33/src/json/JavaToJSONStreaming.java @@ -0,0 +1,32 @@ +package json; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +import javax.json.Json; +import javax.json.stream.JsonGenerator; + + +public class JavaToJSONStreaming { + + public static void main(String[] args) { + + Product prd1 = new Product(777, "Gucci Handbag", 1000.00); + + try (OutputStream fos = new FileOutputStream("product_from_stream.json"); + JsonGenerator jsonGenerator = Json.createGenerator(fos);) { + + jsonGenerator.writeStartObject(); // { + jsonGenerator.write("id", prd1.id); + jsonGenerator.write("description", prd1.description); + jsonGenerator.write("price", prd1.price); + + // If you have nested JSON objects, enclose each of them + // into a pair of writeStartObject() and writeEnd() + + jsonGenerator.writeEnd(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/Lesson33/Lesson33/src/json/Product.java b/Lesson33/Lesson33/src/json/Product.java new file mode 100644 index 0000000..2ffc5ca --- /dev/null +++ b/Lesson33/Lesson33/src/json/Product.java @@ -0,0 +1,12 @@ +package json; + +public class Product { + public int id; + public String description; + public double price; + public Product(int id, String description, double price){ + this.id=id; + this.description=description; + this.price=price; + } +} diff --git a/Lesson33/Lesson33/src/lesson33/StockQuoteApplication.java b/Lesson33/Lesson33/src/lesson33/StockQuoteApplication.java new file mode 100644 index 0000000..738be7b --- /dev/null +++ b/Lesson33/Lesson33/src/lesson33/StockQuoteApplication.java @@ -0,0 +1,8 @@ +package lesson33; + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; + +@ApplicationPath("resources") +public class StockQuoteApplication extends Application { +} diff --git a/Lesson33/Lesson33/src/lesson33/service/Stock.java b/Lesson33/Lesson33/src/lesson33/service/Stock.java new file mode 100644 index 0000000..14154b0 --- /dev/null +++ b/Lesson33/Lesson33/src/lesson33/service/Stock.java @@ -0,0 +1,54 @@ +package lesson33.service; + +import javax.xml.bind.annotation.XmlRootElement; + + +@XmlRootElement +public class Stock { + private String symbol; + private Double price; + private String currency; + private String country; + + public Stock() { + } + + public Stock(String symbol, Double price, String currency, String country) { + this.symbol = symbol; + this.price = price; + this.currency = currency; + this.country = country; + } + + public String getSymbol() { + return symbol; + } + + public void setSymbol(String symbol) { + this.symbol = symbol; + } + + public Double getPrice() { + return price; + } + + public void setPrice(Double price) { + this.price = price; + } + + public String getCurrency() { + return currency; + } + + public void setCurrency(String currency) { + this.currency = currency; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } +} diff --git a/Lesson33/Lesson33/src/lesson33/service/StockService.java b/Lesson33/Lesson33/src/lesson33/service/StockService.java new file mode 100644 index 0000000..a6e81e5 --- /dev/null +++ b/Lesson33/Lesson33/src/lesson33/service/StockService.java @@ -0,0 +1,52 @@ +package lesson33.service; + +import javax.ws.rs.Consumes; +import javax.ws.rs.FormParam; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Response; + +@Path("/stock") +public class StockService { + + @Produces({"application/xml","application/json"}) + @Path("{symbol}") + @GET + public Stock getStock(@PathParam("symbol") String symbol) { + + Stock stock = StockServiceHelper.getStock(symbol); + + if (stock == null) { + return new Stock("NOT FOUND", 0.0, "--", "--"); + } + + return stock; + } + + @POST + @Consumes("application/x-www-form-urlencoded") + public Response addStock(@FormParam("symbol") String symbol, + @FormParam("currency") String currency, + @FormParam("price") String price, + @FormParam("country") String country) { + + if (StockServiceHelper.getStock(symbol) != null) + return Response.status(Response.Status.BAD_REQUEST). + entity("Stock " + symbol + " already exists").type("text/plain").build(); + + double priceToUse; + try { + priceToUse = new Double(price); + } + catch (NumberFormatException e) { + priceToUse = 0.0; + } + + StockServiceHelper.addStock(new Stock(symbol, priceToUse, currency, country)); + + return Response.ok().build(); + } +} diff --git a/Lesson33/Lesson33/src/lesson33/service/StockServiceHelper.java b/Lesson33/Lesson33/src/lesson33/service/StockServiceHelper.java new file mode 100644 index 0000000..969f0b2 --- /dev/null +++ b/Lesson33/Lesson33/src/lesson33/service/StockServiceHelper.java @@ -0,0 +1,29 @@ +package lesson33.service; + +import java.util.HashMap; +import java.util.Map; + +public class StockServiceHelper { + public static void addStock(Stock stock) { + stocks.put(stock.getSymbol(), stock); + } + + public static void removeStock(String symbol) { + stocks.remove(symbol); + } + + public static Stock getStock(String symbol) { + return stocks.get(symbol); + } + + private static Map stocks = new HashMap<>(); + + static { + generateStocks(); + } + + private static void generateStocks() { + addStock(new Stock("IBM", 43.12, "USD", "USA")); + addStock(new Stock("AAPL", 120.0, "USD", "USA")); + } +} diff --git a/TicTacToe/.classpath b/TicTacToe/.classpath index ec75874..ac4a647 100644 --- a/TicTacToe/.classpath +++ b/TicTacToe/.classpath @@ -1,7 +1,7 @@ - + diff --git a/TicTacToe/src/tictactoe/TicTacToe.fxml b/TicTacToe/src/tictactoe/TicTacToe.fxml index 192f9a7..37894a5 100644 --- a/TicTacToe/src/tictactoe/TicTacToe.fxml +++ b/TicTacToe/src/tictactoe/TicTacToe.fxml @@ -5,16 +5,13 @@ - + - + @@ -28,18 +25,28 @@
- + -
diff --git a/TicTacToe/src/tictactoe/TicTacToeController.java b/TicTacToe/src/tictactoe/TicTacToeController.java index 0576dcb..9306c44 100644 --- a/TicTacToe/src/tictactoe/TicTacToeController.java +++ b/TicTacToe/src/tictactoe/TicTacToeController.java @@ -24,6 +24,7 @@ public class TicTacToeController { private boolean isFirstPlayer = true; + @FXML public void buttonClickHandler(ActionEvent evt){ Button clickedButton = (Button) evt.getTarget(); @@ -105,6 +106,7 @@ private void highlightWinningCombo(Button first, Button second, Button third){ } + @FXML public void menuClickHandler(ActionEvent evt){ MenuItem clickedMenu = (MenuItem) evt.getTarget(); String menuLabel = clickedMenu.getText(); @@ -115,7 +117,9 @@ public void menuClickHandler(ActionEvent evt){ buttons.forEach(btn -> { ((Button) btn).setText(""); - btn.getStyleClass().remove("winning-button"); + //System.out.println(btn.getStyleClass()); + //if ("button winning-button".equals(btn.getStyleClass().toString())) + btn.getStyleClass().remove("winning-button"); }); isFirstPlayer = true; diff --git a/TicTacToe/src/tictactoe/TicTacToeTest.fxml b/TicTacToe/src/tictactoe/TicTacToeTest.fxml new file mode 100644 index 0000000..9a0ca79 --- /dev/null +++ b/TicTacToe/src/tictactoe/TicTacToeTest.fxml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + +
+
diff --git a/TicTacToe/src/tictactoe/TicTacToe_Cristina.fxml b/TicTacToe/src/tictactoe/TicTacToe_Cristina.fxml new file mode 100644 index 0000000..d1580c1 --- /dev/null +++ b/TicTacToe/src/tictactoe/TicTacToe_Cristina.fxml @@ -0,0 +1,38 @@ + + + + + + + + + +
+ + + + + + + + + + + + + +
+
diff --git a/TicTacToe/src/tictactoe/application.css b/TicTacToe/src/tictactoe/application.css index 63dba86..8c3366c 100644 --- a/TicTacToe/src/tictactoe/application.css +++ b/TicTacToe/src/tictactoe/application.css @@ -1,5 +1,7 @@ .button{ - -fx-focus-color: transparent; + /* -fx-focus-color: transparent; */ + /* -fx-focus-color: inherit; */ + /* -fx-focus-color: initial; */ -fx-background-insets: -1, 0, 1, 1; -fx-font-weight: bold; -fx-font-size: 36; diff --git a/Lesson26/.classpath b/VoteMyHaiku/.classpath similarity index 81% rename from Lesson26/.classpath rename to VoteMyHaiku/.classpath index 6f7fb2f..c51ee43 100644 --- a/Lesson26/.classpath +++ b/VoteMyHaiku/.classpath @@ -1,12 +1,12 @@ - + - + diff --git a/VoteMyHaiku/.gitignore b/VoteMyHaiku/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/VoteMyHaiku/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/VoteMyHaiku/.project b/VoteMyHaiku/.project new file mode 100644 index 0000000..d39de72 --- /dev/null +++ b/VoteMyHaiku/.project @@ -0,0 +1,36 @@ + + + VoteMyHaiku + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/VoteMyHaiku/.settings/.jsdtscope b/VoteMyHaiku/.settings/.jsdtscope new file mode 100644 index 0000000..3a28de0 --- /dev/null +++ b/VoteMyHaiku/.settings/.jsdtscope @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/VoteMyHaiku/.settings/oracle.eclipse.tools.webtier.ui.prefs b/VoteMyHaiku/.settings/oracle.eclipse.tools.webtier.ui.prefs new file mode 100644 index 0000000..e3869fb --- /dev/null +++ b/VoteMyHaiku/.settings/oracle.eclipse.tools.webtier.ui.prefs @@ -0,0 +1,2 @@ +_hiddenCategory_\:HTML=false +eclipse.preferences.version=1 diff --git a/VoteMyHaiku/.settings/org.eclipse.jdt.core.prefs b/VoteMyHaiku/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/VoteMyHaiku/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/VoteMyHaiku/.settings/org.eclipse.wst.common.component b/VoteMyHaiku/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..0090522 --- /dev/null +++ b/VoteMyHaiku/.settings/org.eclipse.wst.common.component @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/VoteMyHaiku/.settings/org.eclipse.wst.common.project.facet.core.xml b/VoteMyHaiku/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..e7b9e36 --- /dev/null +++ b/VoteMyHaiku/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/VoteMyHaiku/.settings/org.eclipse.wst.jsdt.ui.superType.container b/VoteMyHaiku/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/VoteMyHaiku/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/VoteMyHaiku/.settings/org.eclipse.wst.jsdt.ui.superType.name b/VoteMyHaiku/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/VoteMyHaiku/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/VoteMyHaiku/WebContent/META-INF/MANIFEST.MF b/VoteMyHaiku/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 0000000..254272e --- /dev/null +++ b/VoteMyHaiku/WebContent/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/VoteMyHaiku/WebContent/WEB-INF/glassfish-web.xml b/VoteMyHaiku/WebContent/WEB-INF/glassfish-web.xml new file mode 100644 index 0000000..8afc6f6 --- /dev/null +++ b/VoteMyHaiku/WebContent/WEB-INF/glassfish-web.xml @@ -0,0 +1,6 @@ + + + + + /VoteMyHaiku + \ No newline at end of file diff --git a/VoteMyHaiku/WebContent/WEB-INF/web.xml b/VoteMyHaiku/WebContent/WEB-INF/web.xml new file mode 100644 index 0000000..4ced97a --- /dev/null +++ b/VoteMyHaiku/WebContent/WEB-INF/web.xml @@ -0,0 +1,12 @@ + + + VoteMyHaiku + + index.html + index.htm + index.jsp + default.html + default.htm + default.jsp + + \ No newline at end of file diff --git a/VoteMyHaiku/src/vote/engine/VoteServerServlet.java b/VoteMyHaiku/src/vote/engine/VoteServerServlet.java new file mode 100644 index 0000000..b4177ee --- /dev/null +++ b/VoteMyHaiku/src/vote/engine/VoteServerServlet.java @@ -0,0 +1,57 @@ +package vote.engine; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * Servlet implementation class VoteServerServlet + */ +@WebServlet("/vote") +public class VoteServerServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + + /** + * @see HttpServlet#HttpServlet() + */ + public VoteServerServlet() { + super(); + // TODO Auto-generated constructor stub + } + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + String button1 = request.getParameter("smile"); + String button2 = request.getParameter("wait"); + + if (button1 != null) { + out.println(""); + out.println("

Smile!!!

"); + out.println(""); + } + else if (button2 != null){ + out.println(""); + out.println("

Wait!

"); + out.println(""); + } + + } + + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // TODO Auto-generated method stub + } + +}