Facebook
From Insensitive Cat, 4 Years ago, written in Plain Text.
This paste is a reply to Untitled from Sludgy Bee - view diff
Embed
Download Paste or View Raw
Hits: 255
  1. package ui;
  2.  
  3. import javax.swing.JFrame;
  4.  
  5. public class Test {
  6.  
  7.         public static void main(String[] args) {
  8.  
  9.                 JFrame frame = new MiFrame("Test v1.0");
  10.                 frame.getContentPane().add(new MiPanel("Esto es un test:"));
  11.                 frame.setVisible(true);
  12.         }
  13.  
  14. }
  15.  
  16. -------------------------------------------------
  17.  
  18. package ui;
  19.  
  20. import javax.swing.JFrame;
  21.  
  22. public class MiFrame extends JFrame {
  23.  
  24.         public MiFrame(String titulo) {
  25.                 super(titulo);
  26.                 initUI();
  27.         }
  28.  
  29.         private void initUI() {
  30.                 setSize(600, 400);
  31.                 setLocationRelativeTo(null);
  32.                 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  33.         }
  34. }
  35.  
  36. --------------------------------------------------
  37.  
  38. package ui;
  39.  
  40. import java.awt.BorderLayout;
  41.  
  42. import javax.swing.Box;
  43. import javax.swing.JButton;
  44. import javax.swing.JLabel;
  45. import javax.swing.JPanel;
  46. import javax.swing.JTextField;
  47.  
  48. public class MiPanel extends JPanel {
  49.  
  50.         public MiPanel(String titulo) {
  51.                 initUI(titulo);
  52.         }
  53.  
  54.         private void initUI(String titulo) {
  55.                 setLayout(new BorderLayout());
  56.                
  57.                 Box datos1 = Box.createHorizontalBox();
  58.                 JLabel tituloLabel = new JLabel(titulo);
  59.                 datos1.add(tituloLabel);
  60.                 datos1.add(Box.createHorizontalStrut(10));
  61.                 datos1.add(new JTextField(30));
  62.                
  63.                 Box datos2 = Box.createHorizontalBox();
  64.                 JLabel tituloLabel2 = new JLabel(titulo);
  65.                 datos2.add(tituloLabel2);
  66.                 datos2.add(Box.createHorizontalStrut(10));
  67.                 datos2.add(new JTextField(30));
  68.                
  69.                 Box botonera = Box.createHorizontalBox();
  70.                 botonera.add(Box.createHorizontalGlue());
  71.                 botonera.add(new JButton("OK"));
  72.                 botonera.add(Box.createHorizontalStrut(10));
  73.                 botonera.add(new JButton("Cancel"));
  74.                
  75.                 Box vertical = Box.createVerticalBox();
  76.                 vertical.add(datos1);
  77.                 vertical.add(Box.createVerticalStrut(20));
  78.                 vertical.add(datos2);
  79.                 vertical.add(Box.createVerticalStrut(50));
  80.                 vertical.add(botonera);
  81.                
  82.                 add(vertical, BorderLayout.CENTER);
  83.                
  84.                 JLabel tituloTitulo = new JLabel("TITULO DE TITULOS:");
  85.                 add(tituloTitulo, BorderLayout.NORTH);
  86.                                
  87.         }
  88.        
  89. }
  90.