Guest User

Untitled

a guest
May 4th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.64 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import java.util.*;
  5. import java.awt.Dimension;
  6. import java.io.*;
  7.  
  8. public class odtwarzacz {
  9.  
  10.     public static void main (String[] args) {
  11.         JFrame oknoGlowne = new JFrame("Okno glowne programu");
  12.         oknoGlowne.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  13.         oknoGlowne.setPreferredSize(new Dimension(600, 400));
  14.         oknoGlowne.setResizable(false);
  15.         oknoGlowne.setVisible(true);
  16.         oknoGlowne.pack();
  17.         /*GridBagConstraints layout = new GridBagConstraints();
  18.         layout.insets = new Insets(0,0,0,0);
  19.         layout.gridx = 0;
  20.         layout.gridy = 0;*/
  21.         GridBagConstraints c = new GridBagConstraints();
  22.         oknoGlowne.setLayout(new GridLayout(2, 1));
  23.        
  24.         JPanel gorny = new JPanel(new GridBagLayout());
  25.         gorny.setBackground(Color.green);
  26.         gorny.setPreferredSize(new Dimension(600, 150));
  27.         oknoGlowne.add(gorny);
  28.            
  29.        
  30.         JPanel panel = new JPanel(new GridBagLayout());
  31.         //panel.setPreferredSize(new Dimension(600, 100));
  32.         JButton b1 = new JButton("Przycisk PLAY");
  33.         JButton b2 = new JButton("Przycisk PAUZA");
  34.         JButton b3 = new JButton("Przycisk STOP");
  35.         GridBagConstraints layout = new GridBagConstraints();
  36.         layout.insets = new Insets(0, 10, 5, 0);
  37.         layout.anchor = GridBagConstraints.SOUTH;
  38.         layout.weighty = 1;
  39.         //b1.setBorder(javax.swing.BorderFactory.createLineBorder(Color.BLUE, 1));
  40.         panel.add(b1, layout);
  41.         panel.add(b2, layout);
  42.         panel.add(b3, layout);
  43.         oknoGlowne.add(panel);
  44.         panel.setBackground(Color.blue);
  45.         b1.setBackground(Color.green);
  46.         //b1.setPreferredSize(new Dimension(140, 30));
  47.         b2.setBackground(Color.yellow);
  48.         b2.setVisible(false);
  49.         b3.setBackground(Color.red);
  50.         //b1.setVisible(false);
  51.        
  52.        
  53.         b1.addActionListener(new ActionListener() {
  54.  
  55.             public void actionPerformed(ActionEvent e)
  56.             {
  57.                 //Execute when button is pressed
  58.                 b1.setVisible(false);
  59.                 b2.setVisible(true);
  60.                 System.out.println("Nacisnales play");
  61.             }
  62.         });
  63.        
  64.         b2.addActionListener(new ActionListener() {
  65.  
  66.             public void actionPerformed(ActionEvent e)
  67.             {
  68.                 //Execute when button is pressed
  69.                 b1.setVisible(true);
  70.                 b2.setVisible(false);
  71.                 System.out.println("nacisnales pauza");
  72.             }
  73.         });
  74.        
  75.         b3.addActionListener(new ActionListener() {
  76.  
  77.             public void actionPerformed(ActionEvent e)
  78.             {
  79.                 //Execute when button is pressed
  80.                 b1.setVisible(true);
  81.                 b2.setVisible(false);
  82.                 System.out.println("nacisnales stop");
  83.             }
  84.         });
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment