Tuesday, February 16, 2016

Program to add choice menu in Frame.

import java.awt.*;
class Choice_Test extends Frame
{
public static void main(String arg[])
{
Choice ch = new Choice ( );
ch.add ( "Apples" );
ch.add ( "Oranges" );
ch.add ( "Strawberries" );
ch.add ( "Bananas");
Choice_Test f1=new Choice_Test();
f1.setTitle("Adding a Choice menu in a Frame!!!");
f1.setLayout(new FlowLayout());
f1.add(ch);
f1.setSize(500,300);
f1.setVisible(true);
}
}
Output:


Monday, February 15, 2016

Program to add RadioButton in Frame.

import java.awt.*;

class RadioButton extends Frame
{
public static void main(String args[ ] )
{
CheckboxGroup og=new CheckboxGroup();
Checkbox male=new Checkbox("Male",og,true);
Checkbox female=new Checkbox("Female",og,false);
RadioButton f1 =new RadioButton();
f1.setTitle("Adding a RadioButton in a Frame!!!");
f1.setLayout(new FlowLayout());
f1.add(male);
f1.add(female);
f1.setSize(500,300);
f1.setVisible(true);

}
}
Output:

Saturday, February 13, 2016

Program to add checkbox in Frame.

import java.awt.*;
class chkBox extends Frame
{
public static void main(String args[ ] )
{
Checkbox c1 =new Checkbox("Reading");
Checkbox c2=new Checkbox("Singing");
Checkbox c3=new Checkbox("Dancing");
c1.setState(true);
chkBox f1=new chkBox();
f1.setTitle("Adding a Checkbox in a Frame!!!");
f1.setLayout(new FlowLayout());
f1.add(c1);
f1.add(c2);
f1.add(c3);
f1.setSize(500,300);
f1.setVisible(true);
}
}
Output:

Friday, February 12, 2016

Program to add buttons in Frame.

import java.awt.*;
class btnAdd extends Frame
{
public static void main(String args[ ] )
{
Button b1=new Button("Add");
Button b2=new Button("Subtract");
Button b3=new Button("Mu|tip|y");
Button b4=new Button("Division");
btnAdd f1=new btnAdd();
f1 .setTitle("Adding Buttons in a Frame!!!");
f1 .setLayout(new FlowLayout());
f1 .add(b1 );
f1 .add(b2);
f1 .add(b3);
f1 .add(b4);
f1 .setSize(500,500);
f1 .setVisible(true );
}
}
Output:

Thursday, February 11, 2016

Program to use the various methods of TextArea.

import java.awt.*;
class txtAreaMethods extends Frame
{
public static void main(String args[] )
{
TextArea ta1 =new TextArea(5,30);
ta1.setText("The Quick Brown Fox Jumps Over The Lazy Dog");
ta1.insertText("-Java is Intenesting-",5);
ta1.replaceText("-Text Replaced-",38,50);
txtAreaMethods f1=new txtAreaMethods();
f1.setTitle("Adding a TextArea in a Frame!!!");
f1.setLayout(new FlowLayout());
f1.add(ta1 );
f1.setSize(500,500);
f1.setVisible(true );
}
}
Output:

Program to add TextArea in Frame.

import java.awt.*;
class txtArea extends Frame
{
public static void main(String args[ ])
{
TextArea ta1 =new TextArea("Area to write Text",5,30);
txtArea f1 =new txtArea();
f1.setTitle("Adding a TextArea in a Frame!!!");
f1.setLayout(new FlowLayout());
f1.add(ta1 );
f1.setSize(500,500);
f1.setVisible(true );
}
}
Output:

Tuesday, February 9, 2016

Program to use various methods of TextField.

import java.awt.*;
class txtFieldMethods extends Frame
{
public static void main(String args[])
{
TextField t1 =new TextField(50);
TextField t2=new TextField(50);
TextField t3=new TextField(50);
TextField t4=new TextField(50);
//To make a TextField Read Only
t1.setEditable(false);
//setting the initial Text of a TextField
t2.setText("Java is Interesting");
//Getting the text of a TextField and stone into a String Object
String str=t2.getText();
//setting the Copied text into nother TextField
t3.setText("Copied Suing is : "+str);
//setting llsking chlacter of a TextField
t4.setEchoCharacter('*');
txtFieldMethods f1=new txtFieldMethods();
f1.setTitle("Adding a TextField in a FIame!!!");
f1.setLayout(new FlowLayout());
f1.add(t1);
  f1.add(t2);
f1.add(t3);
f1.add(t4);
f1.setSize(500,500);
f1.setVisible(true );
}
}
Output: