Advertisement
Pihtija

V6 OBP2

Nov 27th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. package grafika;
  2.  
  3. import javax.swing.event.MouseInputAdapter;
  4. import java.awt.*;
  5. import java.awt.event.*;
  6.  
  7. /**
  8. * Created by korisnik on 27.11.2018..
  9. */
  10. public class Prozor extends Frame /*implements ActionListener*/{
  11. public static int brojac,x,y=0;
  12. public Prozor(){
  13. setTitle("Vezba 6");
  14. setSize(400,400);
  15.  
  16. addWindowListener(new WindowAdapter() {
  17. @Override
  18. public void windowClosing(WindowEvent e) {
  19. System.out.println("Dovidjenja");
  20. System.exit(1);
  21. }
  22. });
  23.  
  24. // Button dugme=new Button("Dugme 1");
  25. // setLayout(null);
  26. // dugme.setBounds(50,50,100,40);
  27. // dugme.addActionListener(new ActionListener() {
  28. // @Override
  29. // public void actionPerformed(ActionEvent e) {
  30. // brojac++;
  31. // dugme.setLabel("Kliknuto:"+brojac);
  32. // }
  33. // });
  34. // DogadjaDugmeta dd=new DogadjaDugmeta();
  35. // dugme.addActionListener(dd);
  36. // dugme.addActionListener(this);
  37.  
  38. addMouseMotionListener(new MouseMotionAdapter() {
  39. @Override
  40. public void mouseMoved(MouseEvent e) {
  41.  
  42. x=e.getX();
  43. y=e.getY();
  44.  
  45. repaint();
  46. setBackground(Color.getHSBColor(x,y,x+y));
  47. }
  48.  
  49.  
  50. });
  51.  
  52. addMouseListener(new MouseInputAdapter() {
  53. @Override
  54. public void mouseClicked(MouseEvent e) {
  55. Button dugme = new Button("Dugme");
  56. setLayout(null);
  57. dugme.setBounds(x,y,40,40);
  58. brojac++;
  59. int a= x%255; //srediti boje da ne izlaze iz ogranichenja
  60. int b= y%255;
  61. dugme.setLabel(String.valueOf(brojac));
  62. dugme.setBackground(new Color(a , b, a + b));
  63. add(dugme);
  64.  
  65. dugme.addActionListener(new ActionListener() {
  66. @Override
  67. public void actionPerformed(ActionEvent e) {
  68. dugme.setBackground(Color.gray);
  69. }
  70. });
  71. }
  72. });
  73.  
  74.  
  75.  
  76. // add(dugme);
  77. //
  78. setVisible(true);
  79. }
  80.  
  81.  
  82. public void paint(Graphics g){
  83.  
  84. Font f= new Font("Times Mew Roman", Font.ITALIC, 25);
  85. g.setFont(f);
  86.  
  87. g.drawString("Koordinate x:"+x+",y"+y, 100, 200);
  88.  
  89. }
  90. }
  91.  
  92. // @Override
  93. // public void actionPerformed(ActionEvent e) {
  94. // System.out.println("Klik");
  95. // }
  96. //}
  97.  
  98. ---------------------------------
  99.  
  100. package grafika;
  101.  
  102. import java.awt.*;
  103. import java.awt.event.ActionEvent;
  104. import java.awt.event.ActionListener;
  105.  
  106. /**
  107. * Created by korisnik on 27.11.2018..
  108. */
  109. public class DogadjaDugmeta implements ActionListener{
  110. @Override
  111. public void actionPerformed(ActionEvent e) {
  112. Button b= (Button)e.getSource();
  113. b.setLabel("Klik");
  114. }
  115. }
  116.  
  117.  
  118. -----------------------------
  119.  
  120. package Program;
  121.  
  122. import grafika.Prozor;
  123.  
  124. /**
  125. * Created by korisnik on 27.11.2018..
  126. */
  127. public class Program {
  128. public static void main(String[] args) {
  129. Prozor p=new Prozor();
  130.  
  131.  
  132. }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement