Crenox

Sam GUI #2

Apr 15th, 2014
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. package com.samkough.main;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import javax.swing.*;
  6.  
  7. @SuppressWarnings("serial")
  8. public class Sam extends JFrame
  9. {
  10. private static final int WIDTH = 500;
  11. private static final int HEIGHT = 500;
  12.  
  13. JButton b1;
  14. JLabel l1;
  15. JTextField tf1;
  16. JRadioButton rb1;
  17. JCheckBox cb1;
  18. JMenuItem mi1;
  19.  
  20. public static void main(String args[])
  21. {
  22. Sam frame = new Sam();
  23.  
  24. frame.setVisible(true);
  25. frame.setTitle("GUI");
  26. frame.setSize(WIDTH, HEIGHT);
  27. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  28. frame.setLocationRelativeTo(null);
  29. }
  30.  
  31. public Sam()
  32. {
  33. setLayout(new FlowLayout());
  34.  
  35. b1 = new JButton("Press me!");
  36. l1 = new JLabel("");
  37. tf1 = new JTextField("", 7);
  38. rb1 = new JRadioButton("");
  39. cb1 = new JCheckBox("");
  40. mi1 = new JMenuItem("");
  41.  
  42. add(b1);
  43. add(l1);
  44. add(tf1);
  45. add(rb1);
  46. add(cb1);
  47. add(mi1);
  48.  
  49. Action e = new Action();
  50. b1.addActionListener(e);
  51. }
  52.  
  53. public class Action implements ActionListener
  54. {
  55. public void actionPerformed(ActionEvent e)
  56. {
  57. b1.setText("Button");
  58. l1.setText("Label");
  59. tf1.setText("Text Field");
  60. rb1.setText("Radio Button");
  61. cb1.setText("Check Box");
  62. mi1.setText("Menu Item");
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment