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

Panels in AWT

Panels: import java.applet.*; import java.awt.*; /*<applet code="PanelDemo" width=300 height=300></applet>*/ public class PanelDemo extends Applet { public void  init() { setLayout(new BorderLayout()); Panel pn=new Panel(); Button b1=new Button("Button 1"); pn.add(b1); Button b2=new Button("Button 2"); pn.add(b2); add(pn,"North"); Panel pe=new Panel(); Button b3=new Button("Button 3"); pe.add(b3); add(pe,"East"); Panel pw=new Panel(); Button b4=new Button("Button 4"); pw.add(b4); add(pw,"West"); Panel ps=new Panel(); Button b5=new Button("Button 5"); ps.add(b5); Button b6=new Button("Button 6"); ps.add(b6); add(ps,"South"); } }

56 to 60 Java Questions

56. What is the purpose of apache tomcat? Apache server is a standalone server that is used to test servlets and create JSP pages. It is free and open source that is integrated in the Apache web server. It is fast, reliable server to configure the applications but it is hard to install. It is a servlet container that includes tools to configure and manage the server to run the applications. It can also be configured by editing XML configuration files. 57. Where pragma is used? Pragma is used inside the servlets in the header with a certain value. The value is of no-cache that tells that a servlets is acting as a proxy and it has to forward request. Pragma directives allow the compiler to use machine and operating system features while keeping the overall functionality with the Java language. These are different for different compilers. 58. Briefly explain daemon thread. Daemon thread is a low priority thread which runs in the background performs garbage collection operation for th...

41 to 45 Java Questions

41. What is nested class? If all the methods of a inner class is static then it is a nested class. 42. What is HashMap and Map? Map is Interface and Hashmap is class that implements that. 43. What are different types of access modifiers? public: Any thing declared as public can be accessed from anywhere. private: Any thing declared as private can’t be seen outside of its class. protected: Any thing declared as protected can be accessed by classes in the same package and subclasses in the other packages. default modifier : Can be accessed only to classes in the same package. 44. What is the difference between Reader/Writer and InputStream/Output Stream? The Reader/Writer class is character-oriented and the InputStream/OutputStream class is byte-oriented. 45. What is servlet? Servlets are modules that extend request/response-oriented servers, such as java-enabled web servers. For example, a servlet might be responsible for taking data in an HTML order-entry form and applyi...