Pages

Rabu, 20 November 2013

UTS Windows Phone

Assalamu'alaikum wr. wb

ketemu kembali dengan saya..... sudah satu minggu kita tidak bertemu, apakah agan-agan kangen dengan saya??? hahaha okey, kali ini saya akan memosting hasil UTS (Ujian Tengah Semester) pada hari jum'at kemaren. yaitu membuat sebuah aplikasi. okey langsing saja kita ke tkp.

gambar dibawah ini merupakan hasil aplikasi yang saya kerjakan kemaren.


nah, seperti yang agan-agan lihat, aplikasi diatas adalah sebuah aplikasi gabungan dari 7 tutorial yang saya posting sebelumnya. yaitu inputan dan output. oke untuk step by stepnya kalian bisa ikuti tutorial seperti dibawah ini.

1. New Project (ctrl+shift+N)
2. Pilih windows Phone App + Visual C#
3. Beri nama project  “CreateAButton” Name project jangan lupa samakan dengan Solution Name
4. Lalu browse dan pilih dimana kita akan menyimpan Folder Project aplikasi yang akan kita buat.
5. Lalu klik OK dan pilih Windows OS 7.1 lalu klik OK

6. buat seperti gambar diatas.
7. setelah itu ketikkan koding berikut pada MainPage.xaml

<phone:PhoneApplicationPage 
    x:Class="project_uts2.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0">
            <TextBlock HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="Masukkan Nama Anda :" VerticalAlignment="Top" Height="31" Width="229"/>
            <TextBox x:Name="NamaTextBox" HorizontalAlignment="Left" Height="72" Margin="-2,45,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="456"/>
            <TextBlock HorizontalAlignment="Left" Margin="10,261,0,0" TextWrapping="Wrap" Text="Genre Anime Yang Anda Sukai :" VerticalAlignment="Top" Width="347"/>
            <Button x:Name="OkeButton" Content="Oke" HorizontalAlignment="Left" Margin="10,122,0,0" VerticalAlignment="Top" Click="OkeButton_Click"/>
            <TextBox x:Name="AnimeTextBox" HorizontalAlignment="Left" Height="72" Margin="22,298,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="112" InputScope="Number"/>
            <Button x:Name="Hapus_Button" Content="Hapus" HorizontalAlignment="Left" Margin="116,122,0,0" VerticalAlignment="Top" Click="Hapus_Button_Click"/>
            <TextBlock x:Name="MyTextBlock" HorizontalAlignment="Left" Margin="10,199,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="57" Width="267"/>
            <TextBlock HorizontalAlignment="Left" Margin="139,298,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="81" Width="267">
            <Run Text="Ket : 1. (Action) 2. (Comedy) 3. (Ecchi) 4. (horror)"/>
            <LineBreak/>
            <Run Text="5. (Romance) 6. (Sci-fii)  "/>
            </TextBlock>
            <Button x:Name="PilihButton" Content="Pilih" HorizontalAlignment="Left" Margin="10,375,0,0" VerticalAlignment="Top" Click="Button_Click_1" Height="71"/>
            <TextBlock x:Name="MyTextBlock2" HorizontalAlignment="Left" Margin="110,384,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="276" Height="38"/>
            <Button x:Name="WaktuButton" Content="Waktu" HorizontalAlignment="Left" Margin="10,427,0,0" VerticalAlignment="Top" Click="WaktuButton_Click"/>
            <TextBlock x:Name="MyTextBlock3" HorizontalAlignment="Left" Margin="134,449,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="28" Width="296"/>
            <Button x:Name="AngkaButton" Content="Angka" HorizontalAlignment="Left" Margin="5,499,0,0" VerticalAlignment="Top" Click="AngkaButton_Click"/>
            <TextBox x:Name="AngkaTextBox" HorizontalAlignment="Left" Height="72" Margin="110,499,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="159" InputScope="Number"/>
            <TextBlock x:Name="MyTextBlock4" HorizontalAlignment="Left" Margin="274,499,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="156" Height="98"/>
        </Grid>
    </Grid>
 
</phone:PhoneApplicationPage>

8. lalu ketikkan kode pada MainPage.xaml.cs seperti dibawah ini

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace project_uts2
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        private void OkeButton_Click(object sender, RoutedEventArgs e)
        {
            string newValue;
            newValue = NamaTextBox.Text;
            MyTextBlock.Text = "Nama : " + newValue;
        }

        private void Hapus_Button_Click(object sender, RoutedEventArgs e)
        {
            NamaTextBox.Text = " ";
            MyTextBlock.Text = " ";
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            string message;
            switch (AnimeTextBox.Text)
            {
                case "1":
                    message = "Anda suka genre Action";
                    break;
                case "2":
                    message = "Anda suka genre Comedy";
                    break;
                case "3":
                    message = "Anda suka genre Ecchi";
                    break;
                case "4":
                    message = "Anda suka genre Horror";
                    break;
                case "5":
                    message = "Anda suka genre Romance";
                    break;
                case "6":
                    message = "Anda suka genre Sci-Fii";
                    break;
                default:
                    message = "Angka yang anda masukkan salah mas!";
                    break;
            }

            MyTextBlock2.Text = message;

        }

        private void WaktuButton_Click(object sender, RoutedEventArgs e)
        {
            DateTime myTime = DateTime.Now;
            MyTextBlock3.Text = string.Format("Tanggal {0} , Waktu {1}", myTime.ToShortDateString(), myTime.ToShortTimeString());
        }

        private void AngkaButton_Click(object sender, RoutedEventArgs e)
        {
            string message = "";

            int limit = int.Parse(AngkaTextBox.Text);
            for (int i = 0; i < 5; i++)
            {
                message = message + i.ToString() + System.Environment.NewLine;
            }

            MyTextBlock4.Text = message;
        }
    }
}

9. lalu jalankan emulatornya dan hasilnya akan seperti gambar dibawah ini. 


Mungkin hanya sekian postingan dari saya, mohon maaf apabila ada kesalahan kata yang kurang berkenan di hati agan-agan sekalian. saya pribadi mohon undur diri, sampai ketemu di tutorial-tutorial windows phone selanjutnya.

Wassalamu'alaikum wr. wb

0 komentar:

Posting Komentar