catch negative array.... class ArrayNegativeSizeExample { public static void main(String args[]) { try { int[ ] array = new int[-4]; } catch(NegativeArraySizeException e) { e.printStackTrace(); } } } draw seveal shapes..... import java.awt.*; import java.applet.*; public class shapes extends Applet { public void paint(Graphics g) { g.drawLine(25,25,100,25); g.drawRect(25,50,100,50); g.fillRect(145,50,100,50); g.drawRoundRect(25,125,100,50,15,15); g.fillRoundRect(145,125,100,50,15,15); g.drawOval(25,205,100,50); g.fillOval(145,205,100,50); } } /* */ 4*4 grid..... import java.awt.*; class GridLayoutEx { public static void main(String args[]) { Frame f = new Frame("GUI APP Example"); f.setVisible(true); f.setSize(700,700); f.setBackground(Color.yellow); Button b[ ] = new Button[16]; GridLayout layout = new GridLayout(4,4,20,20); f.setLayout(layout); for(int i=1; i<=15; i++) { b[i] = new Button("Button-"+i); f.add(b[i]); } } } create a frame two buttons... import java.awt.*; import java.awt.event.*; class MotherandFather { public static void main(String args[]) { Frame f = new Frame("Parents Delatils Examples"); Label name = new Lab name.setBounds(120,120,500,50); f.add(name); Label age = new Label(); age.setBounds(120,160,500,50); f.add(age); Label des = new Label(); des.setBounds(120,190,500,50); f.add(des); Button father = new Button("FATHER"); father.setBounds(50,50,150,40); f.add(father); father.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { name.setText("Name = ANIL"); age.setText("Age = 32"); des.setText("designation = professior"); } }); Button mother = new Button("MOTHER"); mother.setBounds(250,50,150,40); f.add(mother); mother.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { name.setText("Name = ANITA"); age.setText("Age = 28"); des.setText("designation = clerk"); } }); f.setSize(500,500); f.setLayout(null); f.setVisible(true); } } your personal details.., import java.awt.*; import java.awt.event.*; public class PersonalDetails { public static void main(String args[]) { Frame f = new Frame("Personal Details"); f.setSize(700, 400); f.setLayout(null); f.setVisible(true); Button btn = new Button ("Click Here FOR MY PERSONAL DETAILS"); btn.setBounds(100,80,320,40); f.add(btn); Label name= new Label(); name.setBounds(20,120,600,30); f.add(name); Label fathername = new Label(); fathername.setBounds(20,160,600,30); f.add(fathername); Label address = new Label(); address.setBounds(20,200,600,30); f.add(address); btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { name.setText("NAME: Srushti V"); fathername.setText("Father Name: Ram"); address.setText("Address : 7th Cross,Indira Nagar,Nidasoshi"); } }); } } window with two textfildes and buttons...,.. import java.awt.*; import java.awt.event.*; class Calculator { public static void main(String[] args) { Frame f= new Frame("Addition of two number"); f.setSize(500, 500); f.setLayout(null); f.setVisible(true); Label l1 = new Label("Enter The Value 1 : "); l1.setBounds(10, 50, 100, 30); f.add(l1); TextField t1 = new TextField(); t1.setBounds(150, 50, 250, 30); f.add(t1); Label l2 = new Label("Enter The Value 2 : "); l2.setBounds(10, 100, 100, 30); f.add(l2); TextField t2 = new TextField(); t2.setBounds(150, 100, 250, 30); f.add(t2); Label l3 = new Label("Total: "); l3.setBounds(10, 150, 100, 30); f.add(l3); Label l4 = new Label("---"); l4.setBounds(150, 150, 250, 30); f.add(l4); Button add = new Button("Add"); add.setBounds(150, 200, 100, 30); f.add(add); Button clear = new Button("Clear"); clear.setBounds(300, 200, 100, 30); f.add(clear); add.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int a = Integer.parseInt(t1.getText()); int b = Integer.parseInt(t2.getText()); int c = a+b; String result = String.valueOf(c); l4.setText(result); } }); clear.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { t1.setText(""); t2.setText(""); } }); } } frame which display your personal... import java.awt.*; import java.awt.event.*; public class KeysDemo { public static void main(String args[]) { Frame f = new Frame("Key Demo"); f.setSize(400,300); f.setLayout(null); f.setVisible(true); Label L=new Label(); L.setBounds(100,100,200,40); f.add(lbl); f.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { if(e.getKeyChar() == 'M' || e.getKeyChar() == 'm') { L.setText("Good morning"); } else if(e.getKeyChar() == 'A'||e.getKeyChar() == 'a') { L.setText("Good afternoon"); } else if(e.getKeyChar() == 'E' || e.getKeyChar() == 'e') { L.setText("good evening"); } else if (e.getKeyChar() == 'N' || e.getKeyChar() =='n') { L.setText("Good night"); } } public void keyReleased(KeyEvent e) { } public void keyTyped (KeyEvent e) { } }); } } Demonstrate the various mouse ..... import java.awt.*; import java.awt.event.*; public class MouseEventsDemo { public static void main(String args[]) { Frame f = new Frame("Mouse Event Demo"); f.setSize(400,300); f.setLayout(null); f.setVisible(true); Label L=new Label(); L.setBounds(100,100,200,40); f.add(L); f.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent ev) { L.setText("Mouse Button Clicked"); } public void mouseEntered(MouseEvent ev) { L.setText("Mouse Entered"); } public void mouseExited(MouseEvent ev) { L.setText("Mouse Exited"); } public void mousePressed(MouseEvent ev) { L.setText("Mouse Pressed"); } public void mouseReleased(MouseEvent ev) { L.setText("Mouse Released"); } }); } } program to create menu bar... import java.awt.*; public class MenuDemo { public static void main(String args[]) { Frame f = new Frame("Menu Demo"); f.setSize(300,300); f.setLayout(null); f.setVisible(true); MenuBar mb = new MenuBar(); f.setMenuBar(mb); Menu fileMenu = new Menu("File"); Menu editMenu = new Menu("Edit"); Menu viewMenu = new Menu("View"); mb.add(fileMenu); mb.add(editMenu); mb.add(viewMenu); MenuItem a1 = new MenuItem("New"); MenuItem a2 = new MenuItem("Open"); MenuItem a3 = new MenuItem("Save"); MenuItem b1 = new MenuItem("Copy"); MenuItem b2 = new MenuItem("Find"); MenuItem c1 = new MenuItem("Show"); fileMenu.add(a1); fileMenu.add(a2); fileMenu.add(a3); editMenu.add(b1); editMenu.add(b2); viewMenu.add(c1); } }