Write a Program to demonstrate the use of AWT components with theory and examples in advanced java


Difference between Checkbox and Radio Button in Java Awt
Checkbox
RadioButton
Here we mark or check all the option over the checkbox
Here in RadioButton we just mark a single option
The Checkbox are Used for getting multiple answers
RadioButton are used for specific answer
Checkbox are represented by square box
RadioButton are represented by circle
Checkbox are used in Multiple choice option
Are used in MCQ Exams,etc

Write the use of setEnabled() method in Java
Ans: The code setEnabled(false), disables the TextField it is not selectable and user can’t copy data from it and also user cannot able edit or copy ,it is just used for preventing purpose from being edited,but it will still look the same as TextFeild without setEnabled() method.

Draw the life Cycle of an Applet

1.     Develop a program using Label to display message “Welcome to Java”
import java.awt.*;
class L
{
L()
{
        Frame f=new Frame();
        Label l1=new Label("Welcome to Java");
    l1.setBounds(100,50,120,80);
    f.add(l1);
        f.setSize(500,500);
        f.setLayout(null);
        f.setVisible(true);
}
public static void main(String a[])
{
        new L();
}
}

Output:

2.     Develop a program to select multiple languages known to user.
import java.awt.*;
class Lan
{
Lan()
{
Frame f=new Frame();
Label l1=new Label("Select known Languages");
l1.setBounds(100,50,120,80);
f.add(l1);
Checkbox c1=new Checkbox("Marathi");
c1.setBounds(100,90,50,50);
f.add(c1);
Checkbox c2=new Checkbox("Hindi");
c2.setBounds(100,150,50,50);
f.add(c2);
Checkbox c3=new Checkbox("English");
c3.setBounds(100,200,80,50);
f.add(c3);
Checkbox c4=new Checkbox("Sanskrit");
c4.setBounds(100,250,80,50);
f.add(c4);

f.setSize(500,500);
f.setLayout(null);
f.setVisible(true);
}
public static void  main(String ar[])
{
                new Lan();
}
}
O/P:

3.     Write a program to create three buttons with caption OK,RESET,CANCEL.
import java.awt.*;
class But
{
But()
{
                Frame f=new Frame();
                Button b1=new Button("Ok");
                b1.setBounds(100,50,50,50);
                f.add(b1);
                Button b2=new Button("Reset");
                b2.setBounds(100,101,50,50);
                f.add(b2);
                Button b3=new Button("Cancel");
                b3.setBounds(100,150,80,50);
                f.add(b3);
                f.setSize(500,500);
                f.setLayout(null);
                f.setVisible(true);
}
public static void main(String a[])
{
                new But();
}
}
               
               
O/P:

Comments

Post a Comment

If you have any query, please let us know