Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import javax.swing.*;
- import java.math.*;
- import java.io.*;
- import java.util.*;
- import java.awt.event.*;
- public class wejsciowka
- {
- public static void main(String[]arg)
- {
- Okno o1=new Okno("Okienko",0,0,500,500,Color.YELLOW);
- }
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////
- class Okno extends JFrame
- {
- private Container tlo;
- public Okno(String tytul, int x0, int y0, int szer, int wys,Color k)
- {
- super(tytul);
- setBounds(x0,y0,szer,wys);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- tlo=getContentPane();
- tlo.setBackground(k);
- budujUI();
- setVisible(true);
- }
- private void budujUI()
- {
- tlo.setLayout(new BorderLayout());
- JPanel gorny=new JPanel();
- gorny.setBackground(Color.BLUE);
- gorny.setLayout(new FlowLayout());
- JButton b1=new JButton("czerwony");
- b1.addActionListener(new Kolory(Color.RED)); //nasłuchiwacz zdarzenia.
- gorny.add(b1);
- JButton b2=new JButton("zielony");
- b2.addActionListener(new Kolory(Color.GREEN));
- gorny.add(b2);
- JButton b3=new JButton("niebieski");
- b3.addActionListener(new Kolory(Color.BLUE));
- gorny.add(b3);
- JButton b4=new JButton("Zamykamy");
- //b4.addActionListener(new Zamykamy());
- b4.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- dispose();
- }
- });
- gorny.add(b4);
- tlo.add(BorderLayout.NORTH,gorny);
- }
- /////////////////////////////////////////////////////////////////////////////////////////////////
- class Kolory implements ActionListener
- {
- private Color k;
- public Kolory (Color ak)
- {
- k = ak;
- }
- @Override
- public void actionPerformed(ActionEvent e)
- {
- tlo.setBackground(k);
- }
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- /*
- class Zielony implements ActionListener
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- tlo.setBackground(Color.GREEN);
- }
- }
- class Niebieski implements ActionListener
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- tlo.setBackground(Color.BLUE);
- }
- }
- class Zamykamy implements ActionListener
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- dispose();
- }
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement