Aplikacja wielookienkowa

0

Mam do stworzenia aplikację, która służy do zarządzania sklepem. Mam problem z odpowiednim zaplanowaniem i rozmieszczeniem okien.
Aktualnie tworze okienko logowania (JFrame), które w zależności od wprowadzonych danych tworzy różne okna (kolejny jframe dla różnych działów w firmie). I tutaj pojawia się problem, czy kolejne okna tworzyć przy pomocy JFramów i przekazywać referencje do poprzedniego, aby zarządzać ich wyświetlaniem, czy da się to zrobić w inny, lepszy i czytelniejszy sposób np. poprzez jakiś manager okien.

Drugie pytanie dotyczy tworzenia własnych komponentów, czy można stworzyć np. gotowy JFrame np.

class CommonFunctionFrame extends JFrame{}

Następnie tam dodać różne kontrolki, a później dziedziczyć po tej klasie? Bo póki co mam problem, że nie mogę wyświetlić takiego Frame'a.

0
  1. Niezłym menadżerem okien jest klasa JDesktopPane. Okna są klasy JInernalFrame, wyglądają identycznie jak JFrame, ale nie tworzą przycisków na pasku. Cały czas jest tylko jeden przycisk.
  2. Można.
0

Dzięki za odpowiedź.
Mam jednak następujący problem. Mam klasę MainViewForm, w której trzymam panel content, do którego mam zamiar dodawać różne treści, myślę też o CardLayout. Problem polega na tym, że dodając jakiś mój panel do panelu Content nic nie widać po uruchomieniu =/ Jakaś pomoc?
MainViewForm.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package computershopandservice.forms;

/**
 *
 * @author temp
 */
public class MainViewForm extends javax.swing.JFrame {

    /**
     * Creates new form ServiceMainViewForm
     */
    public MainViewForm() {
        super("Serwis");
        initComponents();
        contentPane.add(new ServiceMainPanel());
        pack();
    }

    /**
     * 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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        contentPane = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        contentPane.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        javax.swing.GroupLayout contentPaneLayout = new javax.swing.GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
            contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 646, Short.MAX_VALUE)
        );
        contentPaneLayout.setVerticalGroup(
            contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 410, Short.MAX_VALUE)
        );

        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()
                .addComponent(contentPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(contentPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainViewForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainViewForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainViewForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainViewForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainViewForm().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JPanel contentPane;
    // End of variables declaration
}

ServiceMainPanel.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package computershopandservice.forms;

/**
 *
 * @author temp
 */
public class ServiceMainPanel extends javax.swing.JPanel {

    /**
     * Creates new form ServiceMainPanel
     */
    public ServiceMainPanel() {
        initComponents();
    }

    /**
     * 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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        commonToolsPane = new javax.swing.JPanel();
        commonTools1 = new computershopandservice.forms.CommonTools();

        jButton1.setText("jButton1");

        javax.swing.GroupLayout commonTools1Layout = new javax.swing.GroupLayout(commonTools1);
        commonTools1.setLayout(commonTools1Layout);
        commonTools1Layout.setHorizontalGroup(
            commonTools1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        commonTools1Layout.setVerticalGroup(
            commonTools1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout commonToolsPaneLayout = new javax.swing.GroupLayout(commonToolsPane);
        commonToolsPane.setLayout(commonToolsPaneLayout);
        commonToolsPaneLayout.setHorizontalGroup(
            commonToolsPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(commonToolsPaneLayout.createSequentialGroup()
                .addGap(154, 154, 154)
                .addComponent(commonTools1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        commonToolsPaneLayout.setVerticalGroup(
            commonToolsPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, commonToolsPaneLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(commonTools1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(commonToolsPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(248, Short.MAX_VALUE)
                .addComponent(commonToolsPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(255, 255, 255)
                .addComponent(jButton1)
                .addContainerGap(298, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1)
                .addContainerGap())
        );
    }// </editor-fold>
    // Variables declaration - do not modify
    private computershopandservice.forms.CommonTools commonTools1;
    private javax.swing.JPanel commonToolsPane;
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration
}

1 użytkowników online, w tym zalogowanych: 0, gości: 1