AWT

Embed Size (px)

DESCRIPTION

java awt

Citation preview

AWT Java.awt Package contains many classes and methods that allow you to create and manage GUI-Based application. Unlike any simple non-GUI application, GUI application do not terminate when main() method finishes the execution of its last statement. The basic functionalities provided by AWT are Component management. Event handling.

Layout Management.

Graphics Rendering.

Hierarchy of classes in java.awt Package

Components: -These include Labels, Text Fields, Menus, Buttons and other typical elements of user interface (UI). Containers: -Containers are generic AWT Components that can contain other components and containers. Panel: -A panel is a window that does not contain a title bar, menu bar or border. Panel is a super class for Applets. When we run an applet using are applet viewer, the applet viewer, the applet viewer provides the title and border. Frame: -frame encapsulates what is commonly thought of as a Window. It is a sub class of windows and has title bar, menu bar borders and resizing corners. The component class is an abstract class which includes large number of methods for positioning and sizing components, repainting, setting fonts and colors, changing window bounds, handling events etc.Example: -

Others Component classes1. Label: - Labels are text strings that can be used to label other UI components. Labels are passive conbols i.e. they do not generate any event.

Syntax: -

Label lb1=new Label(Enter Name);

Label lb2=new Label(Hello,Label.RIGHT);

2. Button: - The Button class creates a push button that generates an event when it is pressed. It can only have a textual label. The button class defines the following two constructors to create button objects.

Button()

Button(String s)

The first Constructor creates button with no label and other one creates button than has S as a label.

E.g.: -

Button bt = new Button(OK);

The Button class also defines methods to set and get the labels.

Void setLabel(String s);

String getLabel();

3. TextField: -A Text Field is a subclass of the Text component class. It can hold a single row of text and its width is either set to accommodate a string used in the constructor or set by an int parameter specifying the number of columns.

To create a text field, any of the following constructors can be used:

( TextField() ( Creates an empty textfield.

(TextField(int column) (A textfield with given width in columns.

( TextField(String s) (A textfield initialized with the given string.

( TextField(String s, int column) (A textfield with the given width in columns and initialized with the given string.

e.g.: - TextField tf=new TextField(Hello,20);

The above example creates a textfield with 20-columnwidth and initialized to Hello.

The TextField class and its superclass TextComponent provide several mthods to set and obtain text, to make a field editable or read only to make textfield that works like password field etc. Some of these methods are: -

( void setText(String s)

( String getText()

( Boolean is Editable()

( void setEditable(Boolean b)

( void Select(int start, int end)

( String getSelected Text()

The last two methods select a portion of text from text field. The first one selects the characters beginning a start position and ending at end.

And the last on returns the entire selected text.

4. TextArea: - TextArea also is a subclass of TextComponent class. It is a multiline input area that include scroll bars so that large amount of text can be entered and displayed.

Given below are the constructor that are available to create TextArea objects.

( TextArea()

( TextArea(String s)

( TextArea(int rows, int columns)

( TextArea(String s, int row, int columns)

( TextArea(String s, int rows, int column, int column, int scrollbars)

The TextArea class also Supports various methods defined in the TextComponent class, such as getText(), setText(), setEditable(), etc.

5. CheckBox: -Checkboxes are user interface components that have two states checked and unchecked (truth or false). Checkboxes can be of two types: -

( Non Exclusive Checkboxes: -These checkboxes enable you to select any number of checkboxes within a given series.

( Exclusive Checkboxes: -Only one Checkbox can be selected from within a group. These types of checkboxes are also known as radio buttons. They have a circulars appearance.

The Checkbox class has the following constructors: -

( Checkbox()

( Checkbox(String s)

( Checkbox(String s, Boolean state)

( Checkbox(String s, Boolean state, checkbox group)

The first constructor creates an empty and unselected Checkbox,

The second one creates a checkbox with a given string as label,

The third one allows to specify state also and

The last one creates a Check box which specifies the group name (radio button).E.g.: -

Checkbox cb1=new Checkbox (BCA);

Checkbox cb2= new Checkbox(MCA,true);

To create a series of radio buttons, first create an instance of checkbox Group, then create the checkboxes. Each Checkbox requires three parameters to be specified label, group name and whether it is initially selected (true) or not (false).

E.g: -

Checkbox Group cbg= new Checkbox Group();

Checkbox cb1=new Checkbox(red,true,cbg);

Checkbox cb2= new Checkbox(blue,false,cbg);

Checkbox cb3= new Checkbox(green,false,cbg);

Function Supported by Checkbox: -

( String getLabel()

( void setState(Boolean b)

( void setLabel(String s)

( CheckboxGroup getCheckboxGroup()

( Boolean getState()

( void setCheckboxGroup(CheckboxGroup g)

( Checkbox getSelectedCheckbox()

( void setSelectedCheckbox(Checkbox c)

6. Choice: -A choice list appears like a menu and enables selection of an item from that menu. The advantage of the choice list over radio buttons is that it occupies less space on the window. To create a choice list create an instance of the class. Choice by using the single default constructor provided and add the items using add() method.

Void add(String item)

e.g.: -

Choice ch=new Choice();

To add items into the list

ch.add(Cricket);

ch.add(Football);

ch.add(Hockey);

Various methods of Choice: -

( String getItem(int index)

( int getItemCount()

( int getSelectedIndex()

( String getSelectedItem()

( void select(String str)

( void select(int Position)

7. List: -The list class implements a scrollbar list of text items. A list objects shows any number of items in the visible window. A scrollbar automatically appears when it is required to scroll the list. A list object allows either a single selection or multiple selections.

The constructors of the list class are as follows: -

(List()

(List(int rows)

(List(int rows, Boolean multiple)

These constructors creates a list object with row specifying the number of visible items. The true Boolean value allows multiple selection modes.

To add items in the list object, the following two methods can be used:

(void add(String item)

(void add(String item, int index)

The second method adds the item at the specified index. The index value zero refers to the beginning and a value denotes the end of the list.

The first method adds the item to the end of the list.List also defines various methods to find out number of visible rows, total item in the list and also to return the item at a particular position.

(Int getRows()

(int getItemCount()

(void Select(String item)

(void select(int index)

(void getItem(int index)

For Single selection list we use:

(String getSelectedItem()

(int getSelctedIndex()

For multiple selection List:

(String[] getSelectedItems()

(int[] getSelectedIndexes()

8. Scroll bar(): -Scrollbar are used to selct5ed continuous values between a specified minimum and maximum. Scrollbars may be oriented horizontally or vertically.

The constructors are as follows: -

(Scrollbar()

(Scrollbar(int style)

(Scrollbar(int style, int initial, int thumbsize, int min, int max)

Here, Style specifies orientation of the scrollbar which is defined as constants VERTICAL and HORIZONTAL in the class. The number of units represented by the height of the thumb is passed in thumbsize.

E.g.: -

Scrollbar sb =new scrollbar(Scrollbar, HORIZONTAL, 0,10,-50,100)

Methods used in scrollbar are: -

(int getvalue()

(void setvalue(int newval)

(void setMinimum(int min)

(int getMinmum()

(void setMaximum(int max)

(int getMaximum()

9. Menus: -Menus are one of the primary user interface constructs in almost any windowed application. Each user created top-level window can have its own menu bar at the top of the screen. A menu bar can have a number of drop-down menus which in turn can have menu items submenus.

Steps to create a Menu bar: -

( Create an instance of the MenuBar class.

MenuBar mb=new MenuBar();

( Attach it to the frame using the setMenuBar() method.

setMenuBar(mb);

( To create a popup, Create an instance of the Menu class.

Menu m= new Menu(background);

( Add the popup to the menubar using the add() method.

mb.add(m);

( Create and add menu items to the popup using add() and MenuItem() methods.

m.add(new MenuItem(default));

( To have separator, use addSeparator() method.

( To disable any menu item use the set Enabled (false) method.

10. Dialog: -The Dialog class is a sub class of the window class, which defines a movable top-level window with a title bar. Dialogs are separate popup window that accepts input from the user. Unlike frames they have several restrictions such as

( They cannot have menu.

( They cannot be resized.

( They must be opened by a parent window in order to exit.

EVENT HANDLING

: -`Event is object that describes a state change in a source. It can be generated by user interaction with GUI controls.

E.g.: -

Pressing a button, entering character via Keyboard, Selecting an item in the List, Clicking / Selecting a checkbox.

Handling Events

:- Event handling involves that are automatically called when a user action causes an event to take place. An event is generated in response to just about anything that a user can do during the cycle of java program. Every movement of the mouse, keyboard and button click generates an event.

Event: - It is an object that describes a state change in a source. It can be generated by user interaction with GUI control.

E.G.: - Pressing a button, entering character via keyboard.

Event Source: - It is an object that generates an event sources may generate more than one type of event.

Examples:

Public void addtypeListener(Type Listener I)

Where Type Listener is any valid Listener

e.g.: - addkeyListener();

addMouseMotionListener()

Event Classes: - Event classes are used to encapsulate the information that identifies the exact nature of the event.

1. Action Event: - The Action event class defines an integer constant, Action Performed which can be used to identify an action event. It has the following constructor.

It has the following constructor

action Event (Object source, int type, string cmdstr)

Here, Argument source is the object reference where this event is generated type is the type of event and cmdstr is the command string associated with the event source.

2. Item Event: - It event refers to a change of state that is defined by a integer constant Item state changed.

It provides the following methods:

Object getItem()

int getStateChanged()

Item Select table getItemSelectable()

Item Event is generated by checkbox, List box, choice box .

3. Mouse Event: -This Event is generated when the user moves the mouse or presses a mouse button. It defines following Methods:

int getx()

int gety()

Point getPoint()

Point getClickCount()

4. Key Event: -This event is generated by the key board inputs i.e. when a key is pressed or released.

It provide following method: -

char getkeyChar()

int getKeyCode()

5. Window Event: -This event is generated when some operation is performed on a window.

Event Listener Interfaces1. Action Listener: -

This Interface defines a method

public void actionPerformed (ActionEvent e)

When is executed when an ActionEvent is generated from a source.

2. Item Listener: -The following method of this listener is executed when the state of an item changes:

public void itemStateChanged (ItemEvent e)

3. Adjustment Listener: -The adjustmentValueChanged() method of this listener is executed when an adjustment event occurs. Its signature is as follows:

public void adjustmentValueChanged (AdjustmentEvent e)

4. Key Listener: -The methods of this interface are involved when a key is pressed or when a character has been entered. It defines the following methods:

void keyPressed (KeyEvent e)

void keyReleased (KeyEvent e)

void keyTyped (KeyEvent e)

5. Mouse Listener: -This interface defines the following five methods:

void mouseClicked (MouseEvent e)

void mouseEntered (MouseEvent e)

void mouseExited (MouseEvent e)

void mousePressed (MouseEvent e)

void mouseReleased (MouseEvent e)

6. Mouse Motion Listener: -This interface defines two methods which are executed multiple times as the mouse is moved or dragged.

void mouseDragged (MouseEvent e)

void mouseMoved (MouseEvent e)

7. Window Listener: -It defines the following methods:

void windowActivated (WindowEvent e)

void windowClosed (WindowEvent e)

void windowClosing (WindowEvent e)

void windowDeactivated (WindowEvent e)

void windowDeiconified (WindowEvent e)

void windowIconified (WindowEvent e)

void windowOpened (WindowEvent e)SWING: -The AWT is not a very satisfactory tool for creating commercial applications because it was designed to use each platforms native components. Also the component set provided by AWT is limited and not suitable for advanced applications that use trees, tables, progress bars and other complex components.

The Java Foundation classes (JFC) are collections of classes used to develop graphical user interfaces. The JFC includes swing classes.

The JFC was developed by the combined efforts of Java soft, Netscape and IBM.

JFC Also includes:- The Accessibility API (Support I/O devices to aid those with disabilities.

The java 2D classes ( Support better fonts & graphic capabilities.

Drag & Drop support ( Ability to drag and drop objects to and from a java application and a native file system application.

SWING AND AWT: -Swing is an extension (not a replacement) of the AWT. It uses the same event model and the same layout managers. Both share the common super classes component and container.

Heavy Weight vs Light Weight Components : -AWT components use native peer components to display themselves on any platform. These components are called heavy weight because they require across platforms. Swing components are entirely java components. They are called light weight because they are not directly backed by a native peer object.

Pluggable Look and Feel (PLAF)

: -Pluggable look-and- feel feature allows multiple appearances and behaviors for a single component class without having to sub class the component for every look and feel. Look part of look-and feel works for appearance while feel part comes from how components interact with the user i.e. how they respond to event.Swing Packages: -The main package used to develop swing applications is javax.swing but the java.awt is also include in import statements because swing relives heavily on the common frame work shared with the AWT components.

Hierarchy of Heavy Weight classes

JFrame: -The JFrame class implements a top-level container which is maintained by the native platform it is a direct sub class of the Frame class and is used to create a swing application. A frame can automatically close when the close button of title bar is pressed, but to make this action cause the application to exit, window listener should be used.

JApplet: -JApplet is the JFC equivalent of the AWT Applet class. It defines a heavy weight container and is used to support swing components in an applet.

JDailog: - A Dialog window is used to get input from the user on to simply inform the user of an error. It is always associated with a frame, but floats independently of it.AWT PROGRAMMINGFONT EXAMPLEimport java.awt.*;

class test4 extends Frame

{

Label l1;

Font f1;

test4()

{

super ("application Frame");

setLayout (null);

f1 = new Font("Times New Roman", Font.ITALIC,30);

l1 = new Label ("WELCOME TO JAVA WORLD");

l1.setFont(f1);

l1.setBounds (50,30,900,50);

add (l1);

setBackground (Color.blue);

setForeground (Color.red);

setSize (500,500);

show ();

}

public static void main (String arg [])

{

new test4();

}

}

import java.awt.*;

class test2 extends Frame

{

Label l1,l2 ,l4,l5,l6,l7;

TextField t1,t2;

Checkbox C1,C2 ,C5,C6,C7;

CheckboxGroup cg1,cg2;

Choice cn;

TextArea ta;

Button bt;

test2 ()

{

super ("testing Frame");

setLayout (new FlowLayout ());

l1 = new Label ("enter name"); add (l1);

t1 = new TextField (20); add(t1);

l2 = new Label ("sex"); add (l2);

cg1 = new CheckboxGroup ();

C1 = new Checkbox ("male", cg1,true); add (C1);

C2 = new Checkbox ("female", cg1,false); add (C2);

l4 = new Label ("enter age"); add (l4);

t2 = new TextField (10); add (t2);

l5 = new Label ("select your qualification"); add (l5);

C5 = new Checkbox ("bachelor degree"); add (C5);

C6 = new Checkbox ("master degree"); add (C6);

C7 = new Checkbox ("illiterate"); add (C7);

l6 = new Label ("select your branch"); add(l6);

cn = new Choice ();

cn.addItem ("ELECTRICAL");

cn.addItem ("MECHANICAL");

cn.addItem ("ENGINEERING");

add(cn);

l7 = new Label ("about you"); add (l7);

ta = new TextArea (8,15); add (ta);

bt = new Button ("submit"); add (bt);

setSize(500,500);

show ();

}

public static void main (String a[])

{

new test2 ();

}

}

import java.awt.*;

class kkk extends Frame

{

Label lb,lc,ld,lk,lm;

TextField tf;

Checkbox ch,ck,ct,rb,rc;

CheckboxGroup cg;

Choice bn;

TextArea ta;

Button bt;

kkk()

{

super("testing frame");

setLayout(null);

lb=new Label("enter your name");

lb.setBounds(50,50,150,30);

add(lb);

tf=new TextField(30);

tf.setBounds(250,50,100,30);

add(tf);

lc=new Label("select your Hobby");

lc.setBounds(50,110,100,30);

add(lc);

ch= new Checkbox("Reading");

ch.setBounds(250,110,100,30);

add(ch);

ck=new Checkbox("playing");

ck.setBounds(250,150,100,30);

add(ck);

ct=new Checkbox("Dancing");

ct.setBounds(250,190,100,30);

add(ct);

ld=new Label("select your Degree");

ld.setBounds(50,250,150,30);

add(ld);

cg=new CheckboxGroup();

rb=new Checkbox("Graduate",cg,true);

rb.setBounds(250,250,100,30);

add(rb);

rc=new Checkbox("Non-Graduate",cg,false);

rc.setBounds(250,280,100,30);

add(rc);

lk=new Label("select your branch");

lk.setBounds(50,330,150,30);

add(lk);

bn=new Choice();

bn.addItem("Infotech");

bn.addItem("CSE");

bn.addItem("ETE");

bn.addItem("EEE");

bn.addItem("CIVIL");

bn.addItem("MECHENICAL");

bn.setBounds(250,340,100,30);

add(bn);

lm=new Label("About you");

lm.setBounds(50,370,100,30);

add(lm);

ta=new TextArea();

ta.setBounds(50,400,330,80);

add(ta);

bt=new Button("SUMIT");

bt.setBounds(150,490,100,30);

add(bt);

setSize(500,550);

setBackground(Color.blue);

setForeground(Color.red);

show();

}

public static void main(String arg[])

{

new kkk();

}

}

IMAGE

import java.awt.*;

import java.awt.event.*;

public class ima extends Frame

{

Image img;

public static void main(String[] args)

{

ima ai = new ima();

}

public ima()

{

super("Image Frame");

MediaTracker mt = new MediaTracker(this);

img = Toolkit.getDefaultToolkit().getImage("aa.jpg");

mt.addImage(img,0);

setSize(400,400);

setVisible(true);

addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent we){

dispose();

}

});

}

public void update(Graphics g){

paint(g);

}

public void paint(Graphics g){

if(img != null)

g.drawImage(img, 100, 100, this);

else

g.clearRect(0, 0, getSize().width, getSize().height);

}

}

EVENT HANDLING

1) ActionListener

import java.awt.*;

import java.awt.event.*;

class test5 extends Frame implements ActionListener

{

Label lb;

TextField tf;

Button bt,ct;

test5()

{

super ("using events");

setLayout (new FlowLayout());

lb = new Label ("Enter Text");

add (lb);

tf = new TextField (20); add (tf);

bt = new Button ("Clear"); add (bt);

ct = new Button ("Exit"); add (ct);

bt.addActionListener (this);

ct.addActionListener (this);

setSize (500,500);

show();

}

public void actionPerformed (ActionEvent ae)

{

if (ae.getSource()==bt)

{

tf.setText (" ");

}

if (ae.getSource()==ct)

{

System.exit (0);

}

}

public static void main (String p[])

{

new test5 ();

}

}

APPLET import java.awt.*;

import java.applet.*;

import java.awt.event.*;

public class Abhim extends Applet implements ActionListener

{

Label lb1,lb2,lb3;

TextField tf1,tf2,tf3;

Button bt;

public void init()

{

lb1=new Label("Enter 1st no");

add(lb1);

tf1=new TextField(10);

add(tf1);

lb2=new Label("Enter 2nd no");

add(lb2);

tf2=new TextField(10);

add(tf2);

lb3=new Label("Result");

add(lb3);

tf3=new TextField(10);

add(tf3);

tf1.setText("0");

tf2.setText("0");

tf3.setText("0");

bt=new Button("ADD");add(bt);

bt.addActionListener(this);

}

public void actionPerformed(ActionEvent ae)

{

if(ae.getSource()==bt)

{

String a,b,c;

int x=0,y=0,z=0;

try

{

a=tf1.getText();

b=tf2.getText();

x=Integer.parseInt(a);

y=Integer.parseInt(b);

}

catch(Exception e)

{

}

z=x+y;

c=String.valueOf(z);

tf3.setText(c);

}

}

}

ITEMLISTENER

import java.awt.*;

import java.awt.event.*;

class shashi extends Frame implements ItemListener

{

Label lb1,lb2,lb3;

Choice ch;

shashi()

{

setLayout (new FlowLayout());

lb1 = new Label ("select Collage Name");add(lb1);

ch = new Choice();

ch.addItem("NITR");

ch.addItem("PIETR");

ch.addItem("PCER");

add(ch);

ch.addItemListener(this);

lb2=new Label("selected collage Name");add(lb2);

lb3=new Label("-------------");add(lb3);

setSize(500,500);

show();

}

public void itemStateChanged (ItemEvent a)

{

String st=ch.getSelectedItem();

int x=ch.getSelectedIndex();

lb3.setText(st);

if(x==0)

{

lb3.setBackground(Color.red);

}

if(x==1)

{

lb3.setBackground(Color.blue);

}

if(x==2)

{

lb3.setBackground(Color.yellow);

}

}

public static void main(String arg[])

{

new shashi();

}

}

WINDOWLISTENERimport java.awt.*;

import java.awt.event.*;

class sha extends Frame implements WindowListener

{

Label lb;

sha()

{

setLayout(new FlowLayout());

lb=new Label("Welcome To The Page");add(lb);

addWindowListener(this);

setSize(500,500);

show();

}

public void windowActivated(WindowEvent we)

{

}

public void windowClosed(WindowEvent we)

{

}

public void windowClosing(WindowEvent we)

{

System.exit(0);

}

public void windowDeactivated(WindowEvent we)

{

}

public void windowDeiconified(WindowEvent we)

{

}

public void windowIconified(WindowEvent we)

{

}

public void windowOpened(WindowEvent we)

{

}

public static void main(String arg[])

{

new sha();

}

}

KEYLISTENERimport java.awt.*;

import java.awt.event.*;

import java.applet.*;

public class testkey extends Applet implements KeyListener

{

String msg=" ";

int x=10,y=20;

public void init()

{

addKeyListener(this);

requestFocus();

}

public void paint(Graphics g)

{

g.drawString(msg,x,y);

}

public void keyPressed(KeyEvent ke)

{

showStatus("keypressed");

}

public void keyReleased(KeyEvent ke)

{

showStatus("keyreleased");

}

public void keyTyped(KeyEvent ke)

{

msg+=ke.getKeyChar();

showStatus("keytyped");

repaint();

}

}

hi...........

MOUSELISTENER AND MOUSEMOTIONLISTENER

import java.awt.*;

import java.awt.event.*;

import java.applet.*;

public class mousetest extends Applet implements MouseListener,MouseMotionListener

{

String msg=" ";

int x=0,y=0;

public void init()

{

addMouseListener(this);

addMouseMotionListener(this);

}

public void paint (Graphics g)

{

g.drawString (msg,x,y);

}

public void mouse Clicked (Mouse Event me)

{

y=10;

y=10;

msg = "Mouse Clicked";

repaint();

}

public void mouse Entered (Mouse Event me)

{

x=10;

y=10;

msg="Mouse entered";

repaint();

}

public void mouse Exited (Mouse Event me)

{

x=10;

y=10;

msg="Mouse Exited"

repaint();

}

public void mouse Pressed (Mouse Event me)

{

x=me.getX();

y=me.getY();

msg="Mouse Pressed";

repaint();

}

public void mouse Released(Mouse Event me)

{

X=me.getX();

y=me.getX();

msg="Mouse released";

public void mouse Dragged (Mouse Event me)

{

x=me.getX();

y=me.getY();

msg="*";

showStatus("Dragging mouse at" +x+" "+y);

repaint();

}

public void mouse Moved (MouseEvent me)

{

showStatus("Moving mouse at"+ma.get(x)+","+me.getx();

}

}

ADJUSTMENTLISTENER1.notepad.java

import java.awt.*;

import javax.swing.*;

class notepad extends JFrame

{

JMenuBar mb;

JMenu a,b,c,d,e;

JMenuItem a1,a2,a3,a4,a5,a6,a7,b1,b2,b3,b4,b5,b6,b7,c1,c2,c3,d1,e1;

menu()

{

super("NEW NOTEPAD MENU");

mb=new JMenuBar();

a=new JMenu("file");mb.add(a);

a1=new JMenuItem("New ctrl+N");a.add(a1);

a2=new JMenuItem("Open ctrl+O");a.add(a2);

a3=new JMenuItem("Close");a.add(a3);

a4=new JMenuItem("Save ctrl+S");a.add(a4);

a5=new JMenuItem("Save as");a.add(a5);

a6=new JMenuItem("Print ctrl+P");a.add(a6);

a7=new JMenuItem("Exit ctrl+E");a.add(a7);

b=new JMenu("Edit");mb.add(b);

b1=new JMenuItem("cut ctrl+X");b.add(b1);

b2=new JMenuItem("Copy ctrl+C");b.add(b2);

b3=new JMenuItem("Paste ctrl+V");b.add(b3);

b4=new JMenuItem("Undo ctrl+Z");b.add(b4);

b5=new JMenuItem("Redo ctrl+Y");b.add(b5);

b6=new JMenuItem("Delete ctrl+del");b.add(b6);

b7=new JMenuItem("Time Date");b.add(b7);

c=new JMenu("Formate");mb.add(c);

c1=new JMenuItem("Wrdrap");c.add(c1);

c2=new JMenuItem("Font");c.add(c2);

d=new JMenu("View");mb.add(d);

d1=new JMenuItem("Status Bar");d.add(d1);

e=new JMenu("Help");mb.add(e);

e1=new JMenuItem("About Notepad");e.add(e1);

setJMenuBar(mb);

setSize(850,650);

show();

}

public static void main(String arg[])

{

new notepad();

}

}

2.testtree1.java

import java.awt.*;

import javax.swing.*;

import javax.swing.tree.*;

class testtree1 extends JFrame

{

JTree jt;

DefaultMutableTreeNode d1,a,a1,c1,c2,c3,c4,f,a2,e1,e2,e3,b,b1,b2,b3;

Container cn;

testtree1()

{

d1=new DefaultMutableTreeNode("Computer");

a=new DefaultMutableTreeNode("computer");d1.add(a);

a1=new DefaultMutableTreeNode("Techical");a.add(a1);

c1=new DefaultMutableTreeNode("MCA");a1.add(c1);

c2=new DefaultMutableTreeNode("BCA");a1.add(c2);

c3=new DefaultMutableTreeNode("M.TECH");a1.add(c3);

c4=new DefaultMutableTreeNode("B.TECH");a1.add(c4);

f=new DefaultMutableTreeNode("cs+electronic");c4.add(f);

a2=new DefaultMutableTreeNode("Non Techical");a.add(a2);

e1=new DefaultMutableTreeNode("electrical");a2.add(e1);

e2=new DefaultMutableTreeNode("electronic");a2.add(e2);

e3=new DefaultMutableTreeNode("civil");a2.add(e3);

b=new DefaultMutableTreeNode("Software");d1.add(b);

b1=new DefaultMutableTreeNode("System");b.add(b1);

b2=new DefaultMutableTreeNode("Applicaion");b.add(b2);

b3=new DefaultMutableTreeNode("Servics");b.add(b3);

cn=getContentPane();

jt=new JTree(d1);

cn.add(jt);

setSize(500,500);

show();

}

public static void main(String arg[])

{

new testtree1();

}}

3.testtree.java

import java.awt.*;

import javax.swing.*;

import javax.swing.tree.*;

class testtree extends JFrame

{

JTree jt;

DefaultMutableTreeNode d1,a,a1,a2,b,b1,b2,b3;

Container cn;

testtree()

{

d1=new DefaultMutableTreeNode("Computer");

a=new DefaultMutableTreeNode("Computer");

d1.add(a);

a1=new DefaultMutableTreeNode("Electronics");a.add(a1);

a2=new DefaultMutableTreeNode("pc assembling");a.add(a2);

b=new DefaultMutableTreeNode("Software");d1.add(b);

b1=new DefaultMutableTreeNode("System");b.add(b1);

b2=new DefaultMutableTreeNode("application");b.add(b2);

b3=new DefaultMutableTreeNode("service");b.add(b3);

cn=getContentPane();

jt=new JTree(d1);

cn.add(jt);

setSize(1200,1200);

show();

}

public static void main(String arg[])

{

new testtree();

}

}

4.testtabbed.java

import java.awt.*;

import javax.swing.*;

public class testtabbed extends JFrame

{

JTabbedPane jp;

Container cn;

public testtabbed()

{

cn=getContentPane();

jp=new JTabbedPane();

jp.addTab("Country",new cpanel());

jp.addTab("Color",new copanel());

jp.addTab("Flower",new fpanel());

cn.add(jp);

setSize(500,500);

show();

}

public static void main(String arg[])

{

new testtabbed();

}

}

class cpanel extends JPanel

{

public cpanel()

{

JLabel jl1=new JLabel("INDIA");

JLabel jl2=new JLabel("PAKISTAN");

add(jl1);

add(jl2);

setBackground(Color.yellow);

}

}

class copanel extends JPanel

{

public copanel()

{

JLabel jl1=new JLabel("red");

JLabel jl2=new JLabel("green");

add(jl1);

add(jl2);

setBackground(Color.pink);

}

}

class fpanel extends JPanel

{

public fpanel()

{

JLabel jl1=new JLabel("rose");

JLabel jl2=new JLabel("lily");

add(jl1);

add(jl2);

setBackground(Color.blue);

}

}

5.testswing.java

import java.awt.*;

import javax.swing.*;

class testswing extends JFrame

{

JLabel a,b,c,d,e,f;

JTextField tf;

JPasswordField ps;

JCheckBox c1,c2;

JRadioButton r1,r2;

ButtonGroup bg;

JComboBox cb;

JList l;

JTextArea ta;

JButton bt,ct;

String branch[]={"Computer","Electrical","Mechenical","Management"};

Container cn;

testswing()

{

super("Testing event");

cn=getContentPane();

cn.setLayout(null);

a=new JLabel("Enter data");

a.setBounds(50,50,100,30);

cn.add(a);

tf=new JTextField(20);

tf.setBounds(200,50,100,20);

cn.add(tf);

b=new JLabel("Password");

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

cn.add(b);

ps=new JPasswordField(20);

ps.setBounds(200,100,100,20);

cn.add(ps);

c=new JLabel("Vichal");

c.setBounds(50,150,100,30);

cn.add(c);

c1=new JCheckBox("Bike");

c1.setBounds(200,150,80,30);

cn.add(c1);

c2=new JCheckBox("Safari");

c2.setBounds(300,150,80,30);

cn.add(c2);

d=new JLabel("Degree");

d.setBounds(50,200,80,30);

cn.add(d);

r1=new JRadioButton("Graduate");

r1.setBounds(200,200,100,30);

cn.add(r1);

r2=new JRadioButton("Non-graduate");

r2.setBounds(300,200,120,30);

cn.add(r2);

bg=new ButtonGroup();

bg.add(r1);

bg.add(r2);

e=new JLabel("Branch");

e.setBounds(50,250,80,30);

cn.add(e);

cb=new JComboBox(branch);

cb.setBounds(150,250,100,20);

cn.add(cb);

l=new JList(branch);

l.setBounds(300,250,100,80);

cn.add(l);

f=new JLabel("About you");

f.setBounds(50,350,100,30);

cn.add(f);

ta=new JTextArea(10,10);

ta.setBounds(150,360,200,100);

cn.add(ta);

bt=new JButton("submit");

bt.setBounds(100,500,100,30);

cn.add(bt);

ct=new JButton("Exit");

ct.setBounds(250,500,80,30);

cn.add(ct);

setSize(800,800);

show();

}

public static void main(String arg[])

{

new testswing();

}

}

6.testswing1.java

import java.awt.*;

import javax.swing.*;

class testswing1 extends JFrame

{

JLabel a,b,c,d,e,f;

JTextField tf;

JPasswordField ps;

JCheckBox c1,c2;

JRadioButton r1,r2;

ButtonGroup bg;

JComboBox cb;

JList l;

JTextArea ta;

JButton bt,ct;

String branch[]={"India","America","England","South Africa"};

Container cn;

testswing1()

{

super("Testing event");

cn=getContentPane();

cn.setLayout(null);

a=new JLabel("Enter Name");

a.setBounds(50,50,100,30);

cn.add(a);

tf=new JTextField(20);

tf.setBounds(200,50,100,20);

cn.add(tf);

b=new JLabel("Password");

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

cn.add(b);

ps=new JPasswordField(20);

ps.setBounds(200,100,100,20);

cn.add(ps);

c=new JLabel("Matros");

c.setBounds(50,150,100,30);

cn.add(c);

c1=new JCheckBox("Mumbai");

c1.setBounds(200,150,80,30);

cn.add(c1);

c2=new JCheckBox("Delhi");

c2.setBounds(300,150,80,30);

cn.add(c2);

d=new JLabel("Hotel");

d.setBounds(50,200,80,30);

cn.add(d);

r1=new JRadioButton("Hotel Taj");

r1.setBounds(200,200,100,30);

cn.add(r1);

r2=new JRadioButton("Five star hotel");

r2.setBounds(300,200,150,30);

cn.add(r2);

bg=new ButtonGroup();

bg.add(r1);

bg.add(r2);

e=new JLabel("Branch");

e.setBounds(50,250,80,30);

cn.add(e);

cb=new JComboBox(branch);

cb.setBounds(150,250,100,20);

cn.add(cb);

l=new JList(branch);

l.setBounds(300,250,100,80);

cn.add(l);

f=new JLabel("About you");

f.setBounds(50,350,100,30);

cn.add(f);

ta=new JTextArea(10,10);

ta.setBounds(150,360,200,100);

cn.add(ta);

bt=new JButton("submit");

bt.setBounds(100,500,100,30);

cn.add(bt);

ct=new JButton("Exit");

ct.setBounds(250,500,80,30);

cn.add(ct);

setSize(800,800);

show();

}

public static void main(String arg[])

{

new testswing1();

}

}

7.table.javaimport java.awt.*;

import javax.swing.*;

class table extends JFrame

{

JTable jt;

String name[];

table()

{

Object calls[][]=

{

{"Java",new Integer(01),new Integer(4000)},

{"Adv java",new Integer(02),new Integer(5000)},

{"RDBMS",new Integer(03),new Integer(2000)},

{"c programming", new Integer(04),new Integer(1500)},

{"c++",new Integer(05),new Integer(2000)},

};

String name[]={"Course code","Course name","fees"};

jt=new JTable(calls,name);

Container c=getContentPane();

c.setLayout(new FlowLayout());

c.add(jt);

c.add(new JScrollPane(jt),"Center");

setSize(600,600);

show();

}

public static void main(String arg[])

{

new table();

}}

8.student.javaimport java.awt.*;

import javax.swing.*;

class student extends JFrame

{

JLabel l1,l2,l3,l4,l5,l6,l7,l8,l9;

JRadioButton r1,r2;

ButtonGroup b1;

JTextField t1,t2,t3,t4,t5,t6;

Font f1,f2;

JButton bt;

ImageIcon x;

Container cn;

student()

{

super("AJIT");

cn=getContentPane();

cn.setLayout(null);

f1=new Font("Time new Roman",Font.BOLD,30);

l1=new JLabel("STUDENT APPLICATION FORM");

l1.setFont(f1);

l1.setBounds(250,230,700,50);

cn.add(l1);

f2=new Font("Time new Roman",Font.ITALIC,20);

l2=new JLabel("BITT RANCHI");

l2.setFont(f2);

l2.setBounds(400,270,450,40);

cn.add(l2);

l3=new JLabel("NAME OF STUDENT");

l3.setBounds(25,320,150,30);

cn.add(l3);

t1=new JTextField(20);

t1.setBounds(220,320,200,40);

cn.add(t1);

l4=new JLabel("FATHER`S NAME");

l4.setBounds(25,380,250,50);

cn.add(l4);

t2=new JTextField(20);

t2.setBounds(220,380,200,40);

cn.add(t2);

l5=new JLabel("DATE OF BIRTH");

l5.setBounds(500,320,250,50);

cn.add(l5);

t3=new JTextField(20);

t3.setBounds(700,320,200,40);

cn.add(t3);

l6=new JLabel("UNI/COLLEGE");

l6.setBounds(500,380,300,50);

cn.add(l6);

t4=new JTextField(20);

t4.setBounds(700,380,200,40);

cn.add(t4);

l7=new JLabel("COURSE");

l7.setBounds(25,440,300,50);

cn.add(l7);

t5=new JTextField(20);

t5.setBounds(220,440,200,40);

cn.add(t5);

l8=new JLabel("HONOURS");

l8.setBounds(500,440,300,50);cn.add(l8);

t6=new JTextField(20);

t6.setBounds(700,440,200,40);cn.add(t6);

r1=new JRadioButton("cash");

r1.setBounds(700,500,300,20);cn.add(r1);

r2=new JRadioButton("Dimand Draft");

r2.setBounds(700,530,300,20);

cn.add(r2);

b1=new ButtonGroup();

b1.add(r1);

b1.add(r2);

bt=new JButton("submit");

bt.setBounds(100,600,100,50);

cn.add(bt);

x=new ImageIcon("h.jpg");

l9=new JLabel(x);

l9.setBounds(300,25,400,200);

cn.add(l9);

setSize(1200,1200);

show();

}

public static void main(String arg[])

{

new student();

}}

9.map.java

import java.awt.*;

import javax.swing.*;

class map extends JFrame

{

JLabel lb;

ImageIcon x;

Container cn;

map()

{

super("Railway map");

cn=getContentPane();

cn.setLayout(new FlowLayout());

x=ImageIcon("d.jpg");

lb=new JLabel(x);

cn.add(lb);

setSize(500,500);

show();

}

public static void main(String arg[])

{

new map();

}}

11.menus.java

import java.awt.*;

import javax.swing.*;

class menus extends JFrame

{

JMenuBar mb;

JMenu a,b,c;

JMenuItem a1,a2,a3,a4,a5,b1,b2,b3,b4,c1,c2,c3,c4;

menus()

{

super("NEW NOTEPAD MENU");

mb=new JMenuBar();

a=new JMenu("Sports");mb.add(a);

a1=new JMenuItem("Cricket");a.add(a1);

a2=new JMenuItem("Football");a.add(a2);

a3=new JMenuItem("Hockey");a.add(a3);

a4=new JMenuItem("Tenis");a.add(a4);

a5=new JMenuItem("Badmintan");a.add(a5);

b=new JMenu("Technical");mb.add(b);

b1=new JMenuItem("MCA");b.add(b1);

b2=new JMenuItem("BCA");b.add(b2);

b3=new JMenuItem("M.TECH");b.add(b3);

b4=new JMenuItem("B.TECH");b.add(b4);

c=new JMenu("Movies");mb.add(c);

c1=new JMenuItem("Bollywood");c.add(c1);

c2=new JMenuItem("Hollywood");c.add(c2);

c3=new JMenuItem("South Indian");c.add(c3);

c4=new JMenuItem("English movies");c.add(c4);

setJMenuBar(mb);

setSize(850,650);

show();

}

public static void main(String arg[])

{

new menus();

}}

12.optionpane.java

import java.awt.*;

import javax.swing.*;

class optionpane extends JFrame

{

String st,ct,bt,vt;

JLabel lb,lc,ld,le;

Container cn;

optionpane()

{

super("using image");

cn=getContentPane();

cn.setLayout(null);

lb=new JLabel("................");

lb.setBounds(100,100,100,20);cn.add(lb);

lc=new JLabel("................");

lc.setBounds(100,120,100,20);cn.add(lc);

ld=new JLabel("................");

ld.setBounds(100,140,100,20);cn.add(ld);

le=new JLabel("................");

le.setBounds(100,160,150,20);cn.add(le);

setSize(800,800);

setBackground(Color.green);

setForeground(Color.black);

show();

JOptionPane.showMessageDialog(null,"Welcome to my page","welnote",JOptionPane.PLAIN_MESSAGE);

String st=JOptionPane.showInputDialog("enter your name");

String ct=JOptionPane.showInputDialog("mobile no.");

String bt=JOptionPane.showInputDialog("Date of Birth");

String vt=JOptionPane.showInputDialog("Address");

lb.setText(st);

lc.setText(ct);

ld.setText(bt);

le.setText(vt);

}

public static void main(String arg[])

{

new optionpane();

}}

13.font.java

import java.awt.*;

import javax.swing.*;

class font extends JFrame

{

JLabel lb;

JTextField tf;

Font f;

JButton bt;

Container cn;

font()

{

super("welcome");

cn=getContentPane();

cn.setLayout(null);

lb=new JLabel("Enter name");

f=new Font("Times New Roman",Font.ITALIC,30);

lb.setFont(f);

lb.setBounds(50,100,200,30);

cn.add(lb);

tf=new JTextField();

tf.setEditable(false);

tf.setBounds(200,100,100,30);

cn.add(tf);

bt=new JButton("submit");

bt.setBounds(100,200,100,30);

cn.add(bt);

setSize(500,500);

cn.setBackground(Color.red);

lb.setForeground(Color.white);

show();

}

public static void main(String arg[])

{

new font();

}}

14. MenuActionListener.java

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.KeyEvent;

import javax.swing.JFrame;

import javax.swing.JMenu;

import javax.swing.JMenuBar;

import javax.swing.JMenuItem;

class MenuActionListener implements ActionListener

{

public void actionPerformed(ActionEvent e)

{

new notepad();

System.out.println("Selected: " + e.getActionCommand());

}}

public class MenuActionListener

{

public static void main(final String args[])

{

JFrame frame = new JFrame("MenuSample Example");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JMenuBar menuBar = new JMenuBar();

JMenu fileMenu = new JMenu("File");

fileMenu.setMnemonic(KeyEvent.VK_F);

menuBar.add(fileMenu);

JMenuItem newMenuItem = new JMenuItem("New");

newMenuItem.addActionListener(new MenuActionListener());

fileMenu.add(newMenuItem);

frame.setJMenuBar(menuBar);

frame.setSize(350,250);

frame.setVisible(true);

}

}

15.Ajit3.java

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

class Ajit3 extends JFrame

{

JLabel l1,l2,l3,l4,l5,l6,l7,l8,l9;

JCheckBox c1,c2,c3;

JRadioButton r1,r2;

ButtonGroup b1;

JTextField t1,t2,t3,t4,t5,t6;

Font f1,f2;

JButton bt;

ImageIcon x;

Container cn;

Ajit3()

{

super("AJIT");

cn=getContentPane();

cn.setLayout(null);

f1=new Font("Time new Roman",Font.BOLD,30);

l1=new JLabel("AJIT AUTOMOBILE COMPANY");

l1.setFont(f1);

l1.setBounds(250,230,700,50);

cn.add(l1);

f2=new Font("Time new Roman",Font.ITALIC,20);

l2=new JLabel("RANCHI(JHARKHAND)");

l2.setFont(f2);

l2.setBounds(400,270,450,40);

cn.add(l2);

l3=new JLabel("FULL NAME OF HOLDER");

l3.setBounds(25,320,150,30);

cn.add(l3);

t1=new JTextField(20);

t1.setBounds(220,320,200,40);

cn.add(t1);

l4=new JLabel("DESIGNATION OF OWNER");

l4.setBounds(25,380,250,50);

cn.add(l4);

t2=new JTextField(20);

t2.setBounds(220,380,200,40);

cn.add(t2);

l5=new JLabel("REGISTRATION OF THE VEHICLE");

l5.setBounds(500,320,250,50);

cn.add(l5);

t3=new JTextField(20);

t3.setBounds(700,320,200,40);

cn.add(t3);

l6=new JLabel("ENGINE NO.");

l6.setBounds(500,380,300,50);

cn.add(l6);

t4=new JTextField(20);

t4.setBounds(700,380,200,40);

cn.add(t4);

l7=new JLabel("TYPE OF VEHICLE");

l7.setBounds(25,440,300,50);

cn.add(l7);

t5=new JTextField(20);

t5.setBounds(220,440,200,40);

cn.add(t5);

l8=new JLabel("VEHICAL NO.");

l8.setBounds(500,440,300,50);

cn.add(l8);

t6=new JTextField(20);

t6.setBounds(700,440,200,40);

cn.add(t6);

c1=new JCheckBox("RED");

c1.setBounds(25,500,300,20);

cn.add(c1);

c2=new JCheckBox("BLUE");

c2.setBounds(25,530,300,20);

cn.add(c2);

c3=new JCheckBox("YELLOW");

c3.setBounds(25,560,300,20);

cn.add(c3);

r1=new JRadioButton("cash");

r1.setBounds(700,500,300,20);

cn.add(r1);

r2=new JRadioButton("installment");

r2.setBounds(700,530,300,20);

cn.add(r2);

b1=new ButtonGroup();

b1.add(r1);

b1.add(r2);

bt=new JButton("submit");

bt.setBounds(100,600,100,50);

cn.add(bt);

x=new ImageIcon("a.jpg");

l9=new JLabel(x);

l9.setBounds(300,25,400,200);

cn.add(l9);

setSize(1200,1200);

show();

}

public static void main(String arg[])

{

new Ajit3();

}}

16.Ajit4.java

import java.awt.*;

import javax.swing.*;

class Ajit4 extends JFrame

{

String st;

JLabel lb;

Container cn;

Ajit4()

{

super("using image");

cn=getContentPane();

cn.setLayout(new FlowLayout());

lb=new JLabel("................");

cn.add(lb);

setSize(1200,1200);

show();

JOptionPane.showMessageDialog(null,"Welcome to my page","welnote",JOptionPane.PLAIN_MESSAGE);

String st=JOptionPane.showInputDialog("enter your name");

lb.setText(st);

}

public static void main(String arg[])

{

new Ajit4();

}

}

CODE TO INSERT

import java. awt.*;

import javax.swing.*;

import java.awt.event.*;

import java.sql.*;

class regi extends JFrame implements ActionListener

{

JLabel a,b,c,d;

JTextField m,n,o,p;

JButton bt;

Connection con;

ResultSet rs;

Statement st;

Container cn;

regi()

{

super("registration form");

cn=getContentPane();

cn.setLayout(null);

a=new JLabel("name");

a.setBounds(10,100,100,25);

cn.add(a);

m=new JTextField(10);

m.setBounds(120,100,150,25);

cn.add(m);

b=new JLabel("gender");

b.setBounds(10,150,100,25);

cn.add(b);

n=new JTextField(10);

n.setBounds(120,150,150,25);

cn.add(n);

c=new JLabel("date of birth");

c.setBounds(10,200,100,25);

cn.add(c);

o=new JTextField(10);

o.setBounds(120,200,150,25);

cn.add(o);

d=new JLabel("country");

d.setBounds(10,250,100,25);

cn.add(d);

p=new JTextField(10);

p.setBounds(120,250,150,25);

cn.add(p);

bt=new JButton("submit");

bt.setBounds(90,300,100,25);

cn.add(bt);

bt.addActionListener(this);

setSize(1000,1000);

show();

}

public void actionPerformed(ActionEvent ae)

{

try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

}

catch(ClassNotFoundException ce)

{

System.out.println(ce);

}

try

{

con=DriverManager.getConnection("jdbc:odbc:rss");

if(ae.getSource()==bt)

{

String aa=m.getText();

String bb=n.getText();

String cc=o.getText();

String dd=p.getText();

st=con.createStatement();

int k=st.executeUpdate("Insert into shashi values('"+aa+"','"+bb+"','"+cc+"','"+dd+"')");

m.setText("");

n.setText("");

o.setText("");

p.setText("");

}

}

catch(SQLException e)

{

System.out.print(e);

}

}

public static void main(String arg[])

{

new regi();

}

}

CODE TO SEARCH

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import java.sql.*;

class enquiry extends JFrame implements ActionListener

{

JLabel a,b;

JTextField ta;

JButton bt;

JTextArea t;

ImageIcon x;

Statement s;

String Str="";

Connection con;

Container cn;

enquiry()

{

super("Student Enquiry");

cn=getContentPane();

cn.setLayout(null);

a=new JLabel("Enter Roll no.");

a.setBounds(50,20,100,30);

cn.add(a);

ta=new JTextField(10);

ta.setBounds(160,20,100,25);

cn.add(ta);

bt=new JButton("Search");

bt.setBounds(120,60,90,25);

cn.add(bt);

bt.addActionListener(this);

t=new JTextArea(5,85);

t.setBounds(10,110,1000,80);

cn.add(t);

x=new ImageIcon("a.jpg");

b=new JLabel(x);

b.setBounds(100,250,800,400);

cn.add(b);

setSize(1000,1000);

show();

}

public void actionPerformed(ActionEvent ae)

{

try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

}

catch(ClassNotFoundException ce)

{

}

try

{

con=DriverManager.getConnection("jdbc:odbc:bba");

s=con.createStatement();

Str="name"+"\t\t"+"roll_no."+"\t\t"+"rank\n*****************************************************************************\n";

if(ae.getSource()==bt)

{

String no=ta.getText();

String Str1="select* from anjani where(roll_no='"+no+"')";

ResultSet rs=s.executeQuery(Str1);

if(rs.next())

{

Str=Str+rs.getString(1)+"\t\t"+rs.getString(2)+"\t\t"+rs.getString(3);

t.setText(Str);

}

}

}

catch(SQLException e)

{

System.out.println(e);

}

}

public static void main(String arg[])

{

new enquiry();

}

}

DELETE RECORDimport java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import java.sql.*;

class enquiry1 extends JFrame implements ActionListener

{

JLabel a;

JTextField ta;

JButton bt;

Statement s;

Connection con;

Container cn;

enquiry1()

{

super("Student Enquiry1");

cn=getContentPane();

cn.setLayout(null);

a=new JLabel("Enter Roll no.");

a.setBounds(50,20,100,30);

cn.add(a);

ta=new JTextField(10);

ta.setBounds(160,20,100,25);

cn.add(ta);

bt=new JButton("Delete");

bt.setBounds(120,60,90,25);

cn.add(bt);

bt.addActionListener(this);

setSize(1000,1000);

show();

}

public void actionPerformed(ActionEvent ae)

{

try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

}

catch(ClassNotFoundException ce)

{

}

try

{

con=DriverManager.getConnection("jdbc:odbc:bba");

s=con.createStatement();

if(ae.getSource()==bt)

{

String no=ta.getText();

String Str1="delete from anjani where(roll_no='"+no+"')";

ResultSet rs=s.executeQuery(Str1);

}

}

catch(SQLException e)

{

System.out.println(e);

}

}

public static void main(String arg[])

{

new enquiry1();

}

}

UPDATEimport java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import java.sql.*;

class enquiry2 extends JFrame implements ActionListener

{

JLabel a,c;

JTextField ta,da;

JButton bt;

Statement s;

String Str="";

Connection con;

Container cn;

ResultSet rs;

enquiry2()

{

super("Student Enquiry");

cn=getContentPane();

cn.setLayout(null);

a=new JLabel("Enter Roll no.");

a.setBounds(50,20,100,30);

cn.add(a);

ta=new JTextField(10);

ta.setBounds(160,20,100,25);

cn.add(ta);

bt=new JButton("Update");

bt.setBounds(120,90,90,25);

cn.add(bt);

bt.addActionListener(this);

c=new JLabel("New name");

c.setBounds(50,50,100,30);

cn.add(c);

da=new JTextField(10);

da.setBounds(160,50,100,25);

cn.add(da);

setSize(1000,1000);

show();

}

public void actionPerformed(ActionEvent ae)

{

try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

}

catch(ClassNotFoundException ce)

{

}

try

{

con=DriverManager.getConnection("jdbc:odbc:uua");

s=con.createStatement();

if(ae.getSource()==bt)

{

String no=ta.getText();

String nm=da.getText();

String Str1="update anjani set name='"+nm+"' where(roll_no='"+no+"')";

s=con.createStatement();

rs=s.executeQuery(Str1);

int k=s.executeUpdate(Str1);

if(rs.next())

{

}

}

}

catch(SQLException e)

{

System.out.println(e);

}

}

public static void main(String arg[])

{

new enquiry2();

}

}

DEPOSITimport java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import java.sql.*;

public class deposit extends JFrame implements ActionListener

{JLabel l1,l2,l3 ;

JTextField tf1,tf2,tf3 ;

JButton b1,b2,b3;

Container c;

Connection cn;

ResultSet rs;

Statement s;

public deposit()

{

super("deposit Sheet");

c=getContentPane();

c.setLayout(null);

l1=new JLabel("id number");

l1.setBounds(100,100,130,30); c.add(l1);

tf1=new JTextField();

tf1.setBounds(250,100,150,30); c.add(tf1);

l2=new JLabel("Ammount*");

l2.setBounds(100,150,130,30); c.add(l2);

tf2=new JTextField();

tf2.setBounds(250,150,150,30); c.add(tf2);

tf2.setEditable(false);

b1=new JButton("verify");

b1.setBounds(450,100,120,30); c.add(b1);

b2=new JButton("Deposit");

b2.setBounds(450,250,120,30); c.add(b2);

l3=new JLabel("Balance");

l3.setBounds(100,320,120,30); c.add(l3);

tf3=new JTextField();

tf3.setBounds(250,320,150,30); c.add(tf3);

tf3.setEditable(false);

b1.addActionListener(this);

b2.addActionListener(this);

setSize(800,600);

setVisible(true);

}

public void actionPerformed(ActionEvent ae)

{ try

{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

}

catch(ClassNotFoundException ce)

{

System.out.println(ce);

}

String un=tf1.getText();

try

{ cn=DriverManager.getConnection("Jdbc:Odbc:hos");

if(ae.getSource()==b1)

{ String str="select * from bill where id='"+un+"'";

s=cn.createStatement();

rs=s.executeQuery(str);

System.out.println(rs);

if(rs.next())

{

JOptionPane.showMessageDialog(null,"U R Correct","confirm",JOptionPane.INFORMATION_MESSAGE);

tf2.setEditable(true);

int amt=rs.getInt(3);

tf3.setText(String.valueOf(amt));

}

else

JOptionPane.showMessageDialog(null,"U R InCorrect","confirm",JOptionPane.INFORMATION_MESSAGE);

}

else

if(ae.getSource()==b2)

{

String s1,s4,s5;

String un1=tf2.getText();

int am=Integer.parseInt(un1);

int n1=Integer.parseInt(tf3.getText());

s=cn.createStatement();

String acn=tf1.getText();

String str="update bill set bill=bill+"+am+" where id='"+acn+"'";

int k=s.executeUpdate(str);

JOptionPane.showMessageDialog(null,"Your account is updated","Confirm",JOptionPane.INFORMATION_MESSAGE);

}

}

catch(SQLException se){

System.out.println(se);

}}

public static void main(String args[])

{

new deposit();

}

}

LOGIN PAGE

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import java.sql.*;

class user extends JFrame implements ActionListener

{

Font pl;

JLabel l1,l2,l3;

JTextField tf1;

JPasswordField jp;

JButton b1,b2,b3;

Container cn;

Connection c;

Statement s;

ResultSet rs;

public user()

{

super("Users Manual");

cn=getContentPane();

cn.setLayout(null);

l1=new JLabel("Enter User Name");

l1.setBounds(300,80,100,60); cn.add(l1);

tf1=new JTextField(20);

tf1.setBounds(450,100,150,30); cn.add(tf1);

l2=new JLabel("Enter Pin Number");

l2.setBounds(300,150,100,60); cn.add(l2);

jp=new JPasswordField(20);

jp.setBounds(450, 160,150,30); cn.add(jp);

b2=new JButton("Verify");

b2.setBounds(280,260,150,40); cn.add(b2);

b1=new JButton("Click here");

b1.setBounds(480,260,150,40); cn.add(b1);

pl=new Font("Times New Roman",Font.PLAIN,5);

l3=new JLabel("(If You Are A New User)");

l3.setBounds(490,300,150,15); cn.add(l3);

b3=new JButton("Goto Previous Page");

b3.setBounds(350,360,210,50); cn.add(b3);

b1.addActionListener(this);

b2.addActionListener(this);

b3.addActionListener(this);

setSize(900,600);

setVisible(true);

}

public void actionPerformed(ActionEvent ae)

{

try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

}

catch(ClassNotFoundException ce){}

//String pw=jp.getText();

if(ae.getSource()==b1)

{ setVisible(false);

userpro up=new userpro();

}

else

if(ae.getSource()==b2)

{ try

{ c=DriverManager.getConnection("Jdbc:Odbc:atm_records");

String un=tf1.getText();

int pw=Integer.parseInt(jp.getText());

String str="select * from user_account where name='"+un+"'";

s=c.createStatement();

rs=s.executeQuery(str);

if(rs.next())

{

if(rs.getInt(3)==pw)

{

JOptionPane.showMessageDialog(null,"YOU ARE CORRECT","confirm",JOptionPane.INFORMATION_MESSAGE);

setVisible(false);

display d=new display();

}

}

else

JOptionPane.showMessageDialog(null,"YOU ARE INCORRECT","confirm",JOptionPane.PLAIN_MESSAGE);

}

catch(SQLException se){}

}

else

if(ae.getSource()==b3)

{

setVisible(false);

chooser ch=new chooser();

}

}

public static void main(String ar[])

{ new user();

}

}

SCROLLING TEXT

import java.awt.*;

import java.awt.event.*;

class scrollcricket extends Frame implements Runnable,ActionListener

{

Button ch;

Thread t=null;

int i=0;

Font f,ff;

String s=" ICC WORLD CUP 2010-11";

public scrollcricket()

{

super("WELCOME TO THE CRICKET WORLD CUP");

t=new Thread(this);

f =new Font("Times New Roman",Font.ITALIC,65);

setLayout(null);

setBackground(Color.blue);

setForeground(Color.red);

t.start();

ff =new Font("Times New Roman",Font.BOLD,25);

ch=new Button("Goto Next page");

ch.setFont(ff);

ch.setBounds(350,500,250,100); add(ch);

ch.addActionListener(this);

setSize(1000,1000);

setVisible(true);

}

public void run()

{

while(true)

{

int k=getSize().width;

for(i=k;i>=(-730);i-=5)

{

repaint();

try

{

t.sleep(50);

}

catch(InterruptedException ie) {}

}

}

}

public void paint(Graphics g)

{

g.setFont(f);

g.setColor(Color.red);

g.drawString(s,i,200);

}

public void actionPerformed(ActionEvent ae)

{

if(ae.getSource()==ch)

{

setVisible(false);

chooser cg=new chooser();

}

}

public static void main(String ar[])

{

new scrollcricket();

}

}

TEXTAREA SCROLLINGimport javax.swing.JFrame;

import javax.swing.JScrollPane;

import javax.swing.JTextArea;

public class ScrollingTextArea extends JFrame {

JTextArea txt = new JTextArea();

JScrollPane scrolltxt = new JScrollPane(txt);

public ScrollingTextArea() {

setLayout(null);

scrolltxt.setBounds(100, 100, 300, 200);

add(scrolltxt);

}

public static void main(String[] args) {

ScrollingTextArea sta = new ScrollingTextArea();

sta.setSize(313,233);

sta.setTitle("Scrolling JTextArea with JScrollPane");

sta.show();

}

}

USE OF PRINT

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import java.sql.*;

import java.awt.print.*;

class postoffice extends JFrame implements Printable, ActionListener

{

JLabel b1,b2,b3,b4,b5,b6,b7,b8,b9,l;

JButton bt,bt1,bt2,bt3;

JTextField t2,t3,t4,t5,t6,t7,t8,t9;

JComboBox cbw;

Font f1;

Connection c;

Container cn;

Statement st;

ResultSet rs;

public postoffice()

{

super("Post office Form ");

cn=getContentPane();

cn.setLayout(null);

f1=new Font("Monotype Corsiva",Font.BOLD,35);

l=new JLabel("Form of post office");

l.setFont(f1);

l.setForeground(Color.green);

l.setBounds(400,50,500,60);

cn.add(l);

b1=new JLabel("Parcel Type");

f1=new Font("Monotype Corsiva",Font.BOLD,25);

b1.setFont(f1);

b1.setForeground(Color.red);

b1.setBounds(50,150,250,30);

cn.add(b1);

cbw=new JComboBox();

f1=new Font("Monotype Corsiva",Font.BOLD,20);

cbw.setFont(f1);

cbw.addItem("Speed Post");

cbw.addItem("Registry");

cbw.setForeground(Color.black);

cbw.setBounds(350,150,250,30);

cbw.setToolTipText("Select the Item Name");

cn.add(cbw);

b2=new JLabel("Parcel Number:");

f1=new Font("Monotype Corsiva",Font.BOLD,25);

b2.setFont(f1);

b2.setForeground(Color.red);

b2.setBounds(50,200,250,30);

cn.add(b2);

t2=new JTextField(20);

f1=new Font("Times New Roman",Font.BOLD,15);

t2.setFont(f1);

t2.setBounds(350,200,250,25);

t2.setToolTipText("Enter the Item quantity");

cn.add(t2);

b3=new JLabel("Sender Name:");

f1=new Font("Monotype Corsiva",Font.BOLD,25);

b3.setFont(f1);

b3.setForeground(Color.red);

b3.setBounds(50,250,250,30);

cn.add(b3);

t3=new JTextField(20);

f1=new Font("Times New Roman",Font.BOLD,15);

t3.setFont(f1);

t3.setBounds(350,250,250,25);

t3.setToolTipText("Sender Name");

cn.add(t3);

b4=new JLabel("Sender Address:");

f1=new Font("Monotype Corsiva",Font.BOLD,25);

b4.setFont(f1);

b4.setForeground(Color.red);

b4.setBounds(50,300,250,30);

cn.add(b4);

t4=new JTextField(20);

f1=new Font("Times New Roman",Font.BOLD,15);

t4.setFont(f1);

t4.setBounds(350,300,250,25);

cn.add(t4);

b5=new JLabel("Receiver Name:");

f1=new Font("Monotype Corsiva",Font.BOLD,25);

b5.setFont(f1);

b5.setForeground(Color.red);

b5.setBounds(50,350,250,30);

cn.add(b5);

t5=new JTextField(20);

f1=new Font("Times New Roman",Font.BOLD,15);

t5.setFont(f1);

t5.setBounds(350,350,250,25);

cn.add(t5);

b6=new JLabel("Receiver Address:");

f1=new Font("Monotype Corsiva",Font.BOLD,25);

b6.setFont(f1);

b6.setForeground(Color.red);

b6.setBounds(50,400,250,30);

cn.add(b6);

t6=new JTextField(20);

f1=new Font("Times New Roman",Font.BOLD,15);

t6.setFont(f1);

t6.setBounds(350,400,250,25);

cn.add(t6);

b7=new JLabel("Date:");

f1=new Font("Monotype Corsiva",Font.BOLD,25);

b7.setFont(f1);

b7.setForeground(Color.red);

b7.setBounds(50,450,250,30);

cn.add(b7);

t7=new JTextField(20);

f1=new Font("Times New Roman",Font.BOLD,15);

t7.setFont(f1);

t7.setBounds(350,450,250,25);

cn.add(t7);

b8=new JLabel("Contact Number:");

f1=new Font("Monotype Corsiva",Font.BOLD,25);

b8.setFont(f1);

b8.setForeground(Color.red);

b8.setBounds(50,500,250,30);

cn.add(b8);

t8=new JTextField(20);

f1=new Font("Times New Roman",Font.BOLD,15);

t8.setFont(f1);

t8.setBounds(350,500,250,25);

cn.add(t8);

b9=new JLabel("Amount:");

f1=new Font("Monotype Corsiva",Font.BOLD,25);

b9.setFont(f1);

b9.setForeground(Color.red);

b9.setBounds(50,550,250,30);

cn.add(b9);

t9=new JTextField(20);

f1=new Font("Times New Roman",Font.BOLD,15);

t9.setFont(f1);

t9.setBounds(350,550,250,25);

cn.add(t9);

bt=new JButton("Submit");

f1=new Font("Monotype Corsiva",Font.BOLD,25);

bt.setFont(f1);

bt.setForeground(Color.RED);

bt.setBounds(150,650,100,30);

cn.add(bt);

bt.addActionListener(this);

bt1=new JButton("Ok");

f1=new Font("Monotype Corsiva",Font.BOLD,25);

bt1.setFont(f1);

bt1.setForeground(Color.RED);

bt1.setBounds(300,650,100,30);

cn.add(bt1);

bt1.addActionListener(this);

bt2=new JButton("Print");

f1=new Font("Monotype Corsiva",Font.BOLD,25);

bt2.setFont(f1);

bt2.setForeground(Color.RED);

bt2.setBounds(450,650,100,30);

cn.add(bt2);

bt2.addActionListener(this);

addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent we){

dispose();

}

});

setSize(1500,1500);

setVisible(true);

}

public int print(Graphics g, PageFormat pf, int page) throws PrinterException

{

if (page > 0)

{

return NO_SUCH_PAGE;

}

Graphics2D g2d = (Graphics2D)g;

g2d.translate(pf.getImageableX(), pf.getImageableY());

g.drawString("Parcel Type :-", 20, 100);

g.drawString("Parcel Number :-", 20, 130);

g.drawString("Sender Name :-", 20, 160);

g.drawString("Sender Address :-", 20, 190);

g.drawString("Receiver Name :-", 20, 220);

g.drawString("Receiver Address :-", 20, 250);

g.drawString("Date :-", 20, 280);

g.drawString("Contact Number :-", 20, 310);

g.drawString("Amount :-", 20, 340);

String b1=(String)cbw.getSelectedItem();

String b2=t2.getText();

String b3=t3.getText();

String b4=t4.getText();

String b5=t5.getText();

String b6=t6.getText();

String b7=t7.getText();

String b8=t8.getText();

String b9=t9.getText();

g.drawString(b1,150, 100);

g.drawString(b2, 150, 130);

g.drawString(b3, 150, 160);

g.drawString(b4, 150, 190);

g.drawString(b5, 150, 220);

g.drawString(b6, 150, 250);

g.drawString(b7, 150, 280);

g.drawString(b8, 150, 310);

g.drawString(b9, 150, 340);

return PAGE_EXISTS;

}

public void actionPerformed(ActionEvent ae)

{

try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

}

catch(ClassNotFoundException ce)

{

System.out.println(ce);

}

if(ae.getSource()==bt)

{

try

{

c=DriverManager.getConnection("Jdbc:Odbc:post");

String s2,s3,s4,s5,s6,s7,s8,s9;

String parcel=(String)cbw.getSelectedItem();

s2=t2.getText();

s3=t3.getText();

s4=t4.getText();

s5=t5.getText();

s6=t6.getText();

s7=t7.getText();

s8=t8.getText();

s9=t9.getText();

if(t2.getText().equals("") | t3.getText().equals("") | t4.getText().equals("") | parcel.equals("") ) JOptionPane.showMessageDialog(null,"Please Fill in All Valid Entries!!");

else{

String pd="Select * From post_office";

st=c.createStatement();

rs=st.executeQuery(pd);

String str="insert into post_office values('"+parcel+"','"+s2+"','"+s3+"','"+s4+"','"+s5+"','"+s6+"','"+s7+"','"+s8+"','"+s9+"')";

int k=st.executeUpdate(str);

if(k==1 ){

JOptionPane.showMessageDialog(null,"Post Successfully add","Confirm",JOptionPane.INFORMATION_MESSAGE);

}

else

{

JOptionPane.showMessageDialog(null,"Item records is not Successfully add ","Confirm",JOptionPane.INFORMATION_MESSAGE);

}

}

}

catch(SQLException se)

{

System.out.println("error");

}

}

if(ae.getSource()==bt1)

{

t2.setText(" ");

t3.setText(" ");

t4.setText(" ");

}

if(ae.getSource()==bt2)

{

PrinterJob job = PrinterJob.getPrinterJob();

job.setPrintable(this);

boolean ok = job.printDialog();

if (ok)

{

try

{

job.print();

}

catch (PrinterException ex)

{

System.out.print("error");

}

}

}

}

public static void main(String arg[])

{

new postoffice();

}

}

SOUND

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.io.*;

import javax.sound.sampled.*;

public class AudioPlayer02 extends JFrame{

AudioFormat audioFormat;

AudioInputStream audioInputStream;

SourceDataLine sourceDataLine;

boolean stopPlayback = false;

final JButton stopBtn = new JButton("Stop");

final JButton playBtn = new JButton("Play");

final JTextField textField =

new JTextField("c.wav");

public static void main(String args[]){

new AudioPlayer02();

}//end main

//-------------------------------------------//

public AudioPlayer02(){//constructor

stopBtn.setEnabled(false);

playBtn.setEnabled(true);

//Instantiate and register action listeners

// on the Play and Stop buttons.

playBtn.addActionListener(

new ActionListener(){

public void actionPerformed(

ActionEvent e){

stopBtn.setEnabled(true);

playBtn.setEnabled(false);

playAudio();//Play the file

}//end actionPerformed

}//end ActionListener

);//end addActionListener()

stopBtn.addActionListener(

new ActionListener(){

public void actionPerformed(

ActionEvent e){

//Terminate playback before EOF

stopPlayback = true;

}//end actionPerformed

}//end ActionListener

);//end addActionListener()

getContentPane().add(playBtn,"West");

getContentPane().add(stopBtn,"East");

getContentPane().add(textField,"North");

setTitle("Reshma,Puja,Richa,Anshika");

setDefaultCloseOperation(EXIT_ON_CLOSE);

setSize(250,70);

setVisible(true);

}//end constructor

//-------------------------------------------//

//This method plays back audio data from an

// audio file whose name is specified in the

// text field.

private void playAudio() {

try{

File soundFile =

new File(textField.getText());

audioInputStream = AudioSystem.

getAudioInputStream(soundFile);

audioFormat = audioInputStream.getFormat();

System.out.println(audioFormat);

DataLine.Info dataLineInfo =

new DataLine.Info(

SourceDataLine.class,

audioFormat);

sourceDataLine =

(SourceDataLine)AudioSystem.getLine(

dataLineInfo);

//Create a thread to play back the data and

// start it running. It will run until the

// end of file, or the Stop button is

// clicked, whichever occurs first.

// Because of the data buffers involved,

// there will normally be a delay between

// the click on the Stop button and the

// actual termination of playback.

new PlayThread().start();

}catch (Exception e) {

e.printStackTrace();

System.exit(0);

}//end catch

}//end playAudio

//=============================================//

//Inner class to play back the data from the

// audio file.

class PlayThread extends Thread{

byte tempBuffer[] = new byte[10000];

public void run(){

try{

sourceDataLine.open(audioFormat);

sourceDataLine.start();

int cnt;

//Keep looping until the input read method

// returns -1 for empty stream or the

// user clicks the Stop button causing

// stopPlayback to switch from false to

// true.

while((cnt = audioInputStream.read(

tempBuffer,0,tempBuffer.length)) != -1

&& stopPlayback == false){

if(cnt > 0){

//Write data to the internal buffer of

// the data line where it will be

// delivered to the speaker.

sourceDataLine.write(

tempBuffer, 0, cnt);

}//end if

}//end while

//Block and wait for internal buffer of the

// data line to empty.

sourceDataLine.drain();

sourceDataLine.close();

//Prepare to playback another file

stopBtn.setEnabled(false);

playBtn.setEnabled(true);

stopPlayback = false;

}catch (Exception e) {

e.printStackTrace();

System.exit(0);

}//end catch

}//end run

}//end inner class PlayThread

//===================================//

}//end outer class AudioPlayer02.java

NOTEPAD EDITER

//THE IMPORTED LIBRARIES

import javax.swing.*;

import javax.swing.undo.*;

import java.io.*;

import java.awt.*;

import java.awt.event.*;

import javax.swing.event.*;

import java.util.*;

import javax.swing.text.*;

import java.text.*;

public class myedit extends JFrame implements ActionListener

{

public static myedit e;

//DECLARATION OF ALL THE VARIABLES USED IN THIS APPLICATION

JTextArea text = new JTextArea(0,0);

JScrollPane scroll = new JScrollPane(text);

JMenuBar mb=new JMenuBar();

JMenu FILE = new JMenu("File");

JMenu EDIT = new JMenu("Edit");

JMenu SEARCH = new JMenu("Search");

JMenu HELP = new JMenu("Help");

JMenuItem NEWFILE = new JMenuItem("New");

JMenuItem OPENFILE = new JMenuItem("Open...");

JMenuItem SAVEFILE = new JMenuItem("Save");

JMenuItem SAVEASFILE = new JMenuItem("Save As...");

JMenuItem EXITFILE = new JMenuItem("Exit");

JMenuItem CUTEDIT = new JMenuItem("Cut");

JMenuItem COPYEDIT = new JMenuItem("Copy");

JMenuItem PASTEDIT = new JMenuItem("Paste");

JMenuItem DELETEDIT = new JMenuItem("Delete");

JMenuItem SELECTEDIT = new JMenuItem("Select All");

JMenuItem TIMEDIT = new JMenuItem("Time/Date");

JCheckBoxMenuItem WORDEDIT = new JCheckBoxMenuItem("Word Wrap");

JMenuItem FONTEDIT = new JMenuItem("Set Font...");

JMenuItem FINDSEARCH = new JMenuItem("Find");

JMenuItem FINDNEXTSEARCH = new JMenuItem("Find Next");

JMenuItem ABOUTHELP = new JMenuItem("About");

JPopupMenu POPUP = new JPopupMenu();

JMenuItem CUTPOPUP = new JMenuItem("Cut");

JMenuItem COPYPOPUP = new JMenuItem("Copy");

JMenuItem PASTEPOPUP = new JMenuItem("Paste");

JMenuItem DELETEPOPUP = new JMenuItem("Delete");

JMenuItem SELECTPOPUP = new JMenuItem("Select All");

UndoManager undo = new UndoManager();

UndoAction undoAction = new UndoAction();

boolean opened = false;

String wholeText,findString,filename = null;

int ind = 0;

//CLASS FOR HANDLING UNDO MENU OPTION OF EDIT AND POPUP MENU

class UndoAction extends AbstractAction

{

public UndoAction()

{

super("Undo");

}

public void actionPerformed(ActionEvent e)

{

try

{

undo.undo();

}

catch (CannotUndoException ex)

{

System.out.println("Unable to undo: " + ex);

ex.printStackTrace();

}

update();

}

protected void update()

{

if(undo.canUndo())

{

setEnabled(true);

putValue("Undo", undo.getUndoPresentationName());

}

else

{

setEnabled(false);

putValue(Action.NAME, "Undo");

}

}

}

//DEFAULT CONSTRUCTOR OF THE MYEDIT CLASS

public myedit()

{

//SETING DEFAULT TITLE OF THE FRAME

setTitle("Untitled");

//SETTING DEFAULT SIZE OF THE FRAME

setSize(600,400);

//MAKING THE FRAME VISIBLE

setVisible(true);

//SETTING WORD WRAP TO TRUE AS DEFAULT

text.setLineWrap(true);

//SETTING THE DEFAULT STATE OF WORDWRAP MENU OPTION IN EDIT MENU

WORDEDIT.setState(true);

//SETTING THE LAYOUT OF THE FRAME

getContentPane().setLayout(new BorderLayout());

//ADDS THE SCROLLPANE CONTAINING THE TEXTAREA TO THE CONTAINER

getContentPane().add(scroll, BorderLayout.CENTER);

//ADDING THE MAIN MENUBAR TO THE FRAME

setJMenuBar(mb);

//ADDING MENUS TO THE MAIN MENUBAR

mb.add(FILE);

mb.add(EDIT);

mb.add(SEARCH);

mb.add(HELP);

//ADDING MENUITEMS TO THE FILE MENU

FILE.add(NEWFILE);

FILE.add(OPENFILE);

FILE.add(SAVEFILE);

FILE.add(SAVEASFILE);

FILE.addSeparator();

FILE.add(EXITFILE);

//ADDING MENUITEMS TO THE EDIT MENU

EDIT.add(undoAction);

EDIT.add(CUTEDIT);

EDIT.add(COPYEDIT);

EDIT.add(PASTEDIT);

EDIT.add(DELETEDIT);

EDIT.addSeparator();

EDIT.add(SELECTEDIT);

EDIT.add(TIMEDIT);

EDIT.addSeparator();

EDIT.add(WORDEDIT);

EDIT.add(FONTEDIT);

//ADDING MENUITEMS TO THE SEARCH MENU

SEARCH.add(FINDSEARCH);

SEARCH.add(FINDNEXTSEARCH);

//ADDING MENUITEM TO THE HELP MENU

HELP.add(ABOUTHELP);

//ADDING MENUITEMS TO THE POPUPMENU

POPUP.add(undoAction);

POPUP.addSeparator();

POPUP.add(CUTPOPUP);

POPUP.add(COPYPOPUP);

POPUP.add(PASTEPOPUP);

POPUP.add(DELETEPOPUP);

POPUP.addSeparator();

POPUP.add(SELECTPOPUP);

//SETTING SHORTCUT KEYS OF MENUS IN THE MAIN MENUBAR

FILE.setMnemonic(KeyEvent.VK_F);

EDIT.setMnemonic(KeyEvent.VK_E);

SEARCH.setMnemonic(KeyEvent.VK_S);

HELP.setMnemonic(KeyEvent.VK_H);

//SETTING SHORTCUT KEYS OF MENUITEMS IN THE FILE MENU

NEWFILE.setMnemonic(KeyEvent.VK_N);

OPENFILE.setMnemonic(KeyEvent.VK_O);

SAVEFILE.setMnemonic(KeyEvent.VK_S);

SAVEASFILE.setMnemonic(KeyEvent.VK_A);

EXITFILE.setMnemonic(KeyEvent.VK_X);

//SETTING SHORTCUT KEYS OF MENUITEMS IN THE EDIT MENU

CUTEDIT.setMnemonic(KeyEvent.VK_T);

COPYEDIT.setMnemonic(KeyEvent.VK_C);

PASTEDIT.setMnemonic(KeyEvent.VK_P);

DELETEDIT.setMnemonic(KeyEvent.VK_L);

SELECTEDIT.setMnemonic(KeyEvent.VK_A);

TIMEDIT.setMnemonic(KeyEvent.VK_D);

WORDEDIT.setMnemonic(KeyEvent.VK_W);

FONTEDIT.setMnemonic(KeyEvent.VK_F);

//SETTING SHORTCUT KEYS OF MENUITEMS IN THE SEARCH MENU

FINDSEARCH.setMnemonic(KeyEvent.VK_F);

FINDNEXTSEARCH.setMnemonic(KeyEvent.VK_N);

//SETTING SHORTCUT KEYS OF MENUITEM IN THE HELP MENU

ABOUTHELP.setMnemonic(KeyEvent.VK_A);

//SETTING SHORTCUT KEYS OF MENUITEMS IN THE POPUPMENU

CUTPOPUP.setMnemonic(KeyEvent.VK_T);

COPYPOPUP.setMnemonic(KeyEvent.VK_C);

PASTEPOPUP.setMnemonic(KeyEvent.VK_P);

DELETEPOPUP.setMnemonic(KeyEvent.VK_D);

SELECTPOPUP.setMnemonic(KeyEvent.VK_A);

//SETTING ACCELERATOR KEYS OF SOME MENUITEMS IN THE EDIT MENU

CUTEDIT.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,ActionEvent.CTRL_MASK));

COPYEDIT.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,ActionEvent.CTRL_MASK));

PASTEDIT.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,ActionEvent.CTRL_MASK));

//ADDING LISTENERS TO THE MENUITEMS IN FILE MENU

NEWFILE.addActionListener(this);

OPENFILE.addActionListener(this);

SAVEFILE.addActionListener(this);

SAVEASFILE.addActionListener(this);

EXITFILE.addActionListener(this);

//ADDING LISTENERS TO THE MENUITEMS IN EDIT MENU

text.getDocument().addUndoableEditListener(new UndoListener());

CUTEDIT.addActionListener(this);

COPYEDIT.addActionListener(this);

PASTEDIT.addActionListener(this);

DELETEDIT.addActionListener(this);

SELECTEDIT.addActionListener(this);

TIMEDIT.addActionListener(this);

WORDEDIT.addActionListener(this);

FONTEDIT.addActionListener(this);

//ADDING LISTENERS TO THE MENUITEMS IN SEARCH MENU

FINDSEARCH.addActionListener(this);

FINDNEXTSEARCH.addActionListener(this);

//ADDING LISTENERS TO THE MENUITEM IN HELP MENU

ABOUTHELP.addActionListener(this);

//ADDING LISTENERS TO THE MENUITEMS IN POPUPMENU

CUTPOPUP.addActionListener(this);

COPYPOPUP.addActionListener(this);

PASTEPOPUP.addActionListener(this);

DELETEPOPUP.addActionListener(this);

SELECTPOPUP.addActionListener(this);

//ADDING MOUSELISTENER TO RIGHT CLICK FOR THE POPUPLISTENER

text.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

if (e.isPopupTrigger())

{

POPUP.show(e.getComponent(),e.getX(), e.getY());

}

}

public void mouseReleased(MouseEvent e)

{

if (e.isPopupTrigger())

{

POPUP.show(e.getComponent(),e.getX(), e.getY());

}

}

});

//ADDING WINDOWLISTENER TO HANDLE CLOSE WINDOW EVENT

/*addWindowListener( new WindowAdapter()

{ public void windowClosing(WindowEvent evt)

{

int response = JOptionPane.showConfirmDialog(null, "Do you really want to quit?");

System.out.println("Inside Window Listener");

switch (response)

{

case 0:

{

dispose();

break; }

case 2:

{

//myedit x = new myedit();

System.out.println("Inside 2");

e=new myedit();

e.setVisible(true);

break;}

}

System.out.println("response is :="+response);

}

} ); */

addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

exitApln();

}

});

}

//HANDLING ALL EVENTS OF THE TEXT EDITOR

public void actionPerformed(ActionEvent e)

{

//ACTION FOR NEW MENU OPTION OF FILE MENU

if (e.getSource()==NEWFILE)

{

newfile();

}

//ACTION FOR OPEN MENU OPTION OF FILE MENU

if (e.getSource()==OPENFILE)

{

open();

}

//ACTION FOR SAVE MENU OPTION OF FILE MENU

if (e.getSource()==SAVEFILE)

{

save();

}

//ACTION FOR SAVEAS MENU OPTION OF FILE MENU

if (e.getSource()==SAVEASFILE)

{

opened=false;

save();

}

//ACTION FOR EXIT MENU OPTION OF FILE MENU

if (e.getSource()==EXITFILE)

{

exitApln();

}

//ACTION FOR CUT MENU OPTION OF EDIT MENU AND POPUPMENU

if ((e.getSource()==CUTEDIT)||(e.getSource()==CUTPOPUP))

{

text.cut();

}

//ACTION FOR COPY MENU OPTION OF EDIT MENU AND POPUPMENU

if ((e.getSource()==COPYEDIT)||(e.getSource()==COPYPOPUP))

{

text.copy();

}

//ACTION FOR PASTE MENU OPTION OF EDIT MENU AND POPUPMENU

if ((e.getSource()==PASTEDIT)||(e.getSource()==PASTEPOPUP))

{

text.paste();

}

//ACTION FOR DELETE MENU OPTION OF EDIT MENU AND POPUPMENU

if ((e.getSource()==DELETEDIT)||(e.getSource()==DELETEPOPUP))

{

text.replaceSelection(null);

}

//ACTION FOR SELECTALL MENU OPTION OF EDIT MENU AND POPUPMENU

if ((e.getSource()==SELECTEDIT)||(e.getSource()==SELECTPOPUP))

{

text.selectAll();

}

//ACTION FOR TIME/DATE MENU OPTION OF EDIT MENU

if (e.getSource()==TIMEDIT)

{

Date currDate;

String dd;

currDate = new java.util.Date();

dd=currDate.toString();

text.insert(dd,text.getCaretPosition());

}

//ACTION FOR WORD WRAP MENU OPTION OF EDIT MENU

if (e.getSource()==WORDEDIT)

{

if(WORDEDIT.isSelected())

text.setLineWrap(true);

else

text.setLineWrap(false);

}