Monday, February 8, 2016
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:
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:
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
Wednesday, January 27, 2016
Friday, January 22, 2016
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:

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:

Subscribe to:
Posts (Atom)





