// Multiventana (1 a 4) import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.media.opengl.*; import javax.media.opengl.glu.*; import com.sun.opengl.util.GLUT; public class MultiPanel extends JFrame { Rectangle DIM = null; JMenu Opciones; JMenuItem Paneles[] = new JMenuItem[11]; // Son 10 combinaciones y uno para la opciOn salir JMenuItem menuItem; PanelVista Ventanitas[] = new PanelVista[4]; int VPrev = 4; // Indica la cantidad de ventanas creadas con anterioridad. 4 al iniciar ... int Ancho, Alto; public MultiPanel () { int PanelN = 0; String PanelTitulo[] = {"Uno", "2Horizontal", "2Vertical", "3Horizontal", "3Vertical", "3_VHH", "3_HHV", "3_VVH", "3_HVV", "4", "Salir"}; getContentPane().setLayout(null); setTitle("Varias Vistas ... "); setResizable(false); setBounds(50, 50, 900, 900); toFront(); JMenuBar BarraMenu = new JMenuBar(); Opciones = InsertaMenu("Opciones"); while(PanelN != 11) { Paneles[PanelN] = new JMenuItem(); InsertaItem(Opciones, Paneles[PanelN], PanelTitulo[PanelN]); PanelN++; } BarraMenu.add(Opciones); setJMenuBar(BarraMenu); this.setVisible(true); DIM = this.getBounds(); Ventanitas[0] = new PanelVista(Color.blue, 1, 1); Ventanitas[1] = new PanelVista(Color.blue, 1, 1); Ventanitas[2] = new PanelVista(Color.blue, 1, 1); Ventanitas[3] = new PanelVista(Color.blue, 1, 1); } JMenu InsertaMenu(String CAD) { return new JMenu(CAD); } void InsertaItem(JMenu MENU, JMenuItem ITEM, String CAD) { ITEM = new JMenuItem(CAD); MENU.add(ITEM); ITEM.addActionListener(new Evento_Opciones()); } public static void main(String R[]) { new MultiPanel(); } protected void processWindowEvent(WindowEvent e) { if (e.getID() == WindowEvent.WINDOW_CLOSING) System.exit(0); } class Evento_Opciones implements ActionListener { public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("Salir")) System.exit(0); if (e.getActionCommand().equals("Uno")) Paneles(1, 0); if (e.getActionCommand().equals("2Horizontal")) Paneles(2, 0); if (e.getActionCommand().equals("2Vertical")) Paneles(2, 1); if (e.getActionCommand().equals("3Horizontal")) Paneles(3, 0); if (e.getActionCommand().equals("3Vertical")) Paneles(3, 1); if (e.getActionCommand().equals("3_VHH")) Paneles(3, 2); if (e.getActionCommand().equals("3_HHV")) Paneles(3, 3); if (e.getActionCommand().equals("3_VVH")) Paneles(3, 4); if (e.getActionCommand().equals("3_HVV")) Paneles(3, 5); if (e.getActionCommand().equals("4")) Paneles(4, 0); } } void Paneles(int N, int Posicion) // (NVentanas, <0=hrz, 1=vert>) { int k=0; for (k=0; k<VPrev; k++) Ventanitas[k].setVisible(false); VPrev = N; //for (k=0; k<VPrev; k++) remove(Ventanitas[k]); VPrev = N; switch (N) { case 1: Ventanitas[0] = new PanelVista(Color.blue, Ancho(1), Alto(1)); CreaVentana(0, 5, 5, Ancho(1), Alto(1)); break; case 2: if (Posicion == 0) // Horizontales { Ventanitas[0] = new PanelVista(Color.blue, Ancho(1), Alto(2)); CreaVentana(0, 5, 5, Ancho(1), Alto(2)); Ventanitas[1] = new PanelVista(Color.red, Ancho(1), Alto(2)); CreaVentana(1, 5, Alto(2)+10, Ancho(1), Alto(2)); } if (Posicion == 1) // Verticales { Ventanitas[0] = new PanelVista(Color.blue, Ancho(2), Alto(1)); CreaVentana(0, 5, 5, Ancho(2), Alto(1)); Ventanitas[1] = new PanelVista(Color.red, Ancho(2), Alto(1)); CreaVentana(1, Ancho(2)+10, 5, Ancho(2), Alto(1)); } break; case 3: if (Posicion == 0) // Horizontales { Ventanitas[0] = new PanelVista(Color.blue, Ancho(1), Alto(3)); CreaVentana(0, 5, 5, Ancho(1), Alto(3)); Ventanitas[1] = new PanelVista(Color.red, Ancho(1), Alto(3)); CreaVentana(1, 5, Alto(3)+8, Ancho(1), Alto(3)); Ventanitas[2] = new PanelVista(Color.green, Ancho(1), Alto(3)); CreaVentana(2, 5, Alto(3)*2+12, Ancho(1), Alto(3)); } if (Posicion == 1) // Verticales { Ventanitas[0] = new PanelVista(Color.blue, Ancho(3), Alto(1)); CreaVentana(0, 5, 5, Ancho(3), Alto(1)); Ventanitas[1] = new PanelVista(Color.red, Ancho(3), Alto(1)); CreaVentana(1, Ancho(3)+8, 5, Ancho(3), Alto(1)); Ventanitas[2] = new PanelVista(Color.green, Ancho(3), Alto(1)); CreaVentana(2, Ancho(3)*2+12, 5, Ancho(3), Alto(1)); } if (Posicion == 2) // V HH { Ventanitas[0] = new PanelVista(Color.blue, Ancho(2), Alto(1)); CreaVentana(0, 5, 5, Ancho(2), Alto(1)); Ventanitas[1] = new PanelVista(Color.red, Ancho(2), Alto(2)); CreaVentana(1, Ancho(2)+10, 5, Ancho(2), Alto(2)); Ventanitas[2] = new PanelVista(Color.green, Ancho(2), Alto(2)); CreaVentana(2, Ancho(2)+10, Alto(2)+10, Ancho(2), Alto(2)); } if (Posicion == 3) // HH V { Ventanitas[0] = new PanelVista(Color.red, Ancho(2), Alto(2)); CreaVentana(0, 5, 5, Ancho(2), Alto(2)); Ventanitas[1] = new PanelVista(Color.green, Ancho(2), Alto(2)); CreaVentana(1, 5, Alto(2)+10, Ancho(2), Alto(2)); Ventanitas[2] = new PanelVista(Color.blue, Ancho(2), Alto(1)); CreaVentana(2, Ancho(2)+10, 5, Ancho(2), Alto(1)); } if (Posicion == 4) // V V H { Ventanitas[0] = new PanelVista(Color.red, Ancho(2), Alto(2)); CreaVentana(0, 5, 5, Ancho(2), Alto(2)); Ventanitas[1] = new PanelVista(Color.green, Ancho(2), Alto(2)); CreaVentana(1, Ancho(2)+10, 5, Ancho(2), Alto(2)); Ventanitas[2] = new PanelVista(Color.blue, Ancho(1), Alto(2)); CreaVentana(2, 5, Alto(2)+10, Ancho(1), Alto(2)); } if (Posicion == 5) // H V V { Ventanitas[0] = new PanelVista(Color.blue, Ancho(1), Alto(2)); CreaVentana(0, 5, 5, Ancho(1), Alto(2)); Ventanitas[1] = new PanelVista(Color.red, Ancho(2), Alto(2)); CreaVentana(1, 5, Alto(2)+10, Ancho(2), Alto(2)); Ventanitas[2] = new PanelVista(Color.green, Ancho(2), Alto(2)); CreaVentana(2, Ancho(2)+10, Alto(2)+10, Ancho(2), Alto(2)); } break; case 4: Ventanitas[0] = new PanelVista(Color.blue, Ancho(2), Alto(2)); CreaVentana(0, 5, 5, Ancho(2), Alto(2)); Ventanitas[1] = new PanelVista(Color.green, Ancho(2), Alto(2)); CreaVentana(1, Ancho(2)+10, 5, Ancho(2), Alto(2)); Ventanitas[2] = new PanelVista(Color.red, Ancho(2), Alto(2)); CreaVentana(2, 5, Alto(2)+10, Ancho(2), Alto(2)); Ventanitas[3] = new PanelVista(Color.cyan, Ancho(2), Alto(2)); CreaVentana(3, Ancho(2)+10, Alto(2)+10, Ancho(2), Alto(2)); } } void CreaVentana(int N, int x, int y, int Ancho, int Alto) { add(Ventanitas[N]); Ventanitas[N].setBounds(x, y, Ancho, Alto); } int Ancho(int N) { int Ancho = DIM.width; Alto = DIM.height; int Resp = 0; switch (N) { case 1: Resp = Ancho - 10; break; case 2: Resp = (Ancho-15)/2; break; case 3: Resp = (Ancho-18)/3; break; } return Resp; } int Alto(int N) { int Resp = 0; switch (N) { case 1: Resp = Alto - 60; break; case 2: Resp = (Alto - 65)/2; break; case 3: Resp = (Alto - 68)/3; break; } return Resp; } } class PanelVista extends JPanel { int Ancho=0, Alto=0; Color ColorFijo=null; public PanelVista(Color ColorFijo, int Ancho, int Alto) { this.ColorFijo = ColorFijo; this.Ancho=Ancho; this.Alto=Alto; setBackground(ColorFijo); } }