Skip to main content

Dialogs and File Dialogs


Dialogs and File Dialogs

import java.awt.*;
import java.awt.event.*;
public class MessageDialogDemo extends Frame implements ActionListener
{
Button b;
public static void main(String s[])
{
MessageDialogDemo md=new MessageDialogDemo();
md.setVisible(true);
md.setSize(300,300);
}
MessageDialogDemo()
{
super("Message Dialog Demo.......");
setLayout(new FlowLayout());
b=new Button("Message Dialog");
b.addActionListener(this);
add(b);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent ae)
{
String msg="This is the message";
MessageDialog md= new MessageDialog(this, "Message Dialog", true, msg);
md.show();
}
}
class MessageDialog extends Dialog implements ActionListener
{
Button ok;
MessageDialog(Frame parent, String title, boolean mode, String msg)
{
super(parent, title, mode);
Panel pc=new Panel();
Label lbl=new Label(msg);
pc.add(lbl);
add(pc, "Center");

Panel ps=new Panel();
ok=new Button("OK");
ok.addActionListener(this);
ps.add(ok);
add(ps, "South");
pack();
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
});
}
public Insets getInsets()
{
return new Insets(40,20,20,20);
}
public void actionPerformed(ActionEvent ae)
{
dispose();
}
}

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.

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"); } }