import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class MainApp extends JFrame { public MainApp() { setTitle("LIDER App"); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(600, 400); setLayout(new BorderLayout()); // Crear componentes para las ventanas principales JPanel profilePanel = new JPanel(); profilePanel.setBackground(Color.WHITE); JButton profileButton = new JButton("Perfil"); profilePanel.add(profileButton); JPanel statisticsPanel = new JPanel(); statisticsPanel.setBackground(Color.BLACK); JButton statisticsButton = new JButton("Estadísticas"); statisticsPanel.add(statisticsButton); JPanel adsPanel = new JPanel(); adsPanel.setBackground(Color.GRAY); JButton adsButton = new JButton("Publicidad"); adsPanel.add(adsButton); JPanel topLeadersPanel = new JPanel(); topLeadersPanel.setBackground(Color.ORANGE); JButton topLeadersButton = new JButton("Top de Líderes"); topLeadersPanel.add(topLeadersButton); // Agregar los componentes a la ventana principal add(profilePanel, BorderLayout.CENTER); add(statisticsPanel, BorderLayout.SOUTH); add(adsPanel, BorderLayout.WEST); add(topLeadersPanel, BorderLayout.EAST); // Acción del botón para ir a la pantalla de perfil desde todas las ventanas principales ActionListener profileListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(MainApp.this, "Ir a la pantalla de perfil"); } }; profileButton.addActionListener(profileListener); statisticsButton.addActionListener(profileListener); adsButton.addActionListener(profileListener); topLeadersButton.addActionListener(profileListener); // Mostrar la ventana principal setVisible(true); } public static void main(String[] args) { new MainApp(); } }
You can use a CardLayout to switch between different views. The CardLayout is a LayoutManager that manages a set of components, known as cards. Each card is displayed in its own container, and the container is added to the layout. The CardLayout is responsible for showing a different card at any given time. The CardLayout is a very simple layout manager, but it is very