Skip to main content

Menus & Menubars

Menus & Menubars

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*<applet code="MenuBarDemo" width=300 height=300></applet>*/
class MenuFrame extends Frame implements ActionListener, ItemListener, WindowListener
{
MenuBarDemo mbd;
MenuFrame(String title, MenuBarDemo mbd)
{
super(title);
this.mbd=mbd;
addWindowListener(this);
MenuBar mb=new MenuBar();
setMenuBar(mb);
Menu file=new Menu("File");
mb.add(file);
MenuItem open=new MenuItem("Open");
file.add(open);
MenuItem save=new MenuItem("Save");
file.add(save);

Menu edit=new Menu("Edit");
mb.add(edit);
MenuItem cut=new MenuItem("Cut");
edit.add(cut);
MenuItem copy=new MenuItem("Copy");
edit.add(copy);
MenuItem paste=new MenuItem("Paste");
edit.add(paste);
Menu option =new Menu("Option");
mb.add(option);
CheckboxMenuItem zoom=new CheckboxMenuItem("Zoom");
zoom.addItemListener(this);
option.add(zoom);
CheckboxMenuItem view=new CheckboxMenuItem("View");
view.addItemListener(this);
option.add(view);
}
public void actionPerformed(ActionEvent ae)
{
mbd.ta.append("ActionEvent:"+ae.getActionCommand()+"\n");
}
public void itemStateChanged(ItemEvent ie)
{
CheckboxMenuItem cmi=(CheckboxMenuItem)ie.getSource();
mbd.ta.append("ItemEvent:"+cmi.getLabel()+"\n");
}
public void windowActivated(WindowEvent we)
{
}
public void windowClosed(WindowEvent we)
{
}
public void windowClosing(WindowEvent we)
{
dispose();
}
public void windowDeactivated(WindowEvent we)
{
}
public void windowDeiconified(WindowEvent we)
{
}
public void windowIconified(WindowEvent we)
{
}
public void windowOpened(WindowEvent we)
{
}
}
public class MenuBarDemo extends Applet
{
TextArea ta;
public void init()
{
MenuFrame mf=new MenuFrame("My Frame",this);
mf.show();
mf.setSize(600,600);
ta=new TextArea(30,30);
add(ta);
}
}

Comments

Popular posts from this blog

What is Servet ?

A servlet is a java class that extends an application hosted on a web server. Handles the HTTP request-response process (for our purposes) Often thought of as an applet that runs on a server. Provides a component base architecture for web development, using the Java Platform The foundation for Java Server Pages (JSP). Alternative to CGI scripting and platform specific server side applications.

Latest Java 6 to 10

6. What are the access modifiers in java ? There are 3 access modifiers. Public, protected and private, and the default one if no identifier is specified is called friendly, but programmer cannot specify the friendly identifier explicitly. 7. What is are packages? A package is a collection of related classes and interfaces providing access protection and namespace management. 8. What is meant by Inheritance and what are its advantages? Inheritance is the process of inheriting all the features from a class. The advantages of inheritance are reusability of code and accessibility of variables and methods of the super class by subclasses. 9. What is the difference between superclass and subclass? A super class is a class that is inherited whereas sub class is a class that does the inheriting. 10. What is an abstract class? An abstract class is a class designed with implementation gaps for subclasses to fill in and is deliberately incomplete.

51 to 55 Java Questions

51. What is the difference between a constructor and a method? A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator. A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator. 52. What will happen to the Exception object after exception handling? Exception object will be garbage collected. 53. Difference between static and dynamic class loading. Static class loading: The process of loading a class using new operator is called static class loading. Dynamic class loading: The process of loading a class at runtime is called dynamic class loading. Dynamic class loading can be done by using Class.forName(….).newInstance(). 54. Explain the Common use of EJB The EJBs can be used to incorporate business logic in a web-centric application. The EJBs can b...