/*
MyApp.java
Upon clicking on the
the menu item "myMenuItem"
from the menu "myMenu",
A dialog box will appear.
This dialog box contains
a textfield; but you cannot
enter data into it - Why?!
Thanks,
Steve.
*/
import java.awt.*;
import java.awt.event.*;
class MyApp extends Frame implements ActionListener
{
private MenuBar myMenuBar = new MenuBar();
private Menu myMenu = new Menu("myMenu"
;
private MenuItem myMenuItem = new MenuItem("myMenuItem"
;
MyApp()
{
super("MyApp"
;
setLocation(new Point(0, 0));
setSize(300, 300);
setResizable(false);
myMenuItem.addActionListener(this);
myMenu.add(myMenuItem);
myMenuBar.add(myMenu);
setMenuBar(myMenuBar);
this.addWindowListener(new windowAdapter());
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == myMenuItem)
{
MyDialog myDialog = new MyDialog(this, 300, 100);
myDialog.setModal(true);
myDialog.show();
}
}
public static void main(String[] args)
{
MyApp myApp = new MyApp();
myApp.setVisible(true);
}
}
class MyDialog extends Dialog
{
private Label myLabel;
private TextField myTextField;
public MyDialog(Frame parent, int w, int h)
{
super(parent, "MyDialog", false);
setSize(new Dimension(w, h));
setResizable(false);
myLabel = new Label("myLabel", Label.CENTER);
myTextField = new TextField(15);
myTextField.setEditable(true);
Panel myPanel = new Panel();
myPanel.setLayout(new GridLayout(1, 1));
myPanel.add(myLabel);
myPanel.add(myTextField);
add(myPanel);
}
public boolean handleEvent(Event e)
{
if (e.id == Event.WINDOW_DESTROY)
{
dispose();
}
return true;
}
}
class windowAdapter extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
e.getWindow().dispose();
System.exit(0);
}
}
MyApp.java
Upon clicking on the
the menu item "myMenuItem"
from the menu "myMenu",
A dialog box will appear.
This dialog box contains
a textfield; but you cannot
enter data into it - Why?!
Thanks,
Steve.
*/
import java.awt.*;
import java.awt.event.*;
class MyApp extends Frame implements ActionListener
{
private MenuBar myMenuBar = new MenuBar();
private Menu myMenu = new Menu("myMenu"
private MenuItem myMenuItem = new MenuItem("myMenuItem"
MyApp()
{
super("MyApp"
setLocation(new Point(0, 0));
setSize(300, 300);
setResizable(false);
myMenuItem.addActionListener(this);
myMenu.add(myMenuItem);
myMenuBar.add(myMenu);
setMenuBar(myMenuBar);
this.addWindowListener(new windowAdapter());
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == myMenuItem)
{
MyDialog myDialog = new MyDialog(this, 300, 100);
myDialog.setModal(true);
myDialog.show();
}
}
public static void main(String[] args)
{
MyApp myApp = new MyApp();
myApp.setVisible(true);
}
}
class MyDialog extends Dialog
{
private Label myLabel;
private TextField myTextField;
public MyDialog(Frame parent, int w, int h)
{
super(parent, "MyDialog", false);
setSize(new Dimension(w, h));
setResizable(false);
myLabel = new Label("myLabel", Label.CENTER);
myTextField = new TextField(15);
myTextField.setEditable(true);
Panel myPanel = new Panel();
myPanel.setLayout(new GridLayout(1, 1));
myPanel.add(myLabel);
myPanel.add(myTextField);
add(myPanel);
}
public boolean handleEvent(Event e)
{
if (e.id == Event.WINDOW_DESTROY)
{
dispose();
}
return true;
}
}
class windowAdapter extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
e.getWindow().dispose();
System.exit(0);
}
}