Advertisement
kyle1320

Untitled

Oct 16th, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1. import javax.swing.JFrame;
  2. import javax.swing.JPanel;
  3. import javax.swing.SwingUtilities;
  4. import java.awt.Color;
  5. import java.awt.Graphics;
  6. import java.awt.Dimension;
  7. import java.awt.Graphics;
  8.  
  9. import javax.swing.JFrame;
  10. import javax.swing.JPanel;
  11. import javax.swing.SwingUtilities;
  12.  
  13. public class Test {
  14.  
  15.     private static final int FIRST_SIZE = 300;
  16.     private static final int SECOND_SIZE = 150;
  17.    
  18.     public static void main(String[] args) throws Exception {
  19.        
  20.         final JFrame f = new JFrame();
  21.        
  22.         final JPanel p = new JPanel() {
  23.             public void paintComponent(Graphics g) {
  24.                 super.paintComponent(g);
  25.                 g.fillRect(0, 0, SECOND_SIZE, SECOND_SIZE);
  26.             }
  27.         };
  28.            
  29.         p.setPreferredSize(new Dimension(FIRST_SIZE, FIRST_SIZE));
  30.         f.add(p);
  31.            
  32.         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  33.         f.pack();
  34.         f.setLocationRelativeTo(null);
  35.         f.setVisible(true);
  36.        
  37.         Thread.sleep(2000);
  38.        
  39.         SwingUtilities.invokeLater(new Runnable() {
  40.             public void run() {
  41.                 f.pack();
  42.                 f.setSize(0, 0);
  43.                 p.setPreferredSize(new Dimension(SECOND_SIZE, SECOND_SIZE));
  44.                 f.invalidate();
  45.                 f.validate();
  46.                 f.pack();
  47.             }
  48.         });
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement