Belajardengan.com merupakan domain blog lama dari delajardengan.blogspot.com. Mohon kritik dan sarannya untuk perkembangan blog ini.
email: blog.tkx.pnp@gmail.com

Memulai Firefox OS

♠ Posted by Unknown in

Memulai Firefox OS

Banyak orang bertanya, bagaimana memulai firefox OS....  Perlu diketahui OS Firefox itu ibaratkan 'browser'.. jadi dia dia bisa ngejalanin halaman web. End yang dibutuhkan untuk menjalankan halaman web tersebut dibutuhkan file 'manifest.webapp', dimana halaman ini menjadi acuan or pengaturan halaman yang akan ditampilkan

berikut contoh sederhananya.

  • bikin halaman manifest. manifest.webapp seperti dibawah:

  • bikin halaman index.html seperti dibawah:

  • buka tool firefox simulator yang udah diinsatall Firefox OSnya. Klik "Add Directory" cari file "manifest.webapp" dan OK. Klo ada kesalahan akan tampil pesan erorr di list. Klik "Connect"
  • maka emulator akan jalan dan menginstall halaman web yang telah dibuat tadi.
  • berikut tampilannya

  • apabila link di klik maka akan muncul halaman seperti gambar. (apabila punya koneksi internet)


Dasar JEE : Pengalihan Response

♠ Posted by Unknown in
Latihan dasar JEE #1

Pada J2EE terdapat 2 methos pangalihan resposse:

  1. RequestDispacher
  2. Send Direct

Request Dispacher
Kali ini saya akan mencoba membuat sebuah form login sederhana. Disini terdapat dua buah inputtan, yaitu:
1. namauser
2. password
apabila user masuk sebagai admin maka akan dialihkan ke admin.jsp, apabia user memasukkan salah maka akan di alihkan kembali ke halaman login

index.jsp
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>login</h1>
        <form action="LoginDispacher" method="POST">
            <fieldset>
                UserName : <input type="text" name="nama" value="" />
            </fieldset>
            <fieldset>
                Password : <input type="password" name="pass" value="" />
            </fieldset>
            <fieldset>
                <input type="submit" value="Login" />
            </fieldset>
        </form>
    </body>
</html>

admin.jsp
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Halaman Admin</title>
    </head>
    <body>
        <h1> Anda Login sebagai "Admin"</h1>
        
    </body>
</html>

user.jsp
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>User Page</title>
    </head>
    <body>
        <h1>Anda login sebagai "Users"</h1>
    </body>
</html>

Login.java ---> servlet
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String username= request.getParameter("nama");
        String password= request.getParameter("pass");
        RequestDispatcher dis=null;
        if(username.equalsIgnoreCase("admin")&&password.equals("admin")){
            dis= request.getRequestDispatcher("/admin.jsp");
        }else if(username.equalsIgnoreCase("user")&&password.equals("user")){
            dis =request.getRequestDispatcher("/user.jsp");
        }else{
            out.println("Login Salah");
            dis = request.getRequestDispatcher("/index.jsp");
        }
        dis.include(request, response);
    }




apabila pada baris 'dis.include(request, response);' login.java(servlet) diganti dengan 'dis.forward(request, response);' tulisan login salah tidak akan include ke login.

Send Direct
untuk penggunaan method sendDirect kita tinggal ganti login.java (servlet) jadi seperti :
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String username= request.getParameter("nama");
        String password= request.getParameter("pass");
        //RequestDispatcher dis=null;
        if(username.equalsIgnoreCase("admin")&&password.equals("admin")){
            //dis= request.getRequestDispatcher("/admin.jsp");
            response.sendRedirect("admin.jsp");
        }else if(username.equalsIgnoreCase("user")&&password.equals("user")){
            //dis =request.getRequestDispatcher("/user.jsp");
            response.sendRedirect("user.jsp");
        }else{
            out.println("Login Salah");
            //dis = request.getRequestDispatcher("/index.jsp");
            response.sendRedirect("index.jsp");
        }
        //dis.forward(request, response);
    }

Perbedaan Pengalihan response dengan method Dispacher dan sendDirect adalah terdapat pada tampilan url di Browser......


Simple Parsing Data XML http://maps.googleapis.com/

♠ Posted by Unknown in ,
Kali ini saya akan sedikit share bagaimana parsing data xml dengan "Xml.Linq" untuk mendapat data nama Provinsi, Kota, Sub_Kota dari kordinat longitude dan latitude yang didapat  dari GPS.

contoh : http://maps.googleapis.com/maps/api/geocode/xml?latlng=-6.1333,106.7500&sensor=true
ini adalah koordinat salah satu daerah Tanah Datar, Sumatera Barat

    public partial class MainPage : PhoneApplicationPage

    {
        // Constructor
        private WebClient m_myWebClient;
        public MainPage()
        {
            InitializeComponent();
            m_myWebClient = new WebClient();
            string url = "http://maps.googleapis.com/maps/api/geocode/xml?latlng=-0.3056,100.3692&sensor=true";
            Uri uri = new Uri(url);
            m_myWebClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(myWebClient_DownloadStringCompleted);
            m_myWebClient.AllowReadStreamBuffering = true;
            m_myWebClient.DownloadStringAsync(uri);
        }

        private void myWebClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            XDocument ListArray = XDocument.Parse(e.Result);
            string a = e.Result;
            //ListArray.Element("GeocodeResponse").Element("result").Element("address_component").Value;
            //var ss = from x in ListArray.Descendants("GeocodeResponse") select x.Attribute("administrative_area_level_1");
            string SubCity = ListArray.Descendants("type").FirstOrDefault(x => x.Value == "administrative_area_level_3").Parent.Element("long_name").Value;
            string City = ListArray.Descendants("type").FirstOrDefault(x => x.Value == "administrative_area_level_2").Parent.Element("long_name").Value;
            string Provincy = ListArray.Descendants("type").FirstOrDefault(x => x.Value == "administrative_area_level_1").Parent.Element("long_name").Value;
        }
    }
   
Terima Kasih
:)


Link Untuk Belajar

♠ Posted by Unknown in

Link Untuk Belajar

http://msdn.microsoft.com/en-us/library/zd5e2z84.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1

Windows Phone || Contoh Simple Binding List

♠ Posted by Unknown in

Contoh Simple Binding List Windows Phone

MainPage.xaml
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Button Command="{Binding Tambah}" Content="Button" HorizontalAlignment="Left" Margin="336,-126,0,0" VerticalAlignment="Top"/>
            <ListBox ItemsSource="{Binding L_classnama}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal" Width="400" Background="Goldenrod" Margin="0,0,0,5">
                            <!-- Binding Source Gambar -->
                            <Image Margin="20,0,0,0" Height="60" Width="60" Source="{Binding Gambar}"></Image>
                            <!-- Binding TextBlock -->
                            <TextBlock Text="{Binding Nama}" TextWrapping="Wrap" FontSize="30" Style="{StaticResource PhoneTextExtraLargeStyle}" FontFamily="Comic Sans MS"/>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>

MainPage.xaml.cs

public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            DataContext = new MAinPageViewModle();
        }
    }


MAinPageViewModle

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
namespace Bi
{
    class MAinPageViewModle : Microsoft.Practices.Prism.ViewModel.NotificationObject
    {
        public List<ClassNama> L_classnama{get;set;}
        private Microsoft.Practices.Prism.Commands.DelegateCommand _tambah;
        void TambahAction() {
            L_classnama = new List<ClassNama>();
            L_classnama.Add(new ClassNama() { Nama = "xxxx", Gambar = "unduhan.jpg" });
            L_classnama.Add(new ClassNama() { Nama = "xx", Gambar = "unduhan.jpg" });
            L_classnama.Add(new ClassNama() { Nama = "xxx", Gambar = "unduhan.jpg" });
            Console.WriteLine("asssssssssssssssssssssssssssss");
            RaisePropertyChanged("");
        }
        public Microsoft.Practices.Prism.Commands.DelegateCommand Tambah
        {
            get { return _tambah; }
        }
        public MAinPageViewModle(){
            _tambah = new Microsoft.Practices.Prism.Commands.DelegateCommand(TambahAction);
            L_classnama = new List<ClassNama>();
            L_classnama.Add(new ClassNama() { Nama = "asdasdas" ,Gambar="unduhan.jpg"});
            L_classnama.Add(new ClassNama() { Nama = "asdasdas", Gambar = "unduhan.jpg" });
            L_classnama.Add(new ClassNama() { Nama = "asdasdas", Gambar = "unduhan.jpg" });
            L_classnama.Add(new ClassNama() { Nama = "asdasdas", Gambar = "unduhan.jpg" });
            L_classnama.Add(new ClassNama() { Nama = "asdasdas", Gambar = "unduhan.jpg" });
            L_classnama.Add(new ClassNama() { Nama = "asdasdas", Gambar = "unduhan.jpg" });
        }
    }  
}
 
ClassNama

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Bi
{
    class ClassNama  : Microsoft.Practices.Prism.ViewModel.NotificationObject
    {
        private string _nama;
        private string _gambar;
        public string Nama { get { return _nama; } set { _nama = value; RaisePropertyChanged(""); } }
        public string Gambar { get { return _gambar; } set { _gambar = value; RaisePropertyChanged(""); } }
    }
}





Dapatkan nama file dari url C#

♠ Posted by Unknown in

Dapatkan nama file dari url C#

public string GetFileName {             
            get{
                string URL = "http://vendyxiao.com/wp-content/uploads/2011/09/facebook_icon.png";
                _getNameFile = URL.Substring(URL.LastIndexOf("/") + 1, (URL.Length - URL.LastIndexOf("/") - 1));
                return _getNameFile;
            }
            set {
                _getNameFile = value;
            }
        }

Windows Phone || Save Image from Url

♠ Posted by Unknown in

Save Image from Url


using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using SaveImageHttptoIso2.Resources;
using System.Windows.Media.Imaging;
using System.IO;
using System.IO.IsolatedStorage;
using System.Threading;
using Microsoft.Xna.Framework.Media;
using System.Windows.Resources;

namespace SaveImageHttptoIso2
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            Uri uri = new Uri("http://www.english.cam.ac.uk/pop/images/google_icon.png", UriKind.Absolute);
            xxx.Source = new BitmapImage(uri);

            var webClient = new WebClient();
            webClient.OpenReadCompleted += WebClientOpenReadCompleted;
            webClient.OpenReadAsync(new Uri("http://www.english.cam.ac.uk/pop/images/google_icon.png", UriKind.Absolute));
        }

        void WebClientOpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            const string tempJpeg = "TempJPEG.jpg";
            var streamResourceInfo = new StreamResourceInfo(e.Result, null);

            var userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication();
            if (userStoreForApplication.FileExists(tempJpeg))
            {
                userStoreForApplication.DeleteFile(tempJpeg);
            }

            var isolatedStorageFileStream = userStoreForApplication.CreateFile(tempJpeg);

            var bitmapImage = new BitmapImage { CreateOptions = BitmapCreateOptions.None };
            bitmapImage.SetSource(streamResourceInfo.Stream);

            var writeableBitmap = new WriteableBitmap(bitmapImage);
            writeableBitmap.SaveJpeg(isolatedStorageFileStream, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 0, 85);

            
    }
}

Simple Binding Image Windows Phone Isolatedstorage

♠ Posted by Unknown in

Simple Binding Image Windows Phone Isolatedstorage


MainPage.xaml

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <TextBox HorizontalAlignment="Left" Height="72" Margin="10,10,-10,0" TextWrapping="Wrap" Text="{Binding Nama, Mode=TwoWay}" VerticalAlignment="Top" Width="456"/>
            <TextBox HorizontalAlignment="Left" Height="72" Margin="10,82,-10,0" TextWrapping="Wrap" Text="{Binding Password, Mode=TwoWay}" VerticalAlignment="Top" Width="456"/>
            <Button Command="{Binding Save, Mode=TwoWay}" Content="Button" HorizontalAlignment="Left" Margin="158,178,0,0" VerticalAlignment="Top"/>
            <Button Content="Netxt" HorizontalAlignment="Left" Margin="187,311,0,0" VerticalAlignment="Top" Click="Button_Click_1"/>
        </Grid>

---
Page1.xaml

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <TextBlock HorizontalAlignment="Left" Margin="73,40,0,0" TextWrapping="Wrap" Text="{Binding Iso, Mode=OneTime}" VerticalAlignment="Top" Width="275"/>
            <Image Source="{Binding ThumbImage}" HorizontalAlignment="Left" Height="100" Margin="182,176,0,0" VerticalAlignment="Top" Width="100"/>
        </Grid>

---

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.IO.IsolatedStorage;
using System.Windows.Media.Imaging;
using System.IO;
using System.Windows.Resources;
using System.Windows;
namespace lainPageIso
{
    class MainViewModel : INotifyPropertyChanged
    {
        private string _nama, _password;

        private System.Windows.Input.ICommand _save;
 
        public MainViewModel(){
            this._save = new DelegateCommand(this.SaveAction);
        }

        public string Nama {
            get { return _nama; }
            set { _nama = value; RaisePropertyChanged(""); }
        }

        public string Password
        {
            get { return _password; }
            set { _password = value; RaisePropertyChanged(""); }
        }

        public void SaveAction(object p) {

            IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
            StreamWriter streamWriter = null;
            if (!isf.FileExists("coba.txt"))
            {
                isf.CreateFile("coba.txt");
            }
            else {
                streamWriter = new StreamWriter(new IsolatedStorageFileStream("coba.txt",FileMode.Open,isf));
             
            }
            streamWriter.WriteLine(_nama+""+_password);
            streamWriter.Close();
            saveImage();
            RaisePropertyChanged("");
        }

        public System.Windows.Input.ICommand Save {
            get {
                return _save;
            }
        }

        void saveImage() {
            String tempJPEG = "logo.jpg";

            // Create virtual store and file stream. Check for duplicate tempJPEG files.
            using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (myIsolatedStorage.FileExists(tempJPEG))
                {
                    myIsolatedStorage.DeleteFile(tempJPEG);
                }

                IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(tempJPEG);

                StreamResourceInfo sri = null;
                Uri uri = new Uri(tempJPEG, UriKind.Relative);
                sri = Application.GetResourceStream(uri);

                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(sri.Stream);
                WriteableBitmap wb = new WriteableBitmap(bitmap);

                // Encode WriteableBitmap object to a JPEG stream.
                Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);

                //wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
                fileStream.Close();
            }
        }


        public event PropertyChangedEventHandler PropertyChanged;

        private void RaisePropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = this.PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}

---

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO.IsolatedStorage;
using System.Windows.Media.Imaging;
using System.IO;
using System.ComponentModel;

namespace lainPageIso
{
    class Page1ViewModel : INotifyPropertyChanged
    {
        IsolatedStorageFile get = IsolatedStorageFile.GetUserStoreForApplication(); 
        string x   ="";

        public Page1ViewModel() {
            if (get.FileExists("coba.txt"))
            {
                try
                {
                    StreamReader read = new StreamReader(new IsolatedStorageFileStream("coba.txt", FileMode.Open, get));
                    x = read.ReadLine();
                    read.Close();
                }
                catch (Exception ex)
                {
                }

            }
            if (get.FileExists("logo.jpg"))
            {
                x += " image ada";
            }
        }
        public string Iso {         
            
            get { return x; } 
        }

        void readImage() {
            BitmapImage bi = new BitmapImage();

            using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("logo.jpg", FileMode.Open, FileAccess.Read))
                {
                    //bi.SetSource(fileStream);
                    //img.Width = bi.PixelWidth;
                }
            }
            //this.img.Source = bi;
        }

        private string _thumbFileName;
        public string ThumbFileName
        {
            get
            {
                return _thumbFileName;
            }
            set
            {
                _thumbFileName = value;
                RaisePropertyChanged("ThumbFileName");
                RaisePropertyChanged("ThumbImage");
            }
        }

        public BitmapImage ThumbImage
        {
            get
            {
                BitmapImage image = new BitmapImage();
                IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
                string isoFilename = ThumbFileName;
                var stream = isoStore.OpenFile("logo.jpg", System.IO.FileMode.Open);
                image.SetSource(stream);
                return image;
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void RaisePropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = this.PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}






Windows Phone || INotifyPropertyChanged

♠ Posted by Unknown in

INotifyPropertyChanged


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Collections.ObjectModel;
namespace PhoneApp2
{
    class DataBinding2 : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        private int _nama,_a,_b,_c;
        public int Nama {
            get {
                return _nama;
            }
            set {
                _nama = value;
                _nama = _nama * 5;
                berubah("Nama");
            }
        }

        public int A {
            get
            {
                return _a;
            }
            set
            {
                _a = value;
                berubah("");
            }
        }

        public int B
        {
            get
            {
                return _b;
            }
            set
            {
                _b = value;
                berubah("");
            }
        }

        public int C
        {
            get
            {
                return _c=_a+_b;
            }
            set
            {
                _c = value;
                berubah("");
            }
        }
        void berubah(string a) {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(a));
            }
        }
    }
}



------------------


<phone:PhoneApplicationPage
    x:Class="PhoneApp2.Page1"
    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"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d"
    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 Grid.Row="0" Margin="12,17,0,28">
            <TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock 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,12,0">
            <Button Content="Button" HorizontalAlignment="Left" Margin="153,31,0,0" VerticalAlignment="Top" />
            <TextBox Text="{Binding Nama}" HorizontalAlignment="Left" Height="72" Margin="0,133,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="456"/>
            <TextBox HorizontalAlignment="Left" Height="72" Margin="0,205,0,0" TextWrapping="Wrap" Text="{Binding A, Mode=TwoWay}" VerticalAlignment="Top" Width="456"/>
            <TextBox HorizontalAlignment="Left" Height="72" Margin="0,265,0,0" TextWrapping="Wrap" Text="{Binding B, Mode=TwoWay}" VerticalAlignment="Top" Width="456"/>
            <TextBox HorizontalAlignment="Left" Height="72" Margin="0,342,0,0" TextWrapping="Wrap" Text="{Binding C, Mode=TwoWay}" VerticalAlignment="Top" Width="456"/>
        </Grid>
        <Button Content="Button" HorizontalAlignment="Left" VerticalAlignment="Top"/>
    </Grid>

</phone:PhoneApplicationPage>