Oppure

Loading
03/02/08 17:33
rospo
ciao!
non so come spiegarmi bene, ma ci provo :D
io vorrei fare (in swing) un JFrame con menu. fin qui tutto ok, viene bene e facile.
quello che vorrei ora, però, è che in base alla selezione (che avviene da menu) venga caricato all'interno della pagina un JFrame diverso!
in pratica, come i frame dell'html! ho diverse pagine html con 1 base, e dentro al frame mi carico tutte le pagine web che voglio!
qui la stessa cosa! io ho gia fatto tutte le classi che funzionano, ma per richiamarle utilizzo dei bottoni! mi piacerebbe fare una schermata base e tramite il menu caricare le altre JFrame che ho gia scritto, ma sempre la dentro!
è fattibile?tipo internal frame?
ps: ho netbeans 6 come ide :D
grazie mille!
aaa
04/02/08 10:02
netarrow
perchè non ti vanno bene i JInternalFrame dentro il JDesktopPane?

ah forse ho capito che vuoi fare, potresti provare a fare il getContentPane della JFrame da mostrare e inserirlo nella JFrame principale come suo contentPane
Ultima modifica effettuata da netarrow 04/02/08 10:15
aaa
04/02/08 15:28
rospo
si, penso sia quello che voglio, ma non ho idea di come farlo!
mi dai qualche link o, magari, hai un piccolo esempio?
anche 1 cosa veramente banale, giusto x capire la base e come partire a lavorare...
grazie!
aaa
04/02/08 15:39
rospo
ho letto un po di documentazione e trovato questo su mokabyte
mokabyte.it/2001/04/…
solo che non capisco 1 cosa: io posso aggiungere in fase di programmazione oggetti, poi renderli invisibili e tramite il menu farli tornare visibili, e questo è ok.

quello che pensavo io però era tipo adattare le mie classi per permettergli di essere visualizzate in questi frame
aaa
04/02/08 15:40
rospo
esempio di una mia classe
package amministrazione;

import java.util.Vector;

/**
 *
 * @author  gio
 */
public class Dati_Personali extends javax.swing.JFrame {

    private static String Utente = "";
    private static String Tipo = "";
    private static int Codice;

    /** Creates new form Dati_Personali */
    public Dati_Personali() {
        initComponents();
        //recupero i dati dal server e li stampo
        try { // Call Web Service Operation
            scriptorium.ServerService service = new scriptorium.ServerService();
            scriptorium.Server port = service.getServerPort();
            // TODO initialize WS operation arguments here
            java.lang.String arg0 = String.valueOf(Codice);
            // TODO process result here
            java.util.List<java.lang.Object> result = port.recuperaDatiPersone(arg0);
            //salvo i valori ricevuti
            //stampo sul form i valori ricevuti
            txtCodice.setText(String.valueOf(Codice));
            txtCognome.setText((String) result.get(0));
            txtNome.setText((String) result.get(1));
            txtCF.setText((String) result.get(2));
            txtIndirizzo.setText((String) result.get(3));
            txtMail.setText((String) result.get(4));
            txtTel.setText((String) result.get(5));
            txtCellulare.setText((String) result.get(6));
        } catch (Exception ex) {
        // TODO handle custom exceptions here
        }

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtCodice = new javax.swing.JTextField();
        txtCognome = new javax.swing.JTextField();
        txtNome = new javax.swing.JTextField();
        txtCF = new javax.swing.JTextField();
        txtMail = new javax.swing.JTextField();
        txtTel = new javax.swing.JTextField();
        cmdChiudi = new javax.swing.JButton();
        cmdSalva = new javax.swing.JButton();
        labelRisposta = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txtIndirizzo = new javax.swing.JTextField();
        txtCellulare = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        txtRuolo = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Nome");

        jLabel2.setText("Cognome");

        jLabel3.setText("Codice Personale");

        jLabel4.setText("Codice Fiscale");

        jLabel5.setText("Email");

        jLabel6.setText("Telefono d'ufficio");

        txtCodice.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCodiceActionPerformed(evt);
            }
        });

        cmdChiudi.setText("Chiudi");
        cmdChiudi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdChiudiActionPerformed(evt);
            }
        });

        cmdSalva.setText("Salva le modifiche");
        cmdSalva.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdSalvaActionPerformed(evt);
            }
        });

        labelRisposta.setText("Risposta");

        jLabel7.setText("SCHEDA RIASSUNTIVA DATI PERSONALI");

        jLabel8.setText("Cellulare");

        jLabel9.setText("Indirizzo");

        jLabel10.setText("Ruolo");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel3)
                                            .addComponent(jLabel2)
                                            .addComponent(jLabel1)
                                            .addComponent(jLabel4)
                                            .addComponent(jLabel5))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel6)
                                            .addComponent(jLabel9))
                                        .addGap(24, 24, 24))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(txtIndirizzo, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE)
                                        .addComponent(txtCellulare, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE)
                                        .addComponent(txtRuolo, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE)
                                        .addComponent(txtTel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(txtMail)
                                        .addComponent(txtCF, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(txtNome, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(txtCodice, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(txtCognome, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(122, 122, 122))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(60, 60, 60)
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 279, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(203, 203, 203))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(cmdSalva)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cmdChiudi))
                            .addComponent(labelRisposta, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(373, 373, 373))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel7)
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtCodice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtCognome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtCF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel6))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addComponent(txtMail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(txtTel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtIndirizzo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtCellulare, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(35, 35, 35)
                        .addComponent(jLabel9)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(txtRuolo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(labelRisposta)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmdSalva)
                    .addComponent(cmdChiudi))
                .addContainerGap(39, Short.MAX_VALUE))
        );

        txtCodice.setEditable(false);
        labelRisposta.setVisible(false);
        txtRuolo.setEditable(false);

        pack();
    }// </editor-fold>                        
    private void txtCodiceActionPerformed(java.awt.event.ActionEvent evt) {                                          
    // TODO add your handling code here:
}                                         

    private void cmdChiudiActionPerformed(java.awt.event.ActionEvent evt) {                                          
        dispose();

    }                                         

    private void cmdSalvaActionPerformed(java.awt.event.ActionEvent evt) {                                         
        try { // Call Web Service Operation
            scriptorium.ServerService service = new scriptorium.ServerService();
            scriptorium.Server port = service.getServerPort();
            // TODO initialize WS operation arguments here
            Vector vet = new Vector();
            vet.add(0, txtCodice.getText());
            vet.add(1, txtNome.getText());
            vet.add(2, txtCognome.getText());
            vet.add(3, txtCF.getText());
            vet.add(4, txtIndirizzo.getText());
            vet.add(5, txtMail.getText());
            vet.add(6, txtTel.getText());
            vet.add(7, txtCellulare.getText());
            System.out.println(vet);
            // TODO process result here
            boolean result = port.salvaModificheDati(vet);
            if(result=true){
                labelRisposta.setText("Modifica effettuata \ncon successo");
                labelRisposta.setVisible(true);
            }else{
                labelRisposta.setText("Modifica non riuscita");
                labelRisposta.setVisible(true);
            }
        } catch (Exception ex) {
        // TODO handle custom exceptions here
            System.out.println("Errore");
        }
    }                                        

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        Utente = args[0];
        Codice = Integer.parseInt(args[1]);
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {

                new Dati_Personali().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JButton cmdChiudi;
    private javax.swing.JButton cmdSalva;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel labelRisposta;
    private javax.swing.JTextField txtCF;
    private javax.swing.JTextField txtCellulare;
    private javax.swing.JTextField txtCodice;
    private javax.swing.JTextField txtCognome;
    private javax.swing.JTextField txtIndirizzo;
    private javax.swing.JTextField txtMail;
    private javax.swing.JTextField txtNome;
    private javax.swing.JTextField txtRuolo;
    private javax.swing.JTextField txtTel;
    // End of variables declaration                   
}

vorrei poter modificare questa classe perchè, al click del menu "dati personali" venga aperta questa classe all'interno dello stesso frame del menu!
è fattibile? hai suggerimenti su come posso procedere?
aaa
05/02/08 10:43
netarrow
metti il listener sul menu e guardi con degli if-else-if cosa è stato selezionato e in quel caso fai

mainframe.setContentPane(finestradamostrare.getContentPane())

tipo

...
if(e.getSource().equals(oggettoitemmenuA)) {
mainframe.setContentPane((new A()).getContentPane())
} else if(e.getSource().equals(oggettoitemmenuB) {
mainframe.setContentPane((new B()).getContentPane())
}
...

quindi a seconda di cosa uno seleziona istanzi il frame concettualmente collegato a quel ItemMenu e setti il ContentPane della JFrame principale con quello della finestra da mostrare.

Oppure risistemi tutto usando dei JPanel o usando JDesktopPane e JInternalFrame.
aaa
05/02/08 18:25
rospo
grazie mille!!!
funziona che è una meraviglia :D :D :D
aaa