You are on page 1of 3

NAME: ARVIND N

ROLL NO: 181CS121

1) Write a Java program to reverse a String in java?

import java.util.Scanner;

public class Main

public static void main(String[] args)

System.out.println("Enter string to reverse:");

Scanner read = new Scanner(System.in);

String str = read.nextLine();

String reverse = "";

for(int i = str.length() - 1; i >= 0; i--)

reverse = reverse + str.charAt(i);

System.out.println("Reversed string is:");

System.out.println(reverse);

2) write a java program to create text area inside a frame using AWT package

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Frame;
import java.awt.TextArea;

public class Main {

public static void main(String[] args) {


// Create frame with specific title
Frame frame = new Frame("Example Frame");

// Create a component to add to the frame; in this case a text area with sample text
Component textArea = new TextArea("Sample text...");

// Add the components to the frame; by default, the frame has a border layout
frame.add(textArea, BorderLayout.NORTH);

// Show the frame


int width = 300;
int height = 300;
frame.setSize(width, height);
frame.setVisible(true);
}
}

3)write a java program to create button and frame using AWT package

import java.awt.*;

/* We have extended the Frame class here,* thus our class "SimpleExample" would behave

* like a Frame*/

public class SimpleExample extends Frame{

SimpleExample(){

Button b=new Button("Button!!");

// setting button position on screen

b.setBounds(50,50,50,50);

//adding button into frame

add(b);

//Setting Frame width and height

setSize(500,300);

//Setting the layout for the Frame

setLayout(new FlowLayout());

/* By default frame is not visible so * we are setting the visibility to true


* to make it visible.*/

setVisible(true);

public static void main(String args[]){

// Creating the instance of Frame

SimpleExample fr=new SimpleExample();

4) write a java program to create checkbox inside a frame using AWT package

import java.awt.*;
public class CheckBoxExample extends Frame
{
     CheckBoxExample()
    {
        setLayout(new FlowLayout()); 
        Label lblSPORTS = new Label("SPORTS");
        Checkbox chkCRICKET = new Checkbox("CRICKET");
        Checkbox chkBADMITON = new Checkbox("BADMITON",true);
        Checkbox chkCYCLING = new Checkbox("CYCLING");
        add(lblSPORTS);
        add(chkCRICKET);
        add(chkBADMITON);
        add(chkCYCLING);
    }
}
   public class CheckboxJavaExample
 {
         public static void main(String args[])
        {
                CheckBoxExample frame = new CheckBoxExample();
                frame.setTitle("Checkbox in Java Example");
                frame.setSize(350,100);
                frame.setResizable(false);
                frame.setVisible(true);}
 }

You might also like