Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changes from Version 1 of DflMiniCalc

Show
Ignore:
Author:
jcc7 (IP: 68.97.93.38)
Timestamp:
11/12/05 04:31:47 (18 years ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DflMiniCalc

    v0 v1  
     1= DFL Mini-Calc = 
     2 
     3''Part of'' DflCategory 
     4 
     5== Description == 
     6 
     7Demonstrates very simple calculator with two buttons and three input fields. Equivalent to Win32 api MiniCalcExample example. 
     8 
     9== Example == 
     10 
     11{{{ 
     12#!d 
     13// To compile: 
     14// dmd DflMiniCalc.d dfl.lib -L/exet:nt/su:windows:4.0 
     15 
     16private import dfl.all; 
     17 
     18private import std.string; 
     19 
     20class MiniCalcForm: Form 
     21{ 
     22  this() 
     23  { 
     24    text = "DflMiniCalc"; 
     25    CreateControls();        
     26 
     27    acceptButton = plusButton; 
     28  } 
     29     
     30  private void CreateControls() 
     31  { 
     32    size = Size(120, 150);  // Overall form size 
     33 
     34    plusButton = new Button; 
     35    plusButton.parent = this; 
     36    plusButton.text = "Plus"; 
     37    plusButton.left = 10; 
     38    plusButton.size = Size(50, 25); 
     39    plusButton.click ~= &PlusClick; 
     40 
     41    minusButton = new Button; 
     42    minusButton.parent = this; 
     43    minusButton.text = "Minus"; 
     44    minusButton.left = 60; 
     45    minusButton.size = Size(50, 25); 
     46    minusButton.click ~= &MinusClick; 
     47 
     48    firstNumberText = new TextBox; 
     49    firstNumberText.parent = this; 
     50    firstNumberText.text = "170"; 
     51    firstNumberText.location = Point(10, 30); 
     52    firstNumberText.size = Size(100, 20); 
     53 
     54    secondNumberText = new TextBox; 
     55    secondNumberText.parent = this; 
     56    secondNumberText.text = "252"; 
     57    secondNumberText.location = Point(10, 55); 
     58    secondNumberText.size = Size(100, 20); 
     59 
     60    resultNumberText = new TextBox; 
     61    resultNumberText.parent = this; 
     62    resultNumberText.text = ""; 
     63    resultNumberText.location = Point(10, 80); 
     64    resultNumberText.size = Size(100, 20); 
     65  } 
     66     
     67  private void PlusClick(Object sender, EventArgs ea) 
     68  { 
     69    GetNumbers(); 
     70    result = num1 + num2; 
     71    resultNumberText.text = std.string.toString(result); 
     72  } 
     73 
     74  private void MinusClick(Object sender, EventArgs ea) 
     75  { 
     76    GetNumbers(); 
     77    result = num1 - num2; 
     78    resultNumberText.text = std.string.toString(result); 
     79  } 
     80 
     81  private void GetNumbers() 
     82  { 
     83    char[] firstValue = firstNumberText.text; 
     84    char[] secondValue = secondNumberText.text; 
     85    num1 = atoi(firstValue); 
     86    num2 = atoi(secondValue); 
     87  } 
     88 
     89  private TextBox firstNumberText; 
     90  private TextBox secondNumberText; 
     91  private TextBox resultNumberText; 
     92  private Button  plusButton; 
     93  private Button  minusButton; 
     94  private long    num1; 
     95  private long    num2; 
     96  private long    result; 
     97} 
     98 
     99 
     100int main() 
     101{ 
     102  Application.run(new MiniCalcForm);     
     103  return 0; 
     104} 
     105}}} 
     106 
     107== Source == 
     108 
     109|| Link || http://www.dsource.org/tutorials/index.php?show_example=135 || 
     110|| Posted by || Lynn || 
     111|| Date/Time || Wed Dec 22, 2004 8:41 am ||