-->

Tuesday, February 11, 2014

How to Perform Text Interaction with GUI in JAVA Programming part-2

setText()

To be continued from the previous article this method is used for sorting text into a GUI component. In Java Programming, this method is mostly used to store or change text in a text based GUI component. The swing components that support setText()  method include: Text field, Text area, Button, Label, Check Box, and Radio Button.

Suppose you want to change the content of field classTF to ‘XI’ through a code statement; for this you can use setText() method. To change text of classTF field to “XI”, you need to write:

classTF.setText(“XI”)

The setText() changes the value of field before the dot (.) with the string in its parentheses. The value to be set has been given as string constant "XI" in the above statement. You can also use a String value variable to specify the new value, as it is being explained below:

String newValstr = “XI”;
classTF.setText(newValstr);

JOptionPane.showMessageDialog()

The last but not least method for text interaction with GUI is showMethodDialog() which is used to display message in a dialog form.

Using this method, programmer can produce a basic dialog displaying a message to the user. The user will see your message only an "ok" button to close the dialog. To use this method, you need to perform it in two steps:

Firstly, in the Source Editor, where you type your code, at top most position type the following link:
Import javax.swing.JOptionPane;

Now display desired message as per following syntax (please notice carefully the case of letters):
JOptionPane.showMessageDiallog(null,” <desired message here>”);

For example, to display a message “Hello there!” you should write
JoptionPane.showMessageDialloglog(null, “Hello there!”) ;

It will display a separate message dialog displaying your message

How to Create a File System Web Site in Visual Studio

In a file-system Web site, you store the files for your application in a folder on your local computer or on a computer that is accessible on your network. File system Web sites are useful for developing locally on your computer because you do not need Internet Information Services (IIS) to create or test them.

To create a file-system Web site


  1.   In Microsoft Visual Studio, on the File menu, point to New and then click Web Site.
  2. Under Visual Studio installed templates, select the template for the type of web site you want to create.
  3. In the Location list, click File System.
  4. In the language list, click the language you want to use as the default programming language for the Web application.
  5. In the Location text box, type the path and folder where you want to create the Web site. You can specify a local path or a UNC path to a different computer on your network.
  6. If you prefer to browse to an existing location, do the following:
  • Click Browse
  • In the Choose Location dialog box, click the File System tab.
  • In the File System tree, select the folder you want to use or type the path in the folder box.
  • To create a new folder, select the location, click Create New Folder, and then type a name for the new folder.
  • Click Open to return to the New Web Site dialog box.
  1. Click
Visual Studio creates the site, opens a default page in the page designer, and then displays the folder in Solution Explorer.
If the path you specified already contains files, Visual studio prompts you to specify a different location, open the existing web site, or create the Web site anyway. In the last case, the files are created with the Web site overwrite any files with the same name that are already in the folder.

Monday, February 10, 2014

Types of Web Sites in Visual Web Developer

You can use Microsoft Visual Studio to create and work with Microsoft ASP.NET Web Sites (Web applications) in a variety of hosting scenarios: local Internet Information Services(IIS), file system, FTP, and remote sites.
Types of Web Sites in Visual Web Developer

Local IIS Web Sites

Local IIS Web Sites run using a copy of IIS that is installed on your computer. When you create a local IIS Web Site, the pages and folders for your site are stored in a folder under the default IIS folder for Web Sites (Inetpub\wwwroot). Visual Studio also create the appropriate IIS configuration so that the Web Site is recognized by IIS as an application.

Note : To create a local IIS Web Site, you need Administrator privileges on the computer.
Alternatively, you can create an IIS virtual directory in Visual Studio. In this case, the pages and folders for your Web site can be placed in any accessible folder, a virtual directory in your local copy of IIS points to this location.

File System Web Sites

In a file-system Web site, you can create files in any folder you like, whether on your local computer or in a folder on another computer that you access across a network share. You do not need to run IIS on your computer. Instead, you can test pages by using the Visual Studio Development Web Server.

Note : The Visual Studio Development Web Server works locally. It cannot serve pages to another computer and is therefore suitable only for testing pages locally.
If you create a file system Web site, you can later create an IIS virtual directory that points to the Web site.

FTP Sites

Visual Studio allows you to open and edit Web site that are accessible by using an FTP server. This is a typical scenario if your Web site is located on a hosting site.
You can connect from within visual studio to any FTP server on which you have read/write privileges. You can then create and edit Web pages on that server. If the FTP server is configured with ASP.NET and an IIS virtual root that points to the FTP directory, you can also run your pages from the server to test them.

Remote Web Sites

A remote Web Site is a site that uses IIS but is on another computer that you can access over a local area network. The remote computer must have IIS installed and must be configured with Microsoft Office FrontPage Server Extension. When you create a remote Web site, the pages and folders for your site are stored in the default IIS folder on the remote computer. When you run the pages, they are served by using IIS on the remote computer. 

Sunday, February 9, 2014

How to access base class constructor from derived class in C# Programming

Its a concepts of inheritance, child class derived from base class or you can say, a class inherits property from other class known as derived class or child class.
This example cover, If you want to access base class method into child class, you should use base keyword for that. Lets take an simple example to demonstrate of this.

The base class that is accessed is the base class specified in the class declaration. For example, if you specify class childclass : baseclass, the members of baseclass are accessed from childclass, regardless of the base class of baseclass.

Lets take an simple example 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication8
{
    class Program
    {
        public Program ()
        {
            Console .WriteLine ("Base class Constructor");
        }
       
        static void Main(string[] args)
        {

            abc obj = new abc();
            Console.ReadKey();

        }
        
    }
    class abc : Program
    {
        public abc():base()
        {

            Console.WriteLine("Child Class");

          
        }
    }
}

Code Generate the following output 

How to access base class constructor from derived class in C# Programming

How to call base class methods from derived class in c# programming

Its a concepts of inheritance, child class derived from base class or you can say, a class inherits property from other class known as derived class or child class.
This example cover, If you want to access base class method into child class, you should use base keyword for that. lets take an simple example to demonstrate of this.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication8
{
    class Program
    {
       
        static void Main(string[] args)
        {

            abc obj = new abc();
            Console.ReadKey();

        }
        public void getg()
        {
            Console.WriteLine("base class");

        }
    }
    class abc : Program
    {
        public abc()
        {
            base.getg();
            Console.WriteLine("Child class");

          
        }
    }
}

Code generate the following output

How to call base class methods from derived class in c# programming

How to get Total traveling time of Train in c# programming

Its a very easy concepts, finding traveling time, which is travel by a train. Suppose your train arrival Date and time is 2/9/2014  10:47:00 PM and departure date time is 2/8/2014 6:32:00 PM . Now, you want to get total traveling time. Use TimeSpan Structure for getting elapsed time. Lets take an simple example.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication8
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime departure = new DateTime(2014, 2, 8, 18, 32, 0);
            DateTime arrival = new DateTime(2014, 2, 9, 22, 47, 0);
            TimeSpan travelTime = arrival - departure;
            Console.WriteLine("{0} - {1} = {2}", arrival, departure, travelTime);
            Console.ReadKey();
        }
    }
}

Code generate the following output

How to get Total traveling time of Train in c# programming

Saturday, February 8, 2014

DropDownList AutoPostBack, Item, Index and Value in asp.net c#

Introduction

First of all, I would like to thank all of the readers who have read my previous articles. What a great support i have got from you people.I really felt great when use of DropDownlist article was displayed on the dotprogramming page. Following are the articles that I have written so far for beginners.

In this article, we will get DropdownList item text , index value and value of it. Generally, we know that it is bind with ListItem class properties. 

Lets take an simple example 


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Dropdownlist.aspx.cs" Inherits="Dropdownlist" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <strong>Get DropDownList Control&nbsp; Item, Index and value </strong>
        <br />
    </div>
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
        Height="42px" onselectedindexchanged="DropDownList1_SelectedIndexChanged" 
        Width="138px">
            <asp:ListItem>Select Country</asp:ListItem>
            <asp:ListItem Value="Top Country">USA</asp:ListItem>
            <asp:ListItem Value="United State">UK</asp:ListItem>
            <asp:ListItem Value="awsome ">Itly</asp:ListItem>
        </asp:DropDownList>
    <br />
    <br />
    <asp:Label ID="Label1" runat="server"></asp:Label>
    </form>
</body>
</html>

// Code behind code


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Dropdownlist : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Label1.Text = "You selected: <br /> Dropdownlist Text: " +
            DropDownList1.SelectedItem.Text.ToString() +
            "<br />Dropdown Value: " + DropDownList1.SelectedValue.ToString() +
            "<br />Dropdown Index: " + DropDownList1.SelectedIndex.ToString(); 
    }
}

Code generate the following output

DropDownList AutoPostBack, Item, Index and Value in asp.net c#

© Copyright 2013 Computer Programming | All Right Reserved