package guj;
import java.awt.BorderLayout;
import java.awt.Dialog;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import java.awt.Window;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
public class ExemploJDialog extends JDialog {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JPanel pnlBotoes = null;
private JButton btnOK = null;
public ExemploJDialog() {
super();
initialize();
}
public ExemploJDialog(Frame owner) {
super(owner);
initialize();
}
public ExemploJDialog(Dialog owner) {
super(owner);
initialize();
}
public ExemploJDialog(Window owner) {
super(owner);
initialize();
}
public ExemploJDialog(Frame owner, boolean modal) {
super(owner, modal);
initialize();
}
public ExemploJDialog(Frame owner, String title) {
super(owner, title);
initialize();
}
public ExemploJDialog(Dialog owner, boolean modal) {
super(owner, modal);
initialize();
}
public ExemploJDialog(Dialog owner, String title) {
super(owner, title);
initialize();
}
public ExemploJDialog(Window owner, ModalityType modalityType) {
super(owner, modalityType);
initialize();
}
public ExemploJDialog(Window owner, String title) {
super(owner, title);
initialize();
}
public ExemploJDialog(Frame owner, String title, boolean modal) {
super(owner, title, modal);
initialize();
}
public ExemploJDialog(Dialog owner, String title, boolean modal) {
super(owner, title, modal);
initialize();
}
public ExemploJDialog(Window owner, String title, ModalityType modalityType) {
super(owner, title, modalityType);
initialize();
}
public ExemploJDialog(Frame owner, String title, boolean modal, GraphicsConfiguration gc) {
super(owner, title, modal, gc);
initialize();
}
public ExemploJDialog(Dialog owner, String title, boolean modal, GraphicsConfiguration gc) {
super(owner, title, modal, gc);
initialize();
}
public ExemploJDialog(Window owner, String title, ModalityType modalityType, GraphicsConfiguration gc) {
super(owner, title, modalityType, gc);
initialize();
}
private void initialize() {
this.setSize(200, 100);
this.setTitle("Exemplo de JDialog");
this.setContentPane(getJContentPane());
}
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getPnlBotoes(), BorderLayout.SOUTH);
}
return jContentPane;
}
private JPanel getPnlBotoes() {
if (pnlBotoes == null) {
pnlBotoes = new JPanel();
pnlBotoes.setLayout(new FlowLayout());
pnlBotoes.add(getBtnOK(), null);
}
return pnlBotoes;
}
private JButton getBtnOK() {
if (btnOK == null) {
btnOK = new JButton();
btnOK.setText("OK");
btnOK.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
dispose();
}
});
}
return btnOK;
}
}
package guj;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class ExemploJFrame extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JPanel pnlBotoes = null;
private JButton btnTeste = null;
private JPanel getPnlBotoes() {
if (pnlBotoes == null) {
pnlBotoes = new JPanel();
pnlBotoes.setLayout(new FlowLayout());
pnlBotoes.add(getBtnTeste(), null);
}
return pnlBotoes;
}
private JButton getBtnTeste() {
if (btnTeste == null) {
btnTeste = new JButton();
btnTeste.setText("Chame o JDialog Teste");
btnTeste.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
ExemploJDialog ejd = new ExemploJDialog (ExemploJFrame.this);
ejd.setModal(true);
ejd.setVisible(true);
}
});
}
return btnTeste;
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
final ExemploJFrame ejf = new ExemploJFrame();
ejf.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
ejf.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
int opcoes = JOptionPane.showConfirmDialog (ejf, "Deseja sair?", "Exemplo JFrame + JDialog",
JOptionPane.YES_NO_OPTION);
if (opcoes == JOptionPane.YES_OPTION) {
ejf.dispose();
System.exit (0);
}
}
});
ejf.setVisible(true);
}
});
}
public ExemploJFrame() {
super();
initialize();
}
private void initialize() {
this.setSize(300, 200);
this.setContentPane(getJContentPane());
this.setTitle("Exemplo de JFrame");
}
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getPnlBotoes(), BorderLayout.SOUTH);
}
return jContentPane;
}
}