Advertisement
Guest User

Untitled

a guest
May 23rd, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. package javaapplication17;
  2.  
  3. import java.awt.Dimension;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6.  
  7. import javax.swing.JButton;
  8. import javax.swing.JFrame;
  9. import static javax.swing.JFrame.EXIT_ON_CLOSE;
  10. import javax.swing.JPanel;
  11. import javax.swing.SwingUtilities;
  12. import javax.swing.Timer;
  13.  
  14. public class JavaApplication17 extends JFrame{
  15.  
  16. final JButton submitButton = new JButton("TEST");
  17. Timer timer;
  18.  
  19. public JavaApplication17() {
  20.  
  21. initUI();
  22. }
  23.  
  24. private void initUI() {
  25. JPanel panel = new JPanel();
  26. getContentPane().add(panel);
  27.  
  28.  
  29. panel.setLayout(null);
  30.  
  31.  
  32. submitButton.setSize(80, 80);
  33. submitButton.setLocation(20, 20);
  34.  
  35. panel.add(submitButton);
  36.  
  37. setSize(200, 200);
  38. setLocationRelativeTo(null);
  39. setDefaultCloseOperation(EXIT_ON_CLOSE);
  40. test();
  41. timer.start();
  42. }
  43.  
  44. public void test(){
  45. timer = new Timer(18, new ActionListener() {
  46. @Override
  47. public void actionPerformed(ActionEvent e) {
  48. Dimension dim = submitButton.getSize();
  49. if (dim.getHeight() < 79.9) {
  50. submitButton.setSize((int) (dim.getWidth() + 6), (int) (dim.getHeight() + 6));
  51. } else {
  52. submitButton.setSize(20, 20);
  53. }
  54. }
  55. });
  56. }
  57.  
  58. public static void main(String[] args) {
  59. SwingUtilities.invokeLater(new Runnable() {
  60. @Override
  61. public void run() {
  62. JavaApplication17 ex = new JavaApplication17();
  63. ex.setVisible(true);
  64. }
  65. });
  66. }
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement