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