
Slip 20
A) Write a java program using AWT to create a Frame with title “TYBBACA”, background color RED. If user clicks on close button then frame should close.
import javax.swing.*;
import java.awt.*;
class Slip20a{
public static void main(String args[]) {
JFrame frame = new JFrame("TYBBA CA");
frame.setSize(400, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setBackground(Color.RED);
frame.setVisible(true);
}
}
Program Output :
B) Construct a Linked List containing name: CPP, Java, Python and PHP. Then extend your java program to do the following:
i. Display the contents of the List using an Iterator
ii. Display the contents of the List in reverse order using a ListIterator
import java.util.*;
public class Slip20b{
public static void main (String args[]){
LinkedList al = new LinkedList<>();
al.add("CPP");
al.add("JAVA");
al.add("Python");
al.add("PHP");
System.out.println("Display content using Iterator...");
Iterator il=al.iterator();
while(il.hasNext()){
System.out.println(il.next());
}
System.out.println("\nDisplay Content Revverse Using ListIterator");
ListIterator li1=al.listIterator();
while(li1.hasNext()){
li1.next();
}
while(li1.hasPrevious()){
System.out.println("" + li1.previous());
}
}
}
Program Output:
Display content using Iterator...
CPP
JAVA
Python
PHP
Display Content Revverse Using ListIterator
PHP
Python
JAVA
CPP
comment 0 Comment
more_vert