Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Java - JFrame in JFrame
Forum - Java - JFrame in JFrame

Avatar
rospo (Normal User)
Newbie


Messaggi: 9
Iscritto: 03/02/2008

Segnala al moderatore
Postato alle 18:33
Domenica, 03/02/2008
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!

PM Quote
Avatar
netarrow (Admin)
Guru^2


Messaggi: 2502
Iscritto: 12/05/2004

Segnala al moderatore
Postato alle 11:02
Lunedì, 04/02/2008
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 il 04/02/2008 alle 11:15
PM Quote
Avatar
rospo (Normal User)
Newbie


Messaggi: 9
Iscritto: 03/02/2008

Segnala al moderatore
Postato alle 16:28
Lunedì, 04/02/2008
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!

PM Quote
Avatar
rospo (Normal User)
Newbie


Messaggi: 9
Iscritto: 03/02/2008

Segnala al moderatore
Postato alle 16:39
Lunedì, 04/02/2008
ho letto un po di documentazione e trovato questo su mokabyte
http://www.mokabyte.it/2001/04/swing8.htm
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

PM Quote
Avatar
rospo (Normal User)
Newbie


Messaggi: 9
Iscritto: 03/02/2008

Segnala al moderatore
Postato alle 16:40
Lunedì, 04/02/2008
esempio di una mia classe
Codice sorgente - presumibilmente Java

  1. package amministrazione;
  2.  
  3. import java.util.Vector;
  4.  
  5. /**
  6.  *
  7.  * @author  gio
  8.  */
  9. public class Dati_Personali extends javax.swing.JFrame {
  10.  
  11.     private static String Utente = "";
  12.     private static String Tipo = "";
  13.     private static int Codice;
  14.  
  15.     /** Creates new form Dati_Personali */
  16.     public Dati_Personali() {
  17.         initComponents();
  18.         //recupero i dati dal server e li stampo
  19.         try { // Call Web Service Operation
  20.             scriptorium.ServerService service = new scriptorium.ServerService();
  21.             scriptorium.Server port = service.getServerPort();
  22.             // TODO initialize WS operation arguments here
  23.             java.lang.String arg0 = String.valueOf(Codice);
  24.             // TODO process result here
  25.             java.util.List<java.lang.Object> result = port.recuperaDatiPersone(arg0);
  26.             //salvo i valori ricevuti
  27.             //stampo sul form i valori ricevuti
  28.             txtCodice.setText(String.valueOf(Codice));
  29.             txtCognome.setText((String) result.get(0));
  30.             txtNome.setText((String) result.get(1));
  31.             txtCF.setText((String) result.get(2));
  32.             txtIndirizzo.setText((String) result.get(3));
  33.             txtMail.setText((String) result.get(4));
  34.             txtTel.setText((String) result.get(5));
  35.             txtCellulare.setText((String) result.get(6));
  36.         } catch (Exception ex) {
  37.         // TODO handle custom exceptions here
  38.         }
  39.  
  40.     }
  41.  
  42.     /** This method is called from within the constructor to
  43.      * initialize the form.
  44.      * WARNING: Do NOT modify this code. The content of this method is
  45.      * always regenerated by the Form Editor.
  46.      */
  47.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  48.     private void initComponents() {
  49.  
  50.         jLabel1 = new javax.swing.JLabel();
  51.         jLabel2 = new javax.swing.JLabel();
  52.         jLabel3 = new javax.swing.JLabel();
  53.         jLabel4 = new javax.swing.JLabel();
  54.         jLabel5 = new javax.swing.JLabel();
  55.         jLabel6 = new javax.swing.JLabel();
  56.         txtCodice = new javax.swing.JTextField();
  57.         txtCognome = new javax.swing.JTextField();
  58.         txtNome = new javax.swing.JTextField();
  59.         txtCF = new javax.swing.JTextField();
  60.         txtMail = new javax.swing.JTextField();
  61.         txtTel = new javax.swing.JTextField();
  62.         cmdChiudi = new javax.swing.JButton();
  63.         cmdSalva = new javax.swing.JButton();
  64.         labelRisposta = new javax.swing.JLabel();
  65.         jLabel7 = new javax.swing.JLabel();
  66.         txtIndirizzo = new javax.swing.JTextField();
  67.         txtCellulare = new javax.swing.JTextField();
  68.         jLabel8 = new javax.swing.JLabel();
  69.         jLabel9 = new javax.swing.JLabel();
  70.         jLabel10 = new javax.swing.JLabel();
  71.         txtRuolo = new javax.swing.JTextField();
  72.  
  73.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  74.  
  75.         jLabel1.setText("Nome");
  76.  
  77.         jLabel2.setText("Cognome");
  78.  
  79.         jLabel3.setText("Codice Personale");
  80.  
  81.         jLabel4.setText("Codice Fiscale");
  82.  
  83.         jLabel5.setText("Email");
  84.  
  85.         jLabel6.setText("Telefono d'ufficio");
  86.  
  87.         txtCodice.addActionListener(new java.awt.event.ActionListener() {
  88.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  89.                 txtCodiceActionPerformed(evt);
  90.             }
  91.         });
  92.  
  93.         cmdChiudi.setText("Chiudi");
  94.         cmdChiudi.addActionListener(new java.awt.event.ActionListener() {
  95.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  96.                 cmdChiudiActionPerformed(evt);
  97.             }
  98.         });
  99.  
  100.         cmdSalva.setText("Salva le modifiche");
  101.         cmdSalva.addActionListener(new java.awt.event.ActionListener() {
  102.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  103.                 cmdSalvaActionPerformed(evt);
  104.             }
  105.         });
  106.  
  107.         labelRisposta.setText("Risposta");
  108.  
  109.         jLabel7.setText("SCHEDA RIASSUNTIVA DATI PERSONALI");
  110.  
  111.         jLabel8.setText("Cellulare");
  112.  
  113.         jLabel9.setText("Indirizzo");
  114.  
  115.         jLabel10.setText("Ruolo");
  116.  
  117.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  118.         getContentPane().setLayout(layout);
  119.         layout.setHorizontalGroup(
  120.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  121.             .addGroup(layout.createSequentialGroup()
  122.                 .addContainerGap()
  123.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  124.                     .addGroup(layout.createSequentialGroup()
  125.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  126.                             .addGroup(layout.createSequentialGroup()
  127.                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  128.                                     .addGroup(layout.createSequentialGroup()
  129.                                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  130.                                             .addComponent(jLabel3)
  131.                                             .addComponent(jLabel2)
  132.                                             .addComponent(jLabel1)
  133.                                             .addComponent(jLabel4)
  134.                                             .addComponent(jLabel5))
  135.                                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE))
  136.                                     .addGroup(layout.createSequentialGroup()
  137.                                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  138.                                             .addComponent(jLabel6)
  139.                                             .addComponent(jLabel9))
  140.                                         .addGap(24, 24, 24))
  141.                                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  142.                                         .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE)
  143.                                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
  144.                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  145.                                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  146.                                         .addComponent(txtIndirizzo, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE)
  147.                                         .addComponent(txtCellulare, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE)
  148.                                         .addComponent(txtRuolo, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE)
  149.                                         .addComponent(txtTel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE))
  150.                                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
  151.                                         .addComponent(txtMail)
  152.                                         .addComponent(txtCF, javax.swing.GroupLayout.Alignment.LEADING)
  153.                                         .addComponent(txtNome, javax.swing.GroupLayout.Alignment.LEADING)
  154.                                         .addComponent(txtCodice, javax.swing.GroupLayout.Alignment.LEADING)
  155.                                         .addComponent(txtCognome, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)))
  156.                                 .addGap(122, 122, 122))
  157.                             .addGroup(layout.createSequentialGroup()
  158.                                 .addGap(60, 60, 60)
  159.                                 .addComponent(jLabel7)
  160.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
  161.                             .addGroup(layout.createSequentialGroup()
  162.                                 .addComponent(jLabel10)
  163.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 279, javax.swing.GroupLayout.PREFERRED_SIZE)))
  164.                         .addGap(203, 203, 203))
  165.                     .addGroup(layout.createSequentialGroup()
  166.                         .addGap(12, 12, 12)
  167.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  168.                             .addGroup(layout.createSequentialGroup()
  169.                                 .addComponent(cmdSalva)
  170.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  171.                                 .addComponent(cmdChiudi))
  172.                             .addComponent(labelRisposta, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE))
  173.                         .addGap(373, 373, 373))))
  174.         );
  175.         layout.setVerticalGroup(
  176.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  177.             .addGroup(layout.createSequentialGroup()
  178.                 .addContainerGap()
  179.                 .addComponent(jLabel7)
  180.                 .addGap(6, 6, 6)
  181.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  182.                     .addComponent(jLabel3)
  183.                     .addComponent(txtCodice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  184.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  185.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  186.                     .addComponent(jLabel2)
  187.                     .addComponent(txtCognome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  188.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  189.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  190.                     .addComponent(jLabel1)
  191.                     .addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  192.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  193.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  194.                     .addComponent(jLabel4)
  195.                     .addComponent(txtCF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  196.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  197.                     .addGroup(layout.createSequentialGroup()
  198.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  199.                         .addComponent(jLabel5)
  200.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  201.                         .addComponent(jLabel6))
  202.                     .addGroup(layout.createSequentialGroup()
  203.                         .addGap(4, 4, 4)
  204.                         .addComponent(txtMail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  205.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  206.                         .addComponent(txtTel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  207.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
  208.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  209.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  210.                     .addGroup(layout.createSequentialGroup()
  211.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  212.                             .addComponent(txtIndirizzo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  213.                             .addComponent(jLabel8))
  214.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  215.                         .addComponent(txtCellulare, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  216.                     .addGroup(layout.createSequentialGroup()
  217.                         .addGap(35, 35, 35)
  218.                         .addComponent(jLabel9)))
  219.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  220.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  221.                     .addComponent(jLabel10)
  222.                     .addComponent(txtRuolo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  223.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  224.                 .addComponent(labelRisposta)
  225.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  226.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  227.                     .addComponent(cmdSalva)
  228.                     .addComponent(cmdChiudi))
  229.                 .addContainerGap(39, Short.MAX_VALUE))
  230.         );
  231.  
  232.         txtCodice.setEditable(false);
  233.         labelRisposta.setVisible(false);
  234.         txtRuolo.setEditable(false);
  235.  
  236.         pack();
  237.     }// </editor-fold>                        
  238.     private void txtCodiceActionPerformed(java.awt.event.ActionEvent evt) {                                          
  239.     // TODO add your handling code here:
  240. }                                        
  241.  
  242.     private void cmdChiudiActionPerformed(java.awt.event.ActionEvent evt) {                                          
  243.         dispose();
  244.  
  245.     }                                        
  246.  
  247.     private void cmdSalvaActionPerformed(java.awt.event.ActionEvent evt) {                                        
  248.         try { // Call Web Service Operation
  249.             scriptorium.ServerService service = new scriptorium.ServerService();
  250.             scriptorium.Server port = service.getServerPort();
  251.             // TODO initialize WS operation arguments here
  252.             Vector vet = new Vector();
  253.             vet.add(0, txtCodice.getText());
  254.             vet.add(1, txtNome.getText());
  255.             vet.add(2, txtCognome.getText());
  256.             vet.add(3, txtCF.getText());
  257.             vet.add(4, txtIndirizzo.getText());
  258.             vet.add(5, txtMail.getText());
  259.             vet.add(6, txtTel.getText());
  260.             vet.add(7, txtCellulare.getText());
  261.             System.out.println(vet);
  262.             // TODO process result here
  263.             boolean result = port.salvaModificheDati(vet);
  264.             if(result=true){
  265.                 labelRisposta.setText("Modifica effettuata \ncon successo");
  266.                 labelRisposta.setVisible(true);
  267.             }else{
  268.                 labelRisposta.setText("Modifica non riuscita");
  269.                 labelRisposta.setVisible(true);
  270.             }
  271.         } catch (Exception ex) {
  272.         // TODO handle custom exceptions here
  273.             System.out.println("Errore");
  274.         }
  275.     }                                        
  276.  
  277.     /**
  278.      * @param args the command line arguments
  279.      */
  280.     public static void main(String args[]) {
  281.         Utente = args[0];
  282.         Codice = Integer.parseInt(args[1]);
  283.         java.awt.EventQueue.invokeLater(new Runnable() {
  284.  
  285.             public void run() {
  286.  
  287.                 new Dati_Personali().setVisible(true);
  288.             }
  289.         });
  290.     }
  291.     // Variables declaration - do not modify                    
  292.     private javax.swing.JButton cmdChiudi;
  293.     private javax.swing.JButton cmdSalva;
  294.     private javax.swing.JLabel jLabel1;
  295.     private javax.swing.JLabel jLabel10;
  296.     private javax.swing.JLabel jLabel2;
  297.     private javax.swing.JLabel jLabel3;
  298.     private javax.swing.JLabel jLabel4;
  299.     private javax.swing.JLabel jLabel5;
  300.     private javax.swing.JLabel jLabel6;
  301.     private javax.swing.JLabel jLabel7;
  302.     private javax.swing.JLabel jLabel8;
  303.     private javax.swing.JLabel jLabel9;
  304.     private javax.swing.JLabel labelRisposta;
  305.     private javax.swing.JTextField txtCF;
  306.     private javax.swing.JTextField txtCellulare;
  307.     private javax.swing.JTextField txtCodice;
  308.     private javax.swing.JTextField txtCognome;
  309.     private javax.swing.JTextField txtIndirizzo;
  310.     private javax.swing.JTextField txtMail;
  311.     private javax.swing.JTextField txtNome;
  312.     private javax.swing.JTextField txtRuolo;
  313.     private javax.swing.JTextField txtTel;
  314.     // End of variables declaration                  
  315. }


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?

PM Quote
Avatar
netarrow (Admin)
Guru^2


Messaggi: 2502
Iscritto: 12/05/2004

Segnala al moderatore
Postato alle 11:43
Martedì, 05/02/2008
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.

PM Quote
Avatar
rospo (Normal User)
Newbie


Messaggi: 9
Iscritto: 03/02/2008

Segnala al moderatore
Postato alle 19:25
Martedì, 05/02/2008
grazie mille!!!
funziona che è una meraviglia :D :D :D

PM Quote