Advertisement
Guest User

Untitled

a guest
Nov 26th, 2015
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. import java.awt.*;
  2. import javax.swing.*;
  3. import java.math.*;
  4. import java.io.*;
  5. import java.util.*;
  6. import java.awt.event.*;
  7.  
  8. public class wejsciowka
  9. {
  10. public static void main(String[]arg)
  11. {
  12. Okno o1=new Okno("Okienko",0,0,500,500,Color.YELLOW);
  13. }
  14.  
  15. }
  16. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  17. class Okno extends JFrame
  18. {
  19. private Container tlo;
  20.  
  21. public Okno(String tytul, int x0, int y0, int szer, int wys,Color k)
  22. {
  23. super(tytul);
  24. setBounds(x0,y0,szer,wys);
  25. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  26. tlo=getContentPane();
  27. tlo.setBackground(k);
  28. budujUI();
  29. setVisible(true);
  30. }
  31.  
  32. private void budujUI()
  33. {
  34. tlo.setLayout(new BorderLayout());
  35. JPanel gorny=new JPanel();
  36. gorny.setBackground(Color.BLUE);
  37. gorny.setLayout(new FlowLayout());
  38.  
  39. JButton b1=new JButton("czerwony");
  40. b1.addActionListener(new Kolory(Color.RED)); //nasłuchiwacz zdarzenia.
  41.  
  42. gorny.add(b1);
  43.  
  44.  
  45. JButton b2=new JButton("zielony");
  46. b2.addActionListener(new Kolory(Color.GREEN));
  47. gorny.add(b2);
  48.  
  49.  
  50. JButton b3=new JButton("niebieski");
  51. b3.addActionListener(new Kolory(Color.BLUE));
  52.  
  53. gorny.add(b3);
  54.  
  55. JButton b4=new JButton("Zamykamy");
  56. //b4.addActionListener(new Zamykamy());
  57. b4.addActionListener(new ActionListener()
  58. {
  59. @Override
  60. public void actionPerformed(ActionEvent e)
  61. {
  62. dispose();
  63. }
  64. });
  65. gorny.add(b4);
  66.  
  67. tlo.add(BorderLayout.NORTH,gorny);
  68.  
  69. }
  70. /////////////////////////////////////////////////////////////////////////////////////////////////
  71. class Kolory implements ActionListener
  72. {
  73.  
  74. private Color k;
  75. public Kolory (Color ak)
  76. {
  77. k = ak;
  78. }
  79. @Override
  80. public void actionPerformed(ActionEvent e)
  81. {
  82. tlo.setBackground(k);
  83. }
  84. }
  85. ////////////////////////////////////////////////////////////////////////////////////////////////
  86.  
  87. }
  88. ////////////////////////////////////////////////////////////////////////////////////////////////////
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96. /*
  97. class Zielony implements ActionListener
  98. {
  99. @Override
  100. public void actionPerformed(ActionEvent e)
  101. {
  102. tlo.setBackground(Color.GREEN);
  103. }
  104. }
  105. class Niebieski implements ActionListener
  106. {
  107. @Override
  108. public void actionPerformed(ActionEvent e)
  109. {
  110. tlo.setBackground(Color.BLUE);
  111. }
  112. }
  113. class Zamykamy implements ActionListener
  114. {
  115. @Override
  116. public void actionPerformed(ActionEvent e)
  117. {
  118. dispose();
  119. }
  120. }
  121. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement