2015-12-15 HW

posted Dec 15, 2015, 6:24 AM by Samuel Konstantinovich   [ updated Dec 15, 2015, 8:58 AM ]
Homework:
Write static methods CtoF(double t) and FtoC(double t) that converts the given temperature from/to the indicated scale.
CtoF(-40.0) -> -40.0
CtoF(100.0) -> 212.0
FtoC(212.0) -> 100.0

Yesterday:
Discussion on Recursion / Stack vs Heap
Stack Overflow Exception
Why it happens
How memory is organized.

Today:
Basic Window:
import javax.swing.*;
public class Window extends JFrame {
    public Window() {
        this.setTitle("My first GUI");
        this.setSize(600,400);
        this.setLocation(100,100);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
        Window g = new Window();
        g.setVisible(true);
    }
}


Window With some stuff added:

import javax.swing.*;
import java.awt.*;
public class Window2 extends JFrame {
private Container pane;

private JButton b;
private JLabel l;
private JTextField t;
private JCheckBox c;
    public Window2() {
this.setTitle("My first GUI");
this.setSize(600,400);
this.setLocation(100,100);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);


pane = this.getContentPane();
pane.setLayout(new FlowLayout());

b = new JButton("Do Nothing");
l = new JLabel("This is AWESOME! (lies)",null,JLabel.CENTER);
t = new JTextField(12);
c = new JCheckBox("Overclock!!!");
pane.add(l);
pane.add(b);
pane.add(t);
pane.add(c);
}

    public static void main(String[] args) {
        Window2 g = new Window2();
        g.setVisible(true);
    }
}

Comments