Monday, February 8, 2016

Program to add a TextField in a Frame.

import java.awt.*;
class txtField extends Frame
{
public static void main(String args[])
{
TextField t1 =new TextField("Enter a value here!",50);
txtField f1 =new txtField();
f1.setTitle("Adding a TextField in a Frame!!!");
f1.add(t1);
f1.setSize(300,200);
f1.setVisible(true);
}
}
Output:

Sunday, February 7, 2016

Program to change backcolor and textcolor of label using color class.

import java.awt.*;
class Demo4_ColorLabel extends Frame
{
public static void main(String args[ ] )
{
Color c1 =new Color(200, 100,50);
Color c2=new Color(100,150,250);
Label l1 =new Label("Java is lnteresting!!!");
//setting text color of label
l1.setForeground(c1 );
//setting background color of a label
l1.setBackground(c2);
Demo4_ColorLabel f1 =new Demo4_ColorLabel();
f1.setTitle("Working with colors of a Label");
f1.add(l1);
f1.resize(400,200);
f1.show();
}
}
Output:

Program to use setText() and getText() methods of Label.

import java.awt.*;
class Demo3_Label extends Frame
{
public static void main(String args[ ] )
{
Label l1=new Label();
//Setting text of a label
l1.setText("Java is lnteresting!!!");
//Getting text of a label and set it to another label
String lbltext=l1.getText();
Label l2=new Label();
l2.setText(lbltext);
Demo3_Label f1=new Demo3_Label();
f1.setTitle("Adding a Label in a Frame!!!");
f1.add(l2);
f1.resize(300,200);
f1.show( );
}
}
Output:

Thursday, February 4, 2016

Program to set alignment of label in frame.

import java.awt.*;
class Demo_Label extends Frame
{
public static void main(String args[ ])
{
Label l1 =new Label(" Hello Java!!! ", Label.CENTER);
Demo_Label f1 =new Demo_Label();
f1.setTitle("Adding a Label in a Frame!!!");
f1.add(l1);
f1.resize(300,200);
f1.show( );
}
}
Output:

Wednesday, January 27, 2016

Program to create lalbel in frame.

import java.awt.*;
class Demo1_Label extends Frame
{
public static void main(String args[])
{
Label l1 =new Label(" Hello Java!!! ");
Demo1_Label f1 =new Demo1_Label();
f1.setTitle("Adding a Label in a Frame!!!");
f1.add(l1);
f1.resize(300,200);
f1.show( );
}
}
Output:

Friday, January 22, 2016

Program to create frame.

import java.awt.*;
class FrameDemo extends Frame
{
public FrameDemo(String title)
{
super(title); //calling constructor of base class Frame
    }
public static void main(String arg[])
{
FrameDemo f=new FrameDemo("I have been Framed!");
f.setSize(500,500);
f.setVisible(true);
}
}
Output:

Saturday, December 12, 2015

Program to implement multiple inheritance using interfaces.

interface Printable{
void print();
}

interface Showable{
void show();
}

class A implements Printable,Showable{

public void print(){System.out.println("Hello");}
public void show(){System.out.println("Welcome");}
}
class Multiple_inheritance{
public static void main(String args[]){
 A obj = new A();
obj.print();
obj.show();
 }
}
Output: