Crenox

Swing GUI Java

Mar 13th, 2014
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. package com.samkough.main;
  2.  
  3. /*
  4. LINKS:
  5. http://www.wikihow.com/Create-a-Swing-GUI-in-Java
  6. https://stackoverflow.com/questions/144892/how-to-centre-a-window-in-java
  7. */
  8.  
  9. import java.awt.event.ActionListener;
  10. import java.awt.event.ActionEvent;
  11. import javax.swing.*;
  12.  
  13. @SuppressWarnings("serial")
  14. public class Swing extends JFrame implements ActionListener
  15. {
  16. JPanel mypanel;
  17. JButton mybutton;
  18. JLabel mylabel;
  19.  
  20. public static void main(String args[])
  21. {
  22. Swing first = new Swing();
  23. first.setTitle("First Try");
  24. first.setSize(300,200);
  25. first.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  26. first.setVisible(true);
  27. first.setLocationRelativeTo(null);
  28. }
  29.  
  30. public Swing()
  31. {
  32. mypanel = new JPanel();
  33.  
  34. mybutton = new JButton("OK");
  35. mybutton.addActionListener(this);
  36.  
  37. mylabel = new JLabel();
  38.  
  39. mypanel.add(mybutton);
  40. mypanel.add(mylabel);
  41. this.add(mypanel);
  42. }
  43.  
  44. public void actionPerformed(ActionEvent event)
  45. {
  46. if(event.getSource() == mybutton)
  47. {
  48. mylabel.setText("My button clicked.");
  49. }
  50. }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment