Advertisement
jovanovski

ИА Лаб1

Oct 17th, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.97 KB | None | 0 0
  1. package com.gorjan.ialab1;
  2.  
  3. import java.awt.Component;
  4. import java.awt.Container;
  5. import java.awt.GridBagConstraints;
  6. import java.awt.GridBagLayout;
  7. import java.awt.Insets;
  8. import java.awt.LayoutManager;
  9. import javax.swing.*;
  10.  
  11. public class prozorec {
  12.  
  13.     /**
  14.      * @param args
  15.      */
  16.     private static final Insets insets= new Insets(0,0,5,0);
  17.    
  18.     public static void main(String[] args) {
  19.         JFrame ramka= new JFrame("Application Form");
  20.         ramka.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  21.         ramka.setSize(400, 650);
  22.        
  23.         LayoutManager layout = new GridBagLayout();
  24.  
  25.  
  26.         JPanel main = new JPanel();
  27.         main.setLayout(layout);
  28.        
  29.         JPanel panel1 = new JPanel();
  30.         panel1.setBorder(BorderFactory.createTitledBorder("Personal Info"));
  31.         panel1.setLayout(layout);
  32.         addComponent(panel1, new JLabel("Name:"), 0,0,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
  33.         addComponent(panel1, new JLabel("Last Name:"), 0,1,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
  34.         addComponent(panel1, new JLabel("Gender:"), 0,2,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
  35.         addComponent(panel1, new JTextField("Peter"), 1,0,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
  36.         addComponent(panel1, new JTextField("Jackson"), 1,1,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
  37.        
  38.  
  39.         JRadioButton btnOption1 = new JRadioButton("Male");
  40.         JRadioButton btnOption2 = new JRadioButton("Female");
  41.         ButtonGroup group1 = new ButtonGroup();
  42.         group1.add(btnOption1);
  43.         group1.add(btnOption2);
  44.        
  45.         JPanel panel2 = new JPanel();
  46.         panel2.setLayout(layout);
  47.        
  48.         addComponent(panel1, panel2, 1,2,1,1,GridBagConstraints.CENTER, GridBagConstraints.BOTH);
  49.         addComponent(panel2, btnOption2, 1,0,1,1,GridBagConstraints.CENTER, GridBagConstraints.BOTH);
  50.         addComponent(panel2, btnOption1, 0,0,1,1,GridBagConstraints.CENTER, GridBagConstraints.BOTH);
  51.  
  52.  
  53.         JPanel panel3 = new JPanel();
  54.         panel3.setBorder(BorderFactory.createTitledBorder("Education Interests"));
  55.         panel3.setLayout(layout);
  56.         panel3.setSize(500, 100);
  57.         addComponent(panel3, new JLabel("Education"), 0,0,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
  58.        
  59.         JSlider slider = new JSlider();
  60.         slider.setMinimum(1);
  61.         slider.setMaximum(3);
  62.         slider.setMajorTickSpacing(1);
  63.         slider.setPaintTicks(true);
  64.         slider.setPaintLabels(true);
  65.         addComponent(panel3, slider, 0,1,2,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
  66.         addComponent(panel3, new JLabel("Areas"), 0,2,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
  67.         addComponent(panel3, new JLabel("Comment"), 1,2,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
  68.         addComponent(panel3, new JTextField(), 1,3,1,5,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
  69.         addComponent(panel3, new JCheckBox("Computer Scrience"), 0,3,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
  70.         addComponent(panel3, new JCheckBox("History"), 0,4,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
  71.         addComponent(panel3, new JCheckBox("Arts"), 0,5,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
  72.         addComponent(panel3, new JCheckBox("Natural Sciences"), 0,6,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
  73.         addComponent(panel3, new JCheckBox("Sociology"), 0,7,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
  74.        
  75.         addComponent(main, panel1, 0,0,1,1,GridBagConstraints.CENTER, GridBagConstraints.BOTH);
  76.         addComponent(main, panel3, 0,1,1,1,GridBagConstraints.CENTER, GridBagConstraints.BOTH);
  77.  
  78.         addComponent(main, new JButton("Submit"), 0,2,1,1,GridBagConstraints.WEST, GridBagConstraints.BOTH);
  79.        
  80.         ramka.add(main);
  81.         ramka.setVisible(true);
  82.     }
  83.    
  84.     private static void addComponent(Container container, Component component, int gridx, int gridy, int gridwidth, int gridheight, int anchor, int fill) {
  85.         GridBagConstraints gbc= new GridBagConstraints(gridx, gridy, gridwidth, gridheight, 1.0, 1.0, anchor, fill, insets, 0, 0);
  86.         container.add(component, gbc);
  87.     }
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement