-
Notifications
You must be signed in to change notification settings - Fork 158
/
FahrenheitGUI.scm
82 lines (60 loc) · 2.06 KB
/
FahrenheitGUI.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
;; Must be used with Kawa
;;
;; Based on: http://www.cs.dartmouth.edu/~cs5/lectures/0509/FahrenheitGUI.java
;;
;;
;;
(module-name <myprogram>)
(module-compile-options main: #t)
;; import java.awt.*;
;; import java.awt.event.*;
;;import javax.swing.*;
;;
(define JFrame javax.swing.JFrame)
(define JLabel javax.swing.JLabel)
(define JPanel javax.swing.JPanel)
(define JTextField javax.swing.JTextField)
(define WIDTH 300)
(define HEIGHT 75)
(define (fahrenheit2celcius f) (* (- f 32.0) (/ 5.0 9.0)))
;; frame = new JFrame("Temperature Conversion");
;;
(define frame (JFrame "Temperature Conversion"))
;;frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
;;
(frame:setDefaultCloseOperation JFrame:EXIT_ON_CLOSE)
(define inputLabel (JLabel "Enter Fahrenheit temperature (Hit Return to Compute the temperature):"))
;;JLabel outputLabel = new JLabel("Temperature in Celsius: ")
(define outputLabel (JLabel "Temperature in Celsius: "))
(define resultLabel (JLabel "---"))
;; fahrenheit = new JTextField(5);
;;
(define fahrenheit (JTextField 5))
;; panel = new JPanel();
;;
(define panel (JPanel))
;; panel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
(panel:setPreferredSize (java.awt.Dimension WIDTH HEIGHT))
(panel:setBackground java.awt.Color:yellow)
;;(panel:setPreferredSize (new Dimension(WIDTH, HEIGHT))
(panel:add inputLabel)
(panel:add fahrenheit)
(panel:add outputLabel)
(panel:add resultLabel)
(frame:add panel)
(frame:pack)
(define show_frame (lambda () (frame:setVisible #t)))
(define (update-temperature)
(resultLabel:setText
(number->string (fahrenheit2celcius (string->number (fahrenheit:getText))))))
(define-namespace ActionListener <java.awt.event.ActionListener>)
(define-namespace ActionEvent <java.awt.event.ActionEvent>)
; ; fahrenheit.addActionListener(new TempListener());
;;(frame:addActionListener (lambda (evt) (update-temperature)))
;;
(define action-listener
(object (ActionListener)
((action-performed e :: ActionEvent) :: <void>
(update-temperature))))
(fahrenheit:addActionListener action-listener)
(show_frame)