Archive for April, 2010


Apple Inc has announced that it will be shutting down its online music service Lala on May 31st. We still do not have any convincing reasons for such a move from Apple. Meanwhile, Techcrunch has reported that the possible reason could be that Apple is preparing for an “iTunes-in-the-cloud” offering.

Continue Reading »

[marketwire] After an initial drop, texting while driving appears to be on the rise 15 months after California's texting ban was implemented, according to the Automobile Club of Southern California's latest observational roadside survey of drivers. The Auto Club analysis is the first examination of the long-term effects of a U.S. texting law.

Before the texting law went into effect in January 2009, three Auto Club surveys conducted in mid- to late 2008 showed consistently that about 1.4% of motorists were texting at any point in time. Two surveys conducted shortly after the texting ban (May and July 2009) showed that texting (or manipulating electronic devices) had dropped about 70%, to about 0.5%. The Club's latest survey, conducted in late March and early April 2010, shows that texting has more than doubled from the earlier studies -- to 1.1%.

"These results are disappointing," said Steven Bloch, Ph.D., the Auto Club's senior researcher. Many studies clearly demonstrate the risks related to texting while driving, he said. One study shows texting and driving raises the probability of a crash eight-fold, while another shows it increases a truck driver's chance of being in a crash by a factor of 24. Researchers call texting a "perfect storm," because drivers take their hands off the steering wheel and their eyes and minds are off the road.

"The fact that we're seeing a statistically significant rise in texting despite the state ban indicates that additional efforts are needed to help deal with the problem," said Bloch. "It's just over a year after California's texting ban was implemented, and texting is rising toward the level it was before the law."

One approach is for law enforcement to issue more citations. However, it's difficult for law enforcement agencies to cite texting motorists. Drivers typically hold devices in their lap, making it hard for law enforcement to see what motorists are doing. Texting citations are often given out by motorcycle officers, who have a better view of driver actions.

Because of this challenge, the California Highway Patrol reports issuing an average of only about 150 citations per month since the texting ban went into effect. By comparison, over the past year, the CHP issued about 11,600 hand-held cell phone citations each month.

"Agencies may need to rethink how they cite drivers for texting," said Bloch. "A targeted New Jersey enforcement program uses officers standing on street corners, to locate, pull over and cite cell phoning and texting drivers. That method of enforcement may be more effective."

A second way to deter drivers from texting is by increasing penalties. The Auto Club is currently
supporting SB 1475 (Sen. Joe Simitian, D-Palo Alto) that increases the texting fine to $100 (plus penalty assessments), up from $20 for a first offense and $50 for subsequent offenses. The bill also imposes a point on a motorist's driving record.

"Moving violations typically require the DMV to impose a point, and there is little reason that this dangerous traffic violation should be treated differently than others," said Bloch. "Studies have established that imposing points on driving records is a very effective deterrent to hazardous driving."

Courts and juries are also recognizing the danger of texting and driving, and are increasing punishments. In one case, Martin Kuehl, 42, of Costa Mesa, this month was sentenced to four years in prison for killing a pedestrian while texting and driving. The prosecutor used cell phone records and witness accounts to show that Kuehl was texting behind the wheel during the half-hour leading up to the fatal crash.

The Auto Club survey of drivers also examined their level of hand-held and hands-free cell phone use. These results show little change in use levels since the last surveys were conducted in 2009. In the latest survey, hand-held cell phone use was 3.6%, about 60 percent lower than before the state cell phone law went into effect in July 2008. In the four post-law surveys, hand-held cell phone use ranged from 3.1 to 3.9 percent.

The Auto Club and AAA are using educational approaches to help drivers recognize the risks of being distracted while driving. The AAA Foundation for Traffic Safety and AAA called on all drivers to pledge their participation in Heads Up Driving Week last October. Drivers were asked to rethink their driving behavior by taking the first step toward becoming distraction-free and trying it for a week, and then doing it for life.

Auto Club Study: Texting While Driving on the Rise
[prnewswire] The mobile communications markets of Botswana, Namibia, Zambia and Zimbabwe have all experienced subscriber growth over ten percent in the last five years. This has created a powerful network effect, which continues to drive market growth, albeit at lower levels. Value-added and data services are increasingly becoming revenue drivers, particularly in competitive markets such as Botswana and Namibia, which have high mobile penetration levels.

New analysis from Frost & Sullivan (http://www.wireless.frost.com), Southern African Mobile Communications Market, finds that Zambia currently contributes almost half of all revenues in these four countries, followed by Botswana with 26 per cent. This is expected to change by 2015 when Zambia's share will reduce to 38 per cent, but Zimbabwe will contribute one third of the total revenues.

If you are interested more information on this study, please send an e-mail to Patrick Cairns, Corporate Communications, at patrick.cairns@frost.com, with your full name, company name, title, telephone number, company e-mail address, company website, city, state and country.

"These countries differ significantly in the state of their mobile communication markets," notes Frost & Sullivan industry analyst Protea Hirschel. "Botswana and Namibia are characterised by high mobile penetration rates, which is more than 100 per cent in the case of Botswana. The small addressable markets in these two countries constrain long-term growth and the average revenue per user (ARPU) for voice is declining due to greater competition. Therefore, mobile operators are focused on retention strategies and extending data offerings to protect their market shares."

However, Zambia and Zimbabwe have much lower mobile penetration rates with a high demand for voice services, particularly in Zimbabwe. Zimbabwe is a special case as it has recently emerged from a record-breaking hyperinflation. This has resulted in degraded network infrastructure as little investment was made.

"Consumers in these four countries have looked to mobile communications as an alternative to fixed line networks," Hirschel says. "These have been not been extended appreciably over the last ten years. Additionally, consumers are likely to look to mobile operators for Internet connectivity."

Third-generation (3G) networks are already well established in Namibia and Botswana paving the way for mobile operators to offer advanced data and value-added services. So far, only one operator in Zimbabwe has launched 3G, while in Zambia, 3G will be launched in 2010.

However, new subscribers are increasingly poor, resulting in a decline in the average blended voice ARPU, exacerbated by challenging global macroeconomic conditions. At the same time, operating costs for mobile operators have soared and profit margins have come under pressure. For instance, inadequate power grids require mobile operators to have backup generators, which are adversely affected by the rising fuel prices.

"Value propositions take on special importance in markets where poverty levels are high and ensure that subscriber growth rates and revenues are maintained in the face of increased competition," explains Hirschel. "Additionally, up-to-date network technology and alternative power generation combined with infrastructure sharing allow for costs to be controlled."

In more mature markets such as Botswana and Namibia, mobile operators have identified business as a lucrative sector and are using innovative telecommunication solutions to maintain blended ARPU levels. Network infrastructure that supports broadband speeds is a vital component of this strategy.

"While ARPU levels for pre-paid subscribers are lower than for post-paid customers, innovative retention strategies and increasing consumer participation in mobile communications with subsidised handsets can ensure low price elasticity even in a competitive market," concludes Hirschel. "This will allow operators to migrate subscribers towards a higher value."

Frost & Sullivan Finds Double Digit Subscriber Growth in Southern African Mobile Markets
[prnewswire] Only half (51%) of the people surveyed always use their real name on social networking sites. Eighteen percent said they always use a nickname. A third (31%) said they sometimes use their real name and sometimes use a nickname to identify themselves on social networking sites, according to a survey of 1,040 Americans sponsored by the Chubb Group of Insurance Companies.

"Twitter, Facebook and Foursquare have created new social media risks and an environment where many people don't know who they are talking to online. They don't realize who can see their location, creating many exposures for individuals and companies," according to Kenneth Goldstein, worldwide media liability manager at Chubb.

Does everyone know where you are?

Two-thirds (66%) of respondents said they would not use mobile technology that shows people on social networking sites where they are located.

"Although this lets your friends know where to find you, it also alerts criminals of your whereabouts, including when to burglarize your empty home," said Goldstein.

Negative experiences?

Nearly 20% of respondents said they have shared a negative product or service experience with others on Facebook, YouTube or other social networking sites.

Social networking at work?

Almost two-thirds (64%) of respondents said their company had no policy for talking about the company on social networking sites. Of the 36% who said their company had a policy, 18% said they were encouraged to talk about the company and 18% said they were prohibited from talking about the company on social networking sites.

The online survey was conducted by Opinion Research Corp. in April 2010.

Many Don't Use Their Real Name on the Internet, Reveals Social Networking Survey
It's bigger, it's bolder, but is it really that much better? Nintendo's heralded DSi line grew in more ways than one late last month, and now that you've had a handful of weekends to toy with yours, it's time to answer one majorly important question: how would you change it? We found in our review that the DSi XL was a solid option for those without a DSi of any kind, but we didn't feel that it was worth the $190 if you were just upgrading. For those that bought in, do you find yourself agreeing? Is the new size something you're into? Would you have made it a touch larger / smaller? Is the screen up to snuff? Do you think Nintendo went far enough with the advancements? Open up in comments below -- just keep it clean, okay? Your kids are probably reading.

How would you change Nintendo's DSi XL? originally appeared on Engadget on Sat, 01 May 2010 02:01:00 EST. Please see our terms for use of feeds.

Permalink   |   | Email this | Comments

Upgrade Tomorrow

Its May day today and so we have decided to have some minor upgrades today and then more advanced upgrades tomorrow.

During the upgrade, the forum will be unavailable. We apologize in advance for any inconvenience this may cause.

The upgrade mainly will be focused on faster user experience.


Looks like the wait is almost over for a lot of patient Sprint Android owners.  A screenshot of a official Sprint employee memo shows that Sprint is preparing for the release of the long awaited Android 2.1 update for the HTC Hero and the Samsung Moment.  Actually it’s closer than you might think.  According to the internal memo the Samsung Moment is supposed to get the update starting today, April 30th.  I have been following the thread at XDA very closely, and it seems that all of the Moment owners are still waiting for the update to go live.  Anyways, the memo goes on to say that the Hero update is scheduled for the first week of May. The Samsung Moment 2.1 Eclair Maintenance Release is scheduled for next friday, April 30th, and the HTC Hero is scheduled for the first week of May   The other important info that comes out of the memo is that the official update will OTW, which stands for ove-the-wire.  All that means is that it the upgrades will be PC-based.  The is in fact due to the large size of the Android 2.1 update.  Usually we see most firmware updates come OTA (over the air) but the 80MB Moment update and the 117MB Hero update are just too big for Sprint’s network. All Hero and Moment owners should be on high alert for the update, it’s still possible that the Moment update could still go live, but i wouldn’t count on it.  I figure tomorrow is a better option of everyone, including Sprint.  Technically tomorrow is the “first week of May”  But Sprint is known for waiting till the last possible minute to meet a deadline.  If we do see the Moment update released today or tomorrow, it would help to ensure that the Hero update would shortly follow.  Just hang in there a little while longer guys, it’s almost here!  [via XDA ] Similar Posts: Sprint’s Android 2.1 Update for Hero and Moment, Early May?

Continue Reading »

This article continues our exploration of the Abstract Window Toolkit (AWT). It examines the standard controls defined by Java. Controls are components that allow a user to interact with your application in various ways—for example; a commonly used control is the push button.

The AWT supports the following types of controls:-
  1. Labels
  2. Push buttons
  3. Check boxes
  4. Choice lists
  5. Lists
  6. Scroll bars
  7. Text editing
These controls are subclasses of Component.

Adding and Removing Controls



To include a control in a window, you must add it to the window. To do this, you must first create an instance of the desired control and then add it to a window by calling add( ), which is defined by Container. The add( ) method has several forms.

Component add(Component compObj)

Here, compObj is an instance of the control that you want to add. A reference to compObj is returned.

Once a control has been added, it will automatically be visible whenever its parent window is displayed.

Sometimes you will want to remove a control from a window when the control is no longer needed. To do this, call remove( ). This method is also defined by Container. It has this general form:

void remove(Component obj)

Here, obj is a reference to the control you want to remove. You can remove all controls by calling removeAll( ).

Responding to Controls



Except for labels, which are passive controls, all controls generate events when they are accessed by the user. For example, when the user clicks on a push button, an event is sent that identifies the push button. In general, your program simply implements the appropriate interface and then registers an event listener for each control that you need to monitor. Once a listener has been installed, events are automatically sent to it.

Labels



The easiest control to use is a label. A label is an object of type Label, and it contains a string, which it displays. Labels are passive controls that do not support any interaction with the user.

Label defines the following constructors:
  1. Label( )
  2. Label(String str)
  3. Label(String str, int how)
The first version creates a blank label.

The second version creates a label that contains the string specified by str. This string is left-justified.

The third version creates a label that contains the string specified by str using the alignment specified by how. The value of how must be one of these three constants: Label.LEFT, Label.RIGHT, or Label.CENTER.

You can set or change the text in a label by using the setText( ) method. You can obtain the current label by calling getText( ).

These methods are shown here:
  1. void setText(String str)
  2. String getText( )

For setText( ), str specifies the new label. For getText( ), the current label is returned.

You can set the alignment of the string within the label by calling setAlignment( ).

To obtain the current alignment, call getAlignment( ).

The methods are as follows:
  1. void setAlignment(int how)
  2. int getAlignment( )
Here, how must be one of the alignment constants shown earlier.

The following example creates three labels and adds them to an applet:-
Code:
import java.awt.*;
import java.applet.*;
/*
<applet code="LabelDemo" width=300 height=200>
</applet>
*/
public class LabelDemo extends Applet 
{
	public void init() 
	{
		Label one = new Label("One"); 
		Label two = new Label("Two"); 
		Label three = new Label("Three");

		// add labels to applet window

		add(one);
		add(two);
		add(three);
	}
}
Output:-

http://www.go4expert.com/forums/imag.../controlsA.jpg

Using Buttons



The most widely used control is the push button. A push button is a component that contains a label and that generates an event when it is pressed. Push buttons are objects of type Button. Button defines these two constructors:
  1. Button( )
  2. Button(String str)

The first version creates an empty button.

The second creates a button that contains str as a label.

After a button has been created, you can set its label by calling setLabel( ). You can retrieve its label by calling getLabel( ).

These methods are as follows:
  1. void setLabel(String str)
  2. String getLabel( )
Here, str becomes the new label for the button.

Handling Buttons



Each time a button is pressed, an action event is generated. This is sent to any listeners that previously registered an interest in receiving action event notifications from that component. Each listener implements the ActionListener interface. That interface defines the actionPerformed( ) method, which is called when an event occurs. An ActionEvent object is supplied as the argument to this method. It contains both a reference to the button that generated the event and a reference to the string that is the label of the button.

Example:

Here is an example that creates three buttons labeled “Yes,” “No,” and “Undecided.”

Each time one is pressed, a message is displayed that reports which button has been pressed. In this version, the label of the button is used to determine which button has been pressed. The label is obtained by calling the getActionCommand( ) method on the

ActionEvent object passed to actionPerformed( ).

Code:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="ButtonDemo" width=250 height=150>
</applet>
*/

public class ButtonDemo extends Applet implements ActionListener 
{
	String msg = "";
	Button yes, no, maybe;

	public void init() 
	{
		yes = new Button("Yes");
		no = new Button("No");
		maybe = new Button("Undecided");
		add(yes);
		add(no);
		add(maybe);
		yes.addActionListener(this);
		no.addActionListener(this);
		maybe.addActionListener(this);
	}

	public void actionPerformed(ActionEvent ae) 
	{
		String str = ae.getActionCommand();
		if(str.equals("Yes")) 
		{ 
			msg = "You pressed Yes.";
		}
		else if(str.equals("No")) 
		{ 
			msg = "You pressed No.";
		}
		else 
		{
			msg = "You pressed Undecided.";
		}
		repaint();
	}

	public void paint(Graphics g) 
	{
		g.drawString(msg, 6, 100);
	}
}
Sample output is as follows:-

http://www.go4expert.com/forums/imag.../controlsB.jpg

Check Boxes



A check box is a control that is used to turn an option on or off. It consists of a small box that can either contain a check mark or not. There is a label associated with each check box that describes what option the box represents. You change the state of a check box by clicking on it. Check boxes can be used individually or as part of a group. Check boxes are objects of the Checkbox class.

Checkbox supports these constructors:
  1. Checkbox( )
  2. Checkbox(String str)
  3. Checkbox(String str, boolean on)
  4. Checkbox(String str, boolean on, CheckboxGroup cbGroup)
  5. Checkbox(String str, CheckboxGroup cbGroup, boolean on)

The first form creates a check box whose label is initially blank. The state of the check box is unchecked.

The second form creates a check box whose label is specified by str. The state of the check box is unchecked.

The third form allows you to set the initial state of the check box. If on is true, the check box is initially checked otherwise, it is cleared.

The fourth and fifth forms create a check box whose label is specified by str and whose group is specified by cbGroup. If this check box is not part of a group, then cbGroup must be null. (Check box groups are described soon in this article) The value of on determines the initial state of the check box.

To retrieve the current state of a check box, call getState( ). To set its state, call setState(). You can obtain the current label associated with a check box by calling getLabel( ). To set the label, call setLabel( ).

These methods are as follows:
  1. boolean getState( )
  2. void setState(boolean on)
  3. String getLabel( )
  4. void setLabel(String str)
Here, if on is true, the box is checked. If it is false, the box is cleared. The string passed in str becomes the new label associated with the invoking check box.

Handling Check Boxes



Each time a check box is selected or deselected, an item event is generated. This is sent to any listeners that previously registered an interest in receiving item event notifications from that component. Each listener implements the ItemListener interface. That interface defines the itemStateChanged( ) method. An ItemEvent object is supplied as the argument to this method. It contains information about the event (for example, whether it was a selection or deselection).

Example:

The following program creates four check boxes. The initial state of the first box is checked. The status of each check box is displayed. Each time you change the state of a check box, the status display is updated.

Code:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="CheckboxDemo" width=250 height=200>
</applet>
*/
public class CheckboxDemo extends Applet implements ItemListener 
{
	String msg = "";
	Checkbox Win98, winNT, solaris, mac;

	public void init() 
	{
		Win98 = new Checkbox("Windows 98/XP", null, true);
		winNT = new Checkbox("Windows NT/2000");
		solaris = new Checkbox("Solaris");
		mac = new Checkbox("MacOS");
		add(Win98);
		add(winNT);
		add(solaris);
		add(mac);
		Win98.addItemListener(this);
		winNT.addItemListener(this);
		solaris.addItemListener(this);
		mac.addItemListener(this);
	}

	public void itemStateChanged(ItemEvent ie) 
	{
		repaint();
	}

	// Display current state of the check boxes.
	public void paint(Graphics g) 
	{ 
		msg = "Current state: ";
		g.drawString(msg, 6, 80);
		msg = " Windows 98/XP: " + Win98.getState();
		g.drawString(msg, 6, 100);
		msg = " Windows NT/2000: " + winNT.getState();
		g.drawString(msg, 6, 120);
		msg = " Solaris: " + solaris.getState();
		g.drawString(msg, 6, 140);
		msg = " MacOS: " + mac.getState();
		g.drawString(msg, 6, 160);
	}
}
Sample output is as follows:-

http://www.go4expert.com/forums/imag.../controlsC.jpg

CheckboxGroup



It is possible to create a set of mutually exclusive check boxes in which one and only one check box in the group can be checked at any one time. These check boxes are often called radio buttons, because they act like the station selector on a car radio—only one station can be selected at any one time. To create a set of mutually exclusive check boxes, you must first define the group to which they will belong and then specify that group when you construct the check boxes. Check box groups are objects of type CheckboxGroup. Only the default constructor is defined, which creates an empty group. You can determine which check box in a group is currently selected by calling getSelectedCheckbox( ). You can set a check box by calling setSelectedCheckbox( ).

These methods are as follows:
  1. Checkbox getSelectedCheckbox( )
  2. void setSelectedCheckbox(Checkbox which)

Here, which is the check box that you want to be selected. The previously selected check box will be turned off.

Example:

Here is a program that uses check boxes that are part of a group:
Code:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="CBGroup" width=250 height=200>
</applet>
*/
public class CBGroup extends Applet implements ItemListener 
{
	String msg = "";
	Checkbox Win98, winNT, solaris, mac;
	CheckboxGroup cbg;
	public void init() 
	{
		cbg = new CheckboxGroup();
		Win98 = new Checkbox("Windows 98/XP", cbg, true);
		winNT = new Checkbox("Windows NT/2000", cbg, false);
		solaris = new Checkbox("Solaris", cbg, false);
		mac = new Checkbox("MacOS", cbg, false);
		add(Win98);
		add(winNT);
		add(solaris);
		add(mac);
		Win98.addItemListener(this);
		solaris.addItemListener(this);
		mac.addItemListener(this);
	}

	public void itemStateChanged(ItemEvent ie) 
	{
		repaint();
	}
	// Display current state of the check boxes.
	public void paint(Graphics g) 
	{
		msg = "Current selection: ";
		msg += cbg.getSelectedCheckbox().getLabel();
		g.drawString(msg, 6, 100);
	}
}
Sample output is as shown:-

http://www.go4expert.com/forums/imag.../controlsD.jpg

Choice Controls



The Choice class is used to create a pop-up list of items from which the user may choose. Thus, a Choice control is a form of menu. When inactive, a Choice component takes up only enough space to show the currently selected item. When the user clicks on it, the whole list of choices pops up, and a new selection can be made. Each item in the list is a string that appears as a left-justified label in the order it is added to the Choice object. Choice only defines the default constructor, which creates an empty list.

To add a selection to the list, call add( ). It has this general form:

void add(String name)

Here, name is the name of the item being added. Items are added to the list in the order in which calls to add( ) occur. To determine which item is currently selected, you may call either getSelectedItem( ) or getSelectedIndex( ).

These methods are shown here:
  1. String getSelectedItem( )
  2. int getSelectedIndex( )

The getSelectedItem( ) method returns a string containing the name of the item. getSelectedIndex( ) returns the index of the item. The first item is at index 0. By default, the first item added to the list is selected. To obtain the number of items in the list, call getItemCount( ). You can set the currently selected item using the select( ) method with either a zero-based integer index or a string that will match a name in the list.

These methods are shown here:
  1. int getItemCount( )
  2. void select(int index)
  3. void select(String name)

Given an index, you can obtain the name associated with the item at that index by calling getItem( ), which has this general form:

String getItem(int index)

Here, index specifies the index of the desired item.

Handling Choice Lists



Each time a choice is selected, an item event is generated. This is sent to any listeners that previously registered an interest in receiving item event notifications from that component. Each listener implements the ItemListener interface. That interface defines the itemStateChanged( ) method. An ItemEvent object is supplied as the argument to this method.

Example:-

Here is an example that creates two Choice menus. One selects the operating system. The other selects the browser.

Code:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="ChoiceDemo" width=300 height=180>
</applet>
*/
public class ChoiceDemo extends Applet implements ItemListener 
{
	Choice os, browser; 
	String msg = "";
	public void init() 
	{
		os = new Choice();
		browser = new Choice();
		// add items to os list
		os.add("Windows 98/XP");
		os.add("Windows NT/2000");
		os.add("Solaris");
		os.add("MacOS");
		// add items to browser list
		browser.add("Netscape 3.x");
		browser.add("Netscape 4.x");
		browser.add("Netscape 5.x");
		browser.add("Netscape 6.x");
		browser.add("Internet Explorer 4.0");
		browser.add("Internet Explorer 5.0");
		browser.add("Internet Explorer 6.0");
		browser.add("Lynx 2.4");
		browser.select("Netscape 4.x");
		// add choice lists to window
		add(os);
		add(browser);
		// register to receive item events
		os.addItemListener(this); 
		browser.addItemListener(this);
	}
	public void itemStateChanged(ItemEvent ie) 
	{ 
		repaint();
	}
	// Display current selections.
	public void paint(Graphics g) 
	{
		msg = "Current OS: ";
		msg += os.getSelectedItem();
		g.drawString(msg, 6, 120);
		msg = "Current Browser: ";
		msg += browser.getSelectedItem();
		g.drawString(msg, 6, 140);
	}
}
http://www.go4expert.com/forums/imag.../controlsE.jpg

Lists



The List class provides a compact, multiple-choice, scrolling selection list. Unlike the Choice object, which shows only the single selected item in the menu, a List object can be constructed to show any number of choices in the visible window. It can also be created to allow multiple selections.

List provides these constructors:
  1. List( )
  2. List(int numRows)
  3. List(int numRows, boolean multipleSelect)

The first version creates a List control that allows only one item to be selected at any one time.

In the second form, the value of numRows specifies the number of entries in the list that will always be visible (others can be scrolled into view as needed).

In the third form, if multipleSelect is true, then the user may select two or more items at a time. If it is false, then only one item may be selected.

To add a selection to the list, call add( ). It has the following two forms:
  1. void add(String name)
  2. void add(String name, int index)


Here, name is the name of the item added to the list.

The first form adds items to the end of the list.

The second form adds the item at the index specified by index. Indexing begins at zero. You can specify –1 to add the item to the end of the list.

For lists that allow only single selection, you can determine which item is currently selected by calling either getSelectedItem( ) or getSelectedIndex( ).

These methods are shown here:
  1. String getSelectedItem( )
  2. int getSelectedIndex( )
The getSelectedItem( ) method returns a string containing the name of the item. If more than one item is selected or if no selection has yet been made, null is returned. getSelectedIndex( ) returns the index of the item. The first item is at index 0. If more than one item is selected, or if no selection has yet been made, –1 is returned. For lists that allow multiple selection, you must use either getSelectedItems( ) or getSelectedIndexes( ), shown here, to determine the current selections:
  1. String[ ] getSelectedItems( )
  2. int[ ] getSelectedIndexes( )
getSelectedItems( ) returns an array containing the names of the currently selected items. getSelectedIndexes( ) returns an array containing the indexes of the currently selected items.

To obtain the number of items in the list, call getItemCount( ). You can set the currently selected item by using the select( ) method with a zero-based integer index.

These methods are shown here:
  1. int getItemCount( )
  2. void select(int index)
Given an index, you can obtain the name associated with the item at that index by calling getItem( ), which has this general form:

String getItem(int index)

Here, index specifies the index of the desired item.

Handling Lists



To process list events, you will need to implement the ActionListener interface. Each time a List item is double-clicked, an ActionEvent object is generated. Its getActionCommand( ) method can be used to retrieve the name of the newly selected item. Also, each time an item is selected or deselected with a single click, an ItemEvent object is generated. Its getStateChange( ) method can be used to determine whether a selection or deselection triggered this event. getItemSelectable( ) returns a reference to the object that triggered this event.

Example:

Here is an example that converts the Choice controls in the preceding section into

List components, one multiple choice and the other single choice:
Code:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="ListDemo" width=300 height=180>
</applet>
*/
public class ListDemo extends Applet implements ActionListener 
{
	List os, browser;
	String msg = "";

	public void init() 
	{
		os = new List(4, true);
		browser = new List(4, false);
		// add items to os list 
		os.add("Windows 98/XP");
		os.add("Windows NT/2000");
		os.add("Solaris");
		os.add("MacOS");
		// add items to browser list
		browser.add("Netscape 3.x");
		browser.add("Netscape 4.x");
		browser.add("Netscape 5.x");
		browser.add("Netscape 6.x");
		browser.add("Internet Explorer 4.0");
		browser.add("Internet Explorer 5.0") ;
		browser.add("Internet Explorer 6.0");
		browser.add("Lynx 2.4");
		browser.select(1);
		// add lists to window
		add(os);
		add(browser);
		// register to receive action events
		os.addActionListener(this);
		browser.addActionListener(this);
	}
	public void actionPerformed(ActionEvent ae) 
	{
		repaint();
	}

	// Display current selections.
	public void paint(Graphics g) 
	{
		int idx[];
		msg = "Current OS: ";
		idx = os.getSelectedIndexes();
		for(int i=0; i<idx.length; i++)
		msg += os.getItem(idx[i]) + " ";
		g.drawString(msg, 6, 120);
		msg = "Current Browser: ";
		msg += browser.getSelectedItem();
		g.drawString(msg, 6, 140);
	}
}
Sample output is shown below:-

http://www.go4expert.com/forums/imag...controls2A.jpg

Scroll Bars



Scroll bars are used to select continuous values between a specified minimum and maximum. Scroll bars may be oriented horizontally or vertically. A scroll bar is actually a composite of several individual parts. Each end has an arrow that you can click to move the current value of the scroll bar one unit in the direction of the arrow. The current value of the scroll bar relative to its minimum and maximum values is indicated by the slider box (or thumb) for the scroll bar. The slider box can be dragged by the user to a new position. The scroll bar will then reflect this value. In the background space on either side of the thumb, the user can click to cause the thumb to jump in that direction by some increment larger than 1. This action translates into some form of page up and page down.

Scroll bars are encapsulated by the Scrollbar class.

Scrollbar defines the following constructors:
  1. Scrollbar( )
  2. Scrollbar(int style)
  3. Scrollbar(int style, int initialValue, int thumbSize, int min, int max)
The first form creates a vertical scroll bar.

The second and third forms allow you to specify the orientation of the scroll bar. If style is Scrollbar.VERTICAL, a vertical scroll bar is created. If style is Scrollbar.HORIZONTAL, the scroll bar is horizontal.

In the third form of the constructor, the initial value of the scroll bar is passed in initialValue. The number of units represented by the height of the thumb is passed in thumbSize. The minimum and maximum values for the scroll bar are specified by min and max.

If you construct a scroll bar by using one of the first two constructors, then you need to set its parameters by using setValues( ), shown here, before it can be used:

void setValues(int initialValue, int thumbSize, int min, int max)

The parameters have the same meaning as they have in the third constructor just described.

To obtain the current value of the scroll bar, call getValue( ). It returns the current setting. To set the current value, call setValue( ).

These methods are as follows:
  1. int getValue( )
  2. void setValue(int newValue)
Here, newValue specifies the new value for the scroll bar. When you set a value, the slider box inside the scroll bar will be positioned to reflect the new value.

You can also retrieve the minimum and maximum values via getMinimum( ) and getMaximum( ), shown here:
  1. int getMinimum( )
  2. int getMaximum( )
They return the requested quantity.

By default, 1 is the increment added to or subtracted from the scroll bar each time it is scrolled up or down one line. You can change this increment by calling setUnitIncrement( ). By default, page-up and page-down increments are 10. You can change this value by calling setBlockIncrement( ).

These methods are shown here:
  1. void setUnitIncrement(int newIncr)
  2. void setBlockIncrement(int newIncr)

Handling Scroll Bars



To process scroll bar events, you need to implement the AdjustmentListener interface. Each time a user interacts with a scroll bar, an AdjustmentEvent object is generated. Its getAdjustmentType( ) method can be used to determine the type of the adjustment.

The types of adjustment events are as follows:

BLOCK_DECREMENT--A page-down event has been generated.
BLOCK_INCREMENT--A page-up event has been generated.
TRACK--An absolute tracking event has been generated.
UNIT_DECREMENT--The line-down button in a scroll bar has been pressed.
UNIT_INCREMENT--The line-up button in a scroll bar has been pressed.

Example:

The following example creates both a vertical and a horizontal scroll bar. The current settings of the scroll bars are displayed. If you drag the mouse while inside the window, the coordinates of each drag event are used to update the scroll bars. An asterisk is displayed at the current drag position.
Code:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="SBDemo" width=300 height=200>
</applet>
*/
public class SBDemo extends Applet implements AdjustmentListener, MouseMotionListener
{
	String msg = "";
	Scrollbar vertSB, horzSB;
	public void init() 
	{
		int width = Integer.parseInt(getParameter("width"));
		int height = Integer.parseInt(getParameter("height"));
		vertSB = new Scrollbar(Scrollbar.VERTICAL, 0, 1, 0, height);
		horzSB = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, width);
		add(vertSB);
		add(horzSB);
		// register to receive adjustment events
		vertSB.addAdjustmentListener(this);
		horzSB.addAdjustmentListener(this);
		addMouseMotionListener(this);
	}

	public void adjustmentValueChanged(AdjustmentEvent ae) 
	{
		repaint();
	}

	// Update scroll bars to reflect mouse dragging.

	public void mouseDragged(MouseEvent me) 
	{
		int x = me.getX();
		int y = me.getY();
		vertSB.setValue(y);
		horzSB.setValue(x);
		repaint();
	}

	// Necessary for MouseMotionListener
	public void mouseMoved(MouseEvent me) 
	{
	}
	// Display current value of scroll bars.
	public void paint(Graphics g) 
	{
		msg = "Vertical: " + vertSB.getValue();
		msg += ", Horizontal: " + horzSB.getValue();
		g.drawString(msg, 6, 160);
		// show current mouse drag position
		g.drawString("*", horzSB.getValue(),
		vertSB.getValue());
	} 
}
Sample output is as shown below:-

http://www.go4expert.com/forums/imag...controls2B.jpg

TextField



The TextField class implements a single-line text-entry area, usually called an edit control. Text fields allow the user to enter strings and to edit the text using the arrow keys, cut and paste keys, and mouse selections.

TextField is a subclass of TextComponent.

TextField defines the following constructors:
  1. TextField( )
  2. TextField(int numChars)
  3. TextField(String str)
  4. TextField(String str, int numChars)
The first version creates a default text field.

The second form creates a text field that is numChars characters wide.

The third form initializes the text field with the string contained in str.

The fourth form initializes a text field and sets its width.

TextField (and its superclass TextComponent) provides several methods that allow you to utilize a text field. To obtain the string currently contained in the text field, call getText( ). To set the text , call setText( ).

These methods are as follows:
  1. String getText( )
  2. void setText(String str)
Here, str is the new string.

The user can select a portion of the text in a text field. Also, you can select a portion of text under program control by using select( ). A program can obtain the currently selected text by calling getSelectedText( ).

These methods are shown here:
  1. String getSelectedText( )
  2. void select(int startIndex, int endIndex)

getSelectedText( ) returns the selected text. The select( ) method selects the characters beginning at startIndex and ending at endIndex–1.

You can control whether the contents of a text field may be modified by the user by calling setEditable( ). You can determine editability by calling isEditable( ).

These methods are shown here:
  1. boolean isEditable( )
  2. void setEditable(boolean canEdit)
isEditable( ) returns true if the text may be changed and false if not. In setEditable( ), if canEdit is true, the text may be changed. If it is false, the text cannot be altered.

There may be times when you will want the user to enter text that is not displayed, such as a password. You can disable the echoing of the characters as they are typed by calling setEchoChar( ). This method specifies a single character that the TextField will display when characters are entered (thus, the actual characters typed will not be shown). You can check a text field to see if it is in this mode with the echoCharIsSet( ) method. You can retrieve the echo character by calling the getEchoChar( ) method.

These methods are as follows:
  1. void setEchoChar(char ch)
  2. boolean echoCharIsSet( )
  3. char getEchoChar( )
Here, ch specifies the character to be echoed.

Handling a TextField



Since text fields perform their own editing functions, your program generally will not respond to individual key events that occur within a text field. However, you may want to respond when the user presses ENTER. When this occurs, an action event is generated.

Example:

Here is an example that creates the classic user name and password screen:
Code:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="TextFieldDemo" width=380 height=150>
</applet>
*/
public class TextFieldDemo extends Appletimplements ActionListener 
{
	TextField name, pass;
	public void init() 
	{
		Label namep = new Label("Name: ", Label.RIGHT);
		Label passp = new Label("Password: ", Label.RIGHT); 
		name = new TextField(12);
		pass = new TextField(8);
		pass.setEchoChar('?');
		add(namep);
		add(name);
		add(passp);
		add(pass);
		// register to receive action events
		name.addActionListener(this);
		pass.addActionListener(this);
	}
	// User pressed Enter.
	public void actionPerformed(ActionEvent ae) 
	{
		repaint();
	}
	public void paint(Graphics g) 
	{
		g.drawString("Name: " + name.getText(), 6, 60);
		g.drawString("Selected text in name: "+ name.getSelectedText(), 6, 80);
		g.drawString("Password: " + pass.getText(), 6, 100);
	}
}
Sample output is as shown below:-

http://www.go4expert.com/forums/imag...controls2C.jpg

TextArea



Sometimes a single line of text input is not enough for a given task. To handle these situations, the AWT includes a simple multiline editor called TextArea.
Following are the constructors for TextArea:
  1. TextArea( )
  2. TextArea(int numLines, int numChars)
  3. TextArea(String str)
  4. TextArea(String str, int numLines, int numChars)
  5. TextArea(String str, int numLines, int numChars, int sBars)
Here, numLines specifies the height, in lines, of the text area, and numChars specifies its width, in characters. Initial text can be specified by str.

In the fifth form you can specify the scroll bars that you want the control to have. sBars must be one of these values:
  • SCROLLBARS_BOTH
  • SCROLLBARS_NONE
  • SCROLLBARS_HORIZONTAL_ONLY
  • SCROLLBARS_VERTICAL_ONLY

TextArea is a subclass of TextComponent. Therefore, it supports the getText( ), setText( ), getSelectedText( ), select( ), isEditable( ), and setEditable( ) methods.

TextArea adds the following methods:
  1. void append(String str)
  2. void insert(String str, int index)
  3. void replaceRange(String str, int startIndex, int endIndex)

The append( ) method appends the string specified by str to the end of the current text. insert( ) inserts the string passed in str at the specified index. To replace text, call replaceRange( ). It replaces the characters from startIndex to endIndex–1, with the replacement text passed in str.

Text areas are almost self-contained controls. Your program incurs virtually no management overhead. Text areas only generate got-focus and lost-focus events.

Normally, your program simply obtains the current text when it is needed.

Example:

The following program creates a TextArea control:
Code:
import java.awt.*;
import java.applet.*;
/*
<applet code="TextAreaDemo" width=300 height=250>
</applet>
*/
public class TextAreaDemo extends Applet 
{
	public void init() 
	{ 
		String val = "There are two ways of constructing " +"a software design.\n" +
"One way is to make it so simple\n" + "that there are obviously no deficiencies.\n" +
"And the other way is to make it so complicated\n" + 
"that there are no obvious deficiencies.\n\n" + " -C.A.R. Hoare\n\n" +
"There's an old story about the person who wished\n" +
"his computer were as easy to use as his telephone.\n" + 
"That wish has come true,\n" +
"since I no longer know how to use my telephone.\n\n" +
" -Bjarne Stroustrup, AT&T, (inventor of C++)";
		TextArea text = new TextArea(val, 10, 30);
		add(text);
	}
}
Sample output is shown below:-

http://www.go4expert.com/forums/imag...controls2D.jpg


Apple priced digital downloads lower than CDs. Amazon said a digital book should be cheaper than a paper one. But for the time being, virtual magazines will cost a pretty penny, says Fortune. More »



Apple - Magazine - Business - Shopping - IPad
We've seen its communications board before, but now the entire iPad 3G has been torn open and had its parts analyzed. Here's what makes it different from a Wi-Fi-only iPad according to the guys at iFixit: More »



Apple - IPad - Companies - Apple II - Macintosh
Powered by WordPress. Theme: Motion by 85ideas.