codice:
public class PannelloA extends JDialog implements ActionListener, KeyListener {
private JButton ok;
private JTextArea dn;
private JTextField serial_number;
private JTextField validita;
private JTextArea ca;
private JTextField datainizio;
private JTextField datafine;
private static SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
/**
* Costruttore
* @param frame
* @param titolo
* @param modale
* @throws HeadlessException
*/
public PannelloA(Frame frame, String titolo, boolean modale) throws HeadlessException {
super(frame, titolo, modale);
showMarcaTemporale();
}
/**
* Metodo per creare e gestire il pannello delle impostazioni
*
*/
private void showMarcaTemporale() {
// disegno il dialog
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
int width = 550;
int height = 420;
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension s = tk.getScreenSize();
setBounds((s.width - width) / 2,(s.height - height) / 2,width,height);
setResizable(false);
getContentPane().setLayout(new BorderLayout());
JPanel jp1 = new JPanel();
jp1.setLayout(new BorderLayout());
JPanel jp1_1 = new JPanel();
jp1_1.setLayout(null);
JLabel l_dn = new JLabel("DN");
l_dn.setBounds(10, 10, 50, 20);
jp1_1.add(l_dn);
dn = new JTextArea(3, 50);
dn.setLineWrap(true);
//dn.setBounds(140, 10, 350, 40);
dn.setEditable(false);
JScrollPane scrollPane1 = new JScrollPane(dn, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane1.setBounds(140, 10, 350, 60);
jp1_1.add(scrollPane1);
JLabel l_serial = new JLabel("Serial number");
l_serial.setBounds(10, 90, 80, 20);
jp1_1.add(l_serial);
serial_number = new JTextField();
serial_number.setBounds(140, 90, 350, 20);
serial_number.setEditable(false);
jp1_1.add(serial_number);
JLabel l_validita = new JLabel("Validità");
l_validita.setBounds(10, 130, 120, 20);
jp1_1.add(l_validita);
validita = new JTextField();
validita.setBounds(140, 130, 200, 20);
validita.setEditable(false);
jp1_1.add(validita);
JLabel l_ca = new JLabel("C.A. emittente");
l_ca.setBounds(10, 170, 80, 20);
jp1_1.add(l_ca);
ca = new JTextArea(3, 50);
ca.setLineWrap(true);
//ca.setBounds(140, 10, 350, 40);
ca.setEditable(false);
JScrollPane scrollPane2 = new JScrollPane(ca, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane2.setBounds(140, 170, 350, 60);
jp1_1.add(scrollPane2);
JLabel l_datainizio = new JLabel("Inizio validità");
l_datainizio.setBounds(10, 250, 80, 20);
jp1_1.add(l_datainizio);
datainizio = new JTextField();
datainizio.setBounds(140, 250, 100, 20);
datainizio.setEditable(false);
jp1_1.add(datainizio);
JLabel l_datafine = new JLabel("Fine validità");
l_datafine.setBounds(10, 290, 80, 20);
jp1_1.add(l_datafine);
datafine = new JTextField();
datafine.setBounds(140, 290, 100, 20);
datafine.setEditable(false);
jp1_1.add(datafine);
jp1.add(BorderLayout.CENTER, jp1_1);
getContentPane().add(BorderLayout.CENTER, jp1);
JPanel jp4 = new JPanel();
jp4.setLayout(new FlowLayout(FlowLayout.CENTER));
ok = new JButton("chiudi");
ok.addActionListener(this);
ok.addKeyListener(this);
jp4.add(ok);
getContentPane().add(BorderLayout.SOUTH, jp4);
ok.requestFocus();
}
/**
* Gestore degli eventi
*/
public void actionPerformed(ActionEvent e) {
if (e.getSource() == ok){
dispose();
}
}
public void keyTyped(KeyEvent e) {
}
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
((JButton)(e.getSource())).doClick();
}
}
public void keyReleased(KeyEvent e) {
}
}