110 lines
6.9 KiB
HTML
110 lines
6.9 KiB
HTML
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||
|
<html>
|
||
|
<head>
|
||
|
<title>Calculator.java</title>
|
||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||
|
<style type="text/css">
|
||
|
<!--
|
||
|
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||
|
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||
|
.literal {color: #cc7832}
|
||
|
.ST3 {font-family: monospace; font-weight: bold; font-style: italic}
|
||
|
.ST0 {color: #287bde}
|
||
|
.number {color: #6897bb}
|
||
|
.string {color: #6a8759}
|
||
|
.ST1 {color: #ffc66d}
|
||
|
.comment {color: #808080}
|
||
|
.whitespace {color: #505050}
|
||
|
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||
|
.ST4 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||
|
-->
|
||
|
</style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/MP1_FX_CalebFontenot/src/mp1_fx_calebfontenot/Calculator.java</td></tr></table>
|
||
|
<pre>
|
||
|
<span class="comment">/*</span>
|
||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
|
||
|
<span class="comment"> */</span>
|
||
|
<span class="literal">package</span> mp1_fx_calebfontenot;
|
||
|
|
||
|
<span class="comment">import</span> <span class="comment">static</span> <span class="comment">java</span><span class="comment">.</span><span class="comment">lang</span><span class="comment">.</span><span class="comment">Double</span><span class="comment">.</span><span class="comment">parseDouble</span><span class="comment">;</span>
|
||
|
<span class="literal">import</span> javafx.application.Application;
|
||
|
<span class="literal">import</span> javafx.geometry.Pos;
|
||
|
<span class="literal">import</span> javafx.scene.Scene;
|
||
|
<span class="literal">import</span> javafx.scene.control.Button;
|
||
|
<span class="literal">import</span> javafx.scene.control.Label;
|
||
|
<span class="literal">import</span> javafx.scene.control.TextField;
|
||
|
<span class="literal">import</span> javafx.scene.layout.BorderPane;
|
||
|
<span class="literal">import</span> javafx.scene.layout.FlowPane;
|
||
|
<span class="literal">import</span> javafx.scene.layout.HBox;
|
||
|
<span class="literal">import</span> javafx.stage.Stage;
|
||
|
|
||
|
<span class="comment">/**</span>
|
||
|
<span class="comment"> *</span>
|
||
|
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
||
|
<span class="comment">*/</span>
|
||
|
<span class="literal">public</span> <span class="literal">class</span> Calculator <span class="literal">extends</span> Application {
|
||
|
|
||
|
@Override
|
||
|
<span class="literal">public</span> <span class="literal">void</span> <span class="ST1">start</span>(Stage primaryStage) <span class="literal">throws</span> Exception {
|
||
|
FlowPane pane = <span class="literal">new</span> FlowPane();
|
||
|
pane.setHgap(<span class="number">2</span>);
|
||
|
TextField tfNumber1 = <span class="literal">new</span> TextField();
|
||
|
TextField tfNumber2 = <span class="literal">new</span> TextField();
|
||
|
TextField tfResult = <span class="literal">new</span> TextField();
|
||
|
tfNumber1.setPrefColumnCount(<span class="number">3</span>);
|
||
|
tfNumber2.setPrefColumnCount(<span class="number">3</span>);
|
||
|
tfResult.setPrefColumnCount(<span class="number">3</span>);
|
||
|
|
||
|
pane.getChildren().addAll(<span class="literal">new</span> Label(<span class="string">"</span><span class="string">Number 1: </span><span class="string">"</span>), tfNumber1, <span class="literal">new</span> Label(<span class="string">"</span><span class="string">Number 2</span><span class="string">"</span>), tfNumber2, <span class="literal">new</span> Label(<span class="string">"</span><span class="string">Result: </span><span class="string">"</span>), tfResult);
|
||
|
|
||
|
HBox hBox = <span class="literal">new</span> HBox(<span class="number">5</span>);
|
||
|
Button btAdd = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">Add</span><span class="string">"</span>);
|
||
|
Button btSubtract = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">Subtract</span><span class="string">"</span>);
|
||
|
Button btMultiply = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">Multiply</span><span class="string">"</span>);
|
||
|
Button btDivide = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">Divide</span><span class="string">"</span>);
|
||
|
hBox.setAlignment(Pos.<span class="ST2">CENTER</span>);
|
||
|
hBox.getChildren().addAll(btAdd, btSubtract, btMultiply, btDivide);
|
||
|
|
||
|
BorderPane borderPane = <span class="literal">new</span> BorderPane();
|
||
|
borderPane.setCenter(pane);
|
||
|
borderPane.setBottom(hBox);
|
||
|
BorderPane.<span class="ST3">setAlignment</span>(hBox, Pos.<span class="ST2">TOP_CENTER</span>);
|
||
|
|
||
|
Scene scene = <span class="literal">new</span> Scene(borderPane, <span class="number">2</span><span class="number">50</span>, <span class="number">1</span><span class="number">50</span>);
|
||
|
primaryStage.setTitle(<span class="string">"</span><span class="string">Calculator</span><span class="string">"</span>);
|
||
|
primaryStage.setScene(scene);
|
||
|
primaryStage.show();
|
||
|
|
||
|
btAdd.setOnAction(e -> {
|
||
|
tfResult.setText(Double.<span class="ST3">parseDouble</span>(tfNumber1.getText())
|
||
|
+ Double.<span class="ST3">parseDouble</span>(tfNumber2.getText()) + <span class="string">""</span>);
|
||
|
});
|
||
|
|
||
|
btSubtract.setOnAction(e -> {
|
||
|
tfResult.setText(Double.<span class="ST3">parseDouble</span>(tfNumber1.getText())
|
||
|
- Double.<span class="ST3">parseDouble</span>(tfNumber2.getText()) + <span class="string">""</span>);
|
||
|
});
|
||
|
|
||
|
btMultiply.setOnAction(e -> {
|
||
|
tfResult.setText(Double.<span class="ST3">parseDouble</span>(tfNumber1.getText())
|
||
|
* Double.<span class="ST3">parseDouble</span>(tfNumber2.getText()) + <span class="string">""</span>);
|
||
|
});
|
||
|
|
||
|
btDivide.setOnAction(e -> {
|
||
|
tfResult.setText(Double.<span class="ST3">parseDouble</span>(tfNumber1.getText())
|
||
|
/ Double.<span class="ST3">parseDouble</span>(tfNumber2.getText()) + <span class="string">""</span>);
|
||
|
});
|
||
|
|
||
|
}
|
||
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST4">main</span>(String[] args) {
|
||
|
<span class="ST3">launch</span>(args);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
</pre></body>
|
||
|
</html>
|