Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.gorjan.ialab1;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.GridBagConstraints;
- import java.awt.GridBagLayout;
- import java.awt.Insets;
- import java.awt.LayoutManager;
- import javax.swing.*;
- public class prozorec {
- /**
- * @param args
- */
- private static final Insets insets= new Insets(0,0,5,0);
- public static void main(String[] args) {
- JFrame ramka= new JFrame("Application Form");
- ramka.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- ramka.setSize(400, 650);
- LayoutManager layout = new GridBagLayout();
- JPanel main = new JPanel();
- main.setLayout(layout);
- JPanel panel1 = new JPanel();
- panel1.setBorder(BorderFactory.createTitledBorder("Personal Info"));
- panel1.setLayout(layout);
- addComponent(panel1, new JLabel("Name:"), 0,0,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
- addComponent(panel1, new JLabel("Last Name:"), 0,1,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
- addComponent(panel1, new JLabel("Gender:"), 0,2,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
- addComponent(panel1, new JTextField("Peter"), 1,0,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
- addComponent(panel1, new JTextField("Jackson"), 1,1,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
- JRadioButton btnOption1 = new JRadioButton("Male");
- JRadioButton btnOption2 = new JRadioButton("Female");
- ButtonGroup group1 = new ButtonGroup();
- group1.add(btnOption1);
- group1.add(btnOption2);
- JPanel panel2 = new JPanel();
- panel2.setLayout(layout);
- addComponent(panel1, panel2, 1,2,1,1,GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- addComponent(panel2, btnOption2, 1,0,1,1,GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- addComponent(panel2, btnOption1, 0,0,1,1,GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- JPanel panel3 = new JPanel();
- panel3.setBorder(BorderFactory.createTitledBorder("Education Interests"));
- panel3.setLayout(layout);
- panel3.setSize(500, 100);
- addComponent(panel3, new JLabel("Education"), 0,0,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
- JSlider slider = new JSlider();
- slider.setMinimum(1);
- slider.setMaximum(3);
- slider.setMajorTickSpacing(1);
- slider.setPaintTicks(true);
- slider.setPaintLabels(true);
- addComponent(panel3, slider, 0,1,2,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
- addComponent(panel3, new JLabel("Areas"), 0,2,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
- addComponent(panel3, new JLabel("Comment"), 1,2,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
- addComponent(panel3, new JTextField(), 1,3,1,5,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
- addComponent(panel3, new JCheckBox("Computer Scrience"), 0,3,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
- addComponent(panel3, new JCheckBox("History"), 0,4,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
- addComponent(panel3, new JCheckBox("Arts"), 0,5,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
- addComponent(panel3, new JCheckBox("Natural Sciences"), 0,6,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
- addComponent(panel3, new JCheckBox("Sociology"), 0,7,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
- addComponent(main, panel1, 0,0,1,1,GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- addComponent(main, panel3, 0,1,1,1,GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- addComponent(main, new JButton("Submit"), 0,2,1,1,GridBagConstraints.WEST, GridBagConstraints.BOTH);
- ramka.add(main);
- ramka.setVisible(true);
- }
- private static void addComponent(Container container, Component component, int gridx, int gridy, int gridwidth, int gridheight, int anchor, int fill) {
- GridBagConstraints gbc= new GridBagConstraints(gridx, gridy, gridwidth, gridheight, 1.0, 1.0, anchor, fill, insets, 0, 0);
- container.add(component, gbc);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement