From f7794fe996d61c6154c33e585f4090bd5acf3f2a Mon Sep 17 00:00:00 2001 From: Alex Bates Date: Wed, 27 Sep 2023 15:12:46 +0100 Subject: [PATCH] implement examples --- .editorconfig | 12 +++++ src/lib/repl/Sidebar.svelte | 2 +- src/lib/repl/sidebar/Examples.svelte | 51 +++++++++++++++++++++ src/lib/repl/sidebar/SidebarOptions.svelte | 3 ++ static/examples/hello-world-swing/Main.java | 20 ++++++++ static/examples/hello-world/Main.java | 5 ++ 6 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 .editorconfig create mode 100644 src/lib/repl/sidebar/Examples.svelte create mode 100644 static/examples/hello-world-swing/Main.java create mode 100644 static/examples/hello-world/Main.java diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..e98035c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +indent_style = tab +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = false +insert_final_newline = true + +[*.java] +indent_style = space +indent_size = 4 diff --git a/src/lib/repl/Sidebar.svelte b/src/lib/repl/Sidebar.svelte index 620062c..310836b 100644 --- a/src/lib/repl/Sidebar.svelte +++ b/src/lib/repl/Sidebar.svelte @@ -22,7 +22,7 @@
-
+
$isSidebarOpen = true} />
{#if $isSidebarOpen} diff --git a/src/lib/repl/sidebar/Examples.svelte b/src/lib/repl/sidebar/Examples.svelte new file mode 100644 index 0000000..9931f07 --- /dev/null +++ b/src/lib/repl/sidebar/Examples.svelte @@ -0,0 +1,51 @@ + + +{#each examples as fiddle} + +{:else} +
+ +
+{/each} diff --git a/src/lib/repl/sidebar/SidebarOptions.svelte b/src/lib/repl/sidebar/SidebarOptions.svelte index d3efc01..b5a2cf2 100644 --- a/src/lib/repl/sidebar/SidebarOptions.svelte +++ b/src/lib/repl/sidebar/SidebarOptions.svelte @@ -3,6 +3,7 @@ import { createEventDispatcher } from "svelte"; import Favourites from "./Favourites.svelte"; import { browser } from "$app/environment"; + import Examples from "./Examples.svelte"; const dispatch = createEventDispatcher<{ selectOption: number }>(); @@ -41,6 +42,8 @@
{#if selectedOptionIndex === 0} + {:else if selectedOptionIndex === 1} + {/if} {:else}
    diff --git a/static/examples/hello-world-swing/Main.java b/static/examples/hello-world-swing/Main.java new file mode 100644 index 0000000..52f5e90 --- /dev/null +++ b/static/examples/hello-world-swing/Main.java @@ -0,0 +1,20 @@ +import java.awt.Font; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.SwingUtilities; + +class Main implements Runnable { + public static void main(String[] args) { + SwingUtilities.invokeLater(new Main()); + } + + public void run() { + JFrame f = new JFrame("Swing example"); + JLabel l = new JLabel("Hello, world!"); + l.setFont(new Font("Serif", Font.PLAIN, 42)); + f.add(l); + f.pack(); + f.setLocationRelativeTo(null); + f.setVisible(true); + } +} diff --git a/static/examples/hello-world/Main.java b/static/examples/hello-world/Main.java new file mode 100644 index 0000000..53eaf6a --- /dev/null +++ b/static/examples/hello-world/Main.java @@ -0,0 +1,5 @@ +class Main { + public static void main(String[] args) { + System.out.println("Hello, World!"); + } +}