AWT Frame with Dialog Class Example
import java.awt.Button;
import java.awt.Dialog;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
*
* @author bhavesh
*/
public class MySecondFrame extends MasterAWTFrame implements ActionListener {
private Button btok;
public MySecondFrame() {
btok = new Button("OK");
//setLayout(new FlowLayout(FlowLayout.LEFT));
p2.add(btok);
btok.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
new MyDialog(this).setVisible(true);
}
public static void main(String[] args) {
// TODO code application logic here
new MySecondFrame();
}
} // end of MySecondFrame class
class MyDialog extends Dialog
{
private Button close;
public MyDialog(Frame owner) {
super(owner);
close = new Button("Close");
setLayout(new FlowLayout(FlowLayout.CENTER));
add(close);
close.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent ae) {
setVisible(false);
}
}
); // end of close button addActionListener method
setSize(300,100);
setTitle("Do you want to Close?");
} // end of Constructor
} // end of MyDialog class
import java.awt.Dialog;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
*
* @author bhavesh
*/
public class MySecondFrame extends MasterAWTFrame implements ActionListener {
private Button btok;
public MySecondFrame() {
btok = new Button("OK");
//setLayout(new FlowLayout(FlowLayout.LEFT));
p2.add(btok);
btok.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
new MyDialog(this).setVisible(true);
}
public static void main(String[] args) {
// TODO code application logic here
new MySecondFrame();
}
} // end of MySecondFrame class
class MyDialog extends Dialog
{
private Button close;
public MyDialog(Frame owner) {
super(owner);
close = new Button("Close");
setLayout(new FlowLayout(FlowLayout.CENTER));
add(close);
close.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent ae) {
setVisible(false);
}
}
); // end of close button addActionListener method
setSize(300,100);
setTitle("Do you want to Close?");
} // end of Constructor
} // end of MyDialog class
Comments
Post a Comment