Notepad in Java with various Menus and Submenus (AWT or Swings).

Posted on

Project No 06

AIM:


Design Notepad in Java with varied Menus and Submenus.  (AWT or Swings)

 THEORY:

Java’s Summary Windowing Toolkit generates occasions when person performs actions like mouse click on, key press and so on. When an occasion is fired, it’s obtained by a number of listeners that act on that occasion. Elements can deal with occasions by themselves or can delegate it to the objects known as listeners. An EventListener interface has a separate methodology for every distinct occasion sort that occasion class represents.

Low-level Occasions:

·         ComponentListener

·         ContainerListener

·         FocusListener

·         KeyListener

·         MouseListener

·         MouseMotionListener

·         WindowListener

Semantic Occasions:

·         ActionListener

·         AdjustmentListener

·         ItemListener

·         TextListener

A spot during which the varied drawing must be carried out have to be offered and that is known as the container. The container is derived from java.awt.Container class. The weather of the person interface are known as elements. The elements are derived from java.awt.Element class.

1) Button

The Button is just like a push Button in another GUIs.

Button b1= new Button (String label)

b1.addActionListener (this)

2) CheckBox

Checkboxes are person interface elements which have twin state: checked and unchecked. Clicking on it might probably change the state of the checkbox.

Java helps two sorts of checkboxes: unique and non-exclusive.

Non-exclusive:      

Checkbox c = new Checkbox (String title, Boolean state)

Unique: 

Just one among the many group of things might be chosen at a time. These are known as radio Buttons.

CheckboxGroup cg = new CheckboxGroup ();

Checkbox c= new Checkbox(“title”, Boolean state, cg);

c.addMoustListener (this);

3) Alternative

The Alternative class implements a pop-up menu that permits the person to pick an merchandise from that menu.

Alternative abc=new Alternative( );

abc.add( String title );

abc.addItemListener(this);

4) Label

This part can be utilized for displaying a single line of textual content in a container. The textual content might be modified by an utility however the person can not edit the textual content. Labels don’t generates occasions.

Label l= new Label (String textual content);

5) Checklist

The listing part presents the person with a scrolling listing of textual content gadgets. Not like Alternative, which shows solely the single-selected merchandise, the listing might be made to indicate any variety of selections within the seen window. The listing might be constructed to permit a number of choices.

Checklist acts = new Checklist( );

acts.add( String  merchandise);

acts.setMultipleMode(boolean b);  // permits a number of  choice in listing.

6) Scrollbar

Scrollbars are used to pick a worth between a specified minimal and most.

Scrollbar s= new Scrollbar( int orientation );

7) TextField

TextFields are UI elements that settle for textual content enter from the person.

TextField tx = new TextField(int columns);

8) TextArea

Textual content areas behave like TextFields Besides that they’ve extra performance to deal with great amount of textual content.

TextArea ta= new TextArea(int rows, int columns );

The structure supervisor lessons are a set of lessons that implements the java.awt. LayoutManager interface and assist to place the elements in a container.

The Primary structure managers are:

1) FlowLayout:

The FlowLayout lays out elements line smart from left to proper. When the road of elements is crammed, Circulate structure creates new line and continues laying out elements on the following line.

setLayout (new FlowLayout (int align))

setLayout (new FlowLayout (int align, int vgap, int hgap))

2) GridLayout:

This class lays out elements in away similar to spreadsheet= in rows and in columns. The elements in a grid are resized to suit their cells.

setLayout (new GridLayout (int rows, int col))

setLayout (new GridLayout (int rows, int col, int vgap, int hgap))

3) BorderLayout:

The position of the elements is specified as being, North, South, East and West. The border structure resizes the middle part to fill the remaining house.

setLayout (new BorderLayout (int vgap, int hgap))

4) CardLayout:

The CardLayout permits solely certainly one of its elements to be seen at a time. The CardLayout considers every of its elements as a card. A CardLayout is managed by a combo field.

setLayout (new CardLayout (int vgap, int hgap))

Insets are used to supply spacing across the container.

public Insets getInsets( )

{

return new Insets (10,05,15,25)

}

The Panel class is a non-abstract container. The panel can include UI elements and different containers. The default structure of the Panel is FlowLayout.

Panel p1= new Panel( )

p1.add( b1)

The body window is a full-fledged window that may comprises person interface elements like Title bar, Menu bar, and Management parts. The default structure of the body s border Format.

Body f= new body (String title);

          setVisible(boolean)

setSize(int width, int top)

setLocation( int x, int y)

setTitle(String title)

When the person tries to shut the body window, a window Closing occasion is generated that needs to be dealt with for the next to be carried out:

The sources associated to the body needs to be disposed utilizing dispose( );

For the reason that body window is the principle window of the applying, when the person closes the body, the applying itself needs to be closed utilizing exit methodology within the System class. The error worth Zero signifies regular exit i.e. System.exit(0);

Menus:

Menubar mb =new Menubar( );

Menu m =new Menu (“File”);

MenuItem m1 = new MenuItem(“Open”);

MenuItem m2 = new MenuItem(“Shut”);

CheckBoxMenuItem mc =new CheckBoxMenuItem(  )

m.add(m1);

m.addSeparator( );

m.add(mc);

m.add(m2);

mb.add(m);

myframe.setMenubar(mb);

Dialog is a pop-up window on which UI elements might be laid out. Normally they’re used to show messages and get particular information from the person. Not like frames, a dialog has a dad or mum window. The dialog is robotically closed when the dad or mum window is closed. A dialog field might be modal. A modal dialog prevents person enter to different home windows within the utility till the dialog is closed.

CONCLUSION

Java Editor is efficiently carried out.

Supply projectgeek.com