maygapixel

Untitled

Apr 22nd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 1.  import javax.swing.*;
  2. 2.  import java.awt.*;
  3. 3.  import java.awt.event.*;
  4. 4.  class GuiComponents extends JFrame{
  5. 5.       
  6. 6.        private JLabel label;
  7. 7.        private JComboBox choice;
  8. 8.        private Icon icons[];
  9. 9.        private int count =1;
  10. 10.       private String[] combo  = {"Yes","No"};
  11. 11.      
  12. 12.       public GuiComponents(){
  13. 13.       Container c = getContentPane();      
  14. 14.       c.setLayout(new FlowLayout());
  15. 15.       JButton jb = new JButton("Button");
  16. 16.       c.add(jb);
  17. 17.       JCheckBox jcb1 = new JCheckBox();
  18. 18.       Jlabel jl = new JLabel("Label");
  19. 19.       JCheckBox jcb2 = new JCheckBox();
  20. 20.       JTextField jtf = new JTextField("TextField");
  21. 21.       JTextArea jta = new JTextArea("TextArea",5,20);
  22. 22.       c.add(jcb1);
  23. 23.       c.add(jl);
  24. 24.       c.add(jcb2);
  25. 25.       c.add(jtf);
  26. 26.       c.add(jta);
  27. 27.      
  28. 28.       //ScrollPane
  29. 29.       JScrollPane scroll = new JScrollPane();
  30. 30.       Scroll.setBounds(100,52,130,50);
  31. 31.       // list
  32. 32.       final String[] items = {"item 1","item 2","item 3","item 4","item 5","item 6","item 7","item 8","item 9","item 10",};
  33. 33.       final JList list = new JList(items);
  34. 34.       list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
  35. 35.       Scroll.setViewportView(list);
  36. 36.       getContentPane().add(scroll);
  37. 37.       // JComboBox
  38. 38.       icons = new Icon[combo.length];
  39. 39.       choice = new JComboBox(combo);
  40. 40.       JRadioButton often = new JRadioButton("often", true);
  41. 41.       c.add(often);
  42. 42.       JRadioButton sometimes = new JRadioButton("sometimes ", false);
  43. 43.       c.add(sometimes);
  44. 44.       JRadioButton never = new JRadioButton("never ", false);
  45. 45.       c.add(never);
  46. 46.      
  47. 47.       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  48. 48.       setSize(500,300);
  49. 49.       setTitle("GuiComponents");
  50. 50.       setVisible(true);
  51. 51.     }
  52. 52. }
Advertisement
Add Comment
Please, Sign In to add comment