Advertisement
Guest User

Code

a guest
Apr 9th, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.07 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.Dimension;
  3. import java.awt.EventQueue;
  4. import java.awt.Graphics;
  5. import java.awt.Graphics2D;
  6. import java.awt.GraphicsDevice;
  7. import java.awt.GraphicsEnvironment;
  8. import java.awt.Image;
  9. import java.awt.Rectangle;
  10. import java.awt.RenderingHints;
  11. import java.awt.Toolkit;
  12. import java.awt.event.ActionEvent;
  13. import java.awt.event.ActionListener;
  14. import java.awt.event.MouseAdapter;
  15. import java.awt.event.MouseEvent;
  16. import java.awt.geom.AffineTransform;
  17. import java.awt.image.BufferedImage;
  18. import java.io.File;
  19. import java.io.IOException;
  20. import java.net.URL;
  21. import java.sql.Date;
  22. import java.util.Calendar;
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43. import java.util.logging.Level;
  44. import java.util.logging.Logger;
  45.  
  46. import javax.imageio.ImageIO;
  47. import javax.swing.ImageIcon;
  48. import javax.swing.JFrame;
  49. import javax.swing.JLabel;
  50. import javax.swing.JPanel;
  51. import javax.swing.Timer;
  52. import javax.swing.border.EmptyBorder;
  53.  
  54.  
  55.  
  56.  
  57.  
  58. public class main extends JFrame {
  59.    
  60.  
  61.     private JPanel contentPane;
  62.     public JLabel background;
  63.     public JLabel background2;
  64.     private Timer timer;
  65.     private Timer timer2;
  66.     private int counter = 2;
  67.     private int counter2 = 2;
  68.     private BufferedImage img;
  69.    
  70.     /**
  71.      * Launch the application.
  72.      */
  73.     public static void main(String[] args) {
  74.         EventQueue.invokeLater(new Runnable() {
  75.             public void run() {
  76.                 try {
  77.                     main frame = new main();
  78.                     frame.setVisible(true);
  79.                 } catch (Exception e) {
  80.                     e.printStackTrace();
  81.                 }
  82.             }
  83.         });
  84.     }
  85.  
  86.     /**
  87.      * Create the frame.
  88.      * @throws IOException
  89.      */
  90.  
  91.     @SuppressWarnings("deprecation")
  92.     public main() throws IOException {
  93.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  94.        
  95.         contentPane = new JPanel();
  96.         contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  97.         contentPane.setLayout(new BorderLayout(0, 0));
  98.  
  99.         final JLabel background = new JLabel(new ImageIcon("C:/Documents and Settings/All Users/Dokumenty/Moje obrazy/Przykładowe obrazy/Zima.jpg"));
  100.         final JLabel background2 = new JLabel(new ImageIcon("C:/Documents and Settings/All Users/Dokumenty/Moje obrazy/Przykładowe obrazy/fds.jpg"));
  101.        
  102.        
  103.  
  104.         contentPane.addMouseListener(new MouseAdapter() {
  105.             @Override
  106.             public void mousePressed(MouseEvent arg0) {
  107.                 System.exit(0);
  108.             }
  109.         });
  110.        
  111.        
  112.         final ActionListener action2 = new ActionListener()
  113.         {
  114.             public void actionPerformed(ActionEvent event)
  115.             {
  116.                 if(counter2 == 0)
  117.                 {
  118.                     remove(background2);
  119.                     contentPane.repaint();
  120.                 }
  121.                 else
  122.                 {
  123.                     counter2--;
  124.                     System.out.printf("%d", counter2);
  125.                 }
  126.             }
  127.         };
  128.        
  129.  
  130.        
  131.          ActionListener action = new ActionListener()
  132.             {  
  133.                 @Override
  134.                 public void actionPerformed(ActionEvent event)
  135.                 {
  136.                    if(counter == 0)
  137.                    {
  138.                        remove(background);
  139.                        contentPane.repaint();
  140.                        
  141.                        getContentPane().add(background2);
  142.                        revalidate();
  143.                        timer2 = new Timer(1000, action2);
  144.                        timer2.setInitialDelay(0);
  145.                        timer2.start();
  146.                        
  147.                    }
  148.                    else
  149.                    {
  150.                        counter--;
  151.                    }
  152.                 }
  153.             };
  154.            
  155.            
  156.            
  157.            
  158.  
  159.        
  160.         setUndecorated(true);
  161.         setContentPane(contentPane);
  162.         setTitle("Game");
  163.         GraphicsEnvironment graphicsEnvironment=GraphicsEnvironment.getLocalGraphicsEnvironment();
  164.         Rectangle maximumWindowBounds=graphicsEnvironment.getMaximumWindowBounds();
  165.         setBounds(maximumWindowBounds);
  166.         background.setBounds(maximumWindowBounds);
  167.         background.setSize( maximumWindowBounds.width, maximumWindowBounds.height);
  168.         timer = new Timer(1000, action);
  169.         timer.setInitialDelay(0);
  170.         timer.start();
  171.         getContentPane().add(background);
  172.         revalidate();
  173.         repaint();
  174.     }
  175.    
  176.  
  177.    
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement