/* * Projecte Fressa a JAVA * TFormDialog.java * Created on 13 / novembre / 2008, 09:15 * * @author Jordi Lagares Roset "jlagares@xtec.cat - www.lagares.org" * amb el suport del Departament d'Educacio de la Generalitat de Catalunya * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details (see the LICENSE file). */ import java.awt.*; import java.awt.event.*; public class TFormDialog extends javax.swing.JDialog { public javax.swing.JButton jButtonDAcord; public javax.swing.JButton jButtonCancelar; public int resultat = 0; public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new TFormDialog(new javax.swing.JFrame(), true).setVisible(true); } }); } public TFormDialog(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); } public TFormDialog(javax.swing.JDialog parent, boolean modal) { super(parent, modal); initComponents(); } private void initComponents() { setSize(387,280); getContentPane().setLayout(null); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Form Dialog"); setResizable(false); jButtonDAcord = new javax.swing.JButton(); //jButtonDAcord.setText("D'acord"); //jButtonDAcord.setIcon(new javax.swing.ImageIcon(this.getClass().getResource("dibuixos/dacord.gif"))); jButtonDAcord.setIcon(new javax.swing.ImageIcon(this.getClass().getResource("dibuixos/catala/ok.gif"))); jButtonDAcord.setBounds(280,175,90,33); jButtonDAcord.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); getContentPane().add(jButtonDAcord); jButtonDAcord.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonDAcordClick(); } }); jButtonCancelar = new javax.swing.JButton(); //jButtonCancelar.setText("Cancel.lar"); //jButtonCancelar.setIcon(new javax.swing.ImageIcon(this.getClass().getResource("dibuixos/cancelar.gif"))); jButtonCancelar.setIcon(new javax.swing.ImageIcon(this.getClass().getResource("dibuixos/catala/cancel.gif"))); jButtonCancelar.setBounds(280,215,90,33); jButtonCancelar.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); getContentPane().add(jButtonCancelar); jButtonCancelar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonCancelarClick(); } }); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(WindowEvent e) { Toolkit.getDefaultToolkit().removeAWTEventListener(ListenerReturnEsc); } }); } private AWTEventListener ListenerReturnEsc = new AWTEventListener() { public void eventDispatched(AWTEvent event) { KeyEvent ke = (KeyEvent)event; if (ke.getID() == KeyEvent.KEY_TYPED) { if (ke.getKeyChar() == KeyEvent.VK_ESCAPE) { jButtonCancelarClick(); } else if (ke.getKeyChar() == KeyEvent.VK_ENTER) { if (Global.EsWindowsLookAndFeel==1) { if (jButtonCancelar.isFocusOwner()) { } else { jButtonDAcordClick(); } } else { if (jButtonCancelar.isFocusOwner()) { jButtonCancelarClick() ; } else { jButtonDAcordClick(); } } } } } }; private void jButtonDAcordClick() { Toolkit.getDefaultToolkit().removeAWTEventListener(ListenerReturnEsc); resultat=1; setVisible(false); } private void jButtonCancelarClick() { Toolkit.getDefaultToolkit().removeAWTEventListener(ListenerReturnEsc); resultat=0; setVisible(false); } public void ShowModalCentered() { Toolkit.getDefaultToolkit().addAWTEventListener(ListenerReturnEsc,AWTEvent.KEY_EVENT_MASK); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = this.getSize(); if (frameSize.height > screenSize.height) frameSize.height = screenSize.height; if (frameSize.width > screenSize.width) frameSize.width = screenSize.width; this.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); this.setVisible(true); } }