Advertisement
Guest User

Untitled

a guest
Jan 25th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. import java.awt.event.ActionEvent;
  2. import java.awt.event.ActionListener;
  3. import java.awt.Color;
  4. import java.awt.Dimension;
  5. import java.awt.FlowLayout;
  6. import javax.swing.JButton;
  7. import javax.swing.JPanel;
  8.  
  9.  
  10. public class PanelZPrzyciskami extends JPanel implements ActionListener {
  11.  
  12. /**
  13. *
  14. */
  15.  
  16. public static final int HEIGHT = 200;
  17. public static final int WIDTH = 350;
  18. private JButton Button1;
  19. private JButton Button2;
  20. private JButton Button3;
  21. private JButton Button4;
  22.  
  23. public PanelZPrzyciskami (){
  24. Button1 = new JButton ("Zielony");
  25. Button2 = new JButton ("Niebieski");
  26. Button3 = new JButton ("Żółty");
  27. Button4 = new JButton ("Zmienny");
  28.  
  29. Button1.addActionListener(this);
  30. Button2.addActionListener(this);
  31. Button3.addActionListener(this);
  32. Button4.addActionListener(this);
  33.  
  34.  
  35.  
  36. setLayout (new FlowLayout());
  37. setPreferredSize (new Dimension (WIDTH, HEIGHT));
  38. add (Button1);
  39. add (Button2);
  40. add (Button3);
  41. add (Button4);
  42. }
  43.  
  44.  
  45.  
  46. @Override
  47. public void actionPerformed(ActionEvent e) {
  48. Object source = e.getSource();
  49. if (source == Button4)
  50. if(Button4.getText() == "Rozmiar") do
  51. { Button4.setText("Kolor");
  52. if (source==Button1)
  53. Button1.setSize(100, 100);
  54. else if (source==Button2)
  55. Button2.setSize(100, 100);
  56. else if (source == Button3)
  57. Button3.setSize(100, 100);}
  58.  
  59. //public void actionPerformed1(ActionEvent f) {
  60. //Object source = f.getSource();
  61.  
  62. if (source == Button4)
  63. if(Button4.getText() == "Kolor")
  64. Button4.setText("Rozmiar");
  65. if (source==Button1)
  66. Button1.setBackground(Color.GREEN);
  67. else if (source==Button2)
  68. Button2.setBackground(Color.BLUE);
  69. else if (source == Button3)
  70. Button3.setBackground(Color.YELLOW);
  71.  
  72. }
  73. }}
  74.  
  75.  
  76. //public static void main(String[] args) {
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83. import javax.swing.JFrame;
  84.  
  85.  
  86. public class okno1 extends JFrame {
  87.  
  88. public okno1(){
  89. super ("Not Hello World");
  90.  
  91. PanelZPrzyciskami panel_z_przyciskami = new PanelZPrzyciskami();
  92. add (panel_z_przyciskami);
  93. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  94. pack();
  95. setVisible(true);
  96. }
  97. /**
  98. * @param args
  99. */
  100. //public static void main(String[] args) {
  101. // TODO Auto-generated method stub
  102.  
  103.  
  104.  
  105. }
  106.  
  107.  
  108.  
  109. public class Test2 {
  110.  
  111.  
  112. public static void main(String[] args) {
  113.  
  114. new okno1();
  115. }
  116.  
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement