Skip to main content

Section 5.1 ActiveCode

Python programs are made interactive in HTML, on request.

Listing 5.1.1. An interactive Python program, using Runestone

A C program will only be interactive if hosted on a Runestone server.

#include <stdio.h>

int main(void)
{
    puts("Hello, world!");
}
Listing 5.1.2. An C program, interactive on a Runestone server

A Java program will only be interactive if hosted on a Runestone server.

import javax.swing.JFrame;  //Importing class JFrame
import javax.swing.JLabel;  //Importing class JLabel
public class HelloWorld {
    public static void main(String[] args) {
        JFrame frame = new JFrame();           //Creating frame
        frame.setTitle("Hi!");                 //Setting title frame
        frame.add(new JLabel("Hello, world!"));//Adding text to frame
        frame.pack();                          //Setting size to smallest
        frame.setLocationRelativeTo(null);     //Centering frame
        frame.setVisible(true);                //Showing frame
    }
}
Listing 5.1.3. A Java program, interactive on a Runestone server

Javascript programs are made interactive in HTML, on request.

Listing 5.1.4. An interactive JavaScript program, using Runestone

A <program> is not interactive, by default, no matter where it is hosted.

import javax.swing.JFrame;  //Importing class JFrame
import javax.swing.JLabel;  //Importing class JLabel
public class HelloWorld {
    public static void main(String[] args) {
        JFrame frame = new JFrame();           //Creating frame
        frame.setTitle("Hi!");                 //Setting title frame
        frame.add(new JLabel("Hello, world!"));//Adding text to frame
        frame.pack();                          //Setting size to smallest
        frame.setLocationRelativeTo(null);     //Centering frame
        frame.setVisible(true);                //Showing frame
    }
}
Listing 5.1.5. A static Java program

An Octave program will only be interactive if hosted on a Runestone server. Octave is meant to be a drop-in replacement for Matlab.

x = 2 + 2
printf("%d\n", x)
Listing 5.1.6. A simple Octave program

A language not supported by Runestone Services will be rendered static.

program HelloWorld;
begin
  WriteLn('Hello, world!');
end.
Listing 5.1.7. A Pascal program that cannot be interactive on Runestone

A nonsense paragraph just to check on spacing. A nonsense paragraph just to check on spacing. A nonsense paragraph just to check on spacing. A nonsense paragraph just to check on spacing.