Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package grafika;
- import javax.swing.event.MouseInputAdapter;
- import java.awt.*;
- import java.awt.event.*;
- /**
- * Created by korisnik on 27.11.2018..
- */
- public class Prozor extends Frame /*implements ActionListener*/{
- public static int brojac,x,y=0;
- public Prozor(){
- setTitle("Vezba 6");
- setSize(400,400);
- addWindowListener(new WindowAdapter() {
- @Override
- public void windowClosing(WindowEvent e) {
- System.out.println("Dovidjenja");
- System.exit(1);
- }
- });
- // Button dugme=new Button("Dugme 1");
- // setLayout(null);
- // dugme.setBounds(50,50,100,40);
- // dugme.addActionListener(new ActionListener() {
- // @Override
- // public void actionPerformed(ActionEvent e) {
- // brojac++;
- // dugme.setLabel("Kliknuto:"+brojac);
- // }
- // });
- // DogadjaDugmeta dd=new DogadjaDugmeta();
- // dugme.addActionListener(dd);
- // dugme.addActionListener(this);
- addMouseMotionListener(new MouseMotionAdapter() {
- @Override
- public void mouseMoved(MouseEvent e) {
- x=e.getX();
- y=e.getY();
- repaint();
- setBackground(Color.getHSBColor(x,y,x+y));
- }
- });
- addMouseListener(new MouseInputAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- Button dugme = new Button("Dugme");
- setLayout(null);
- dugme.setBounds(x,y,40,40);
- brojac++;
- int a= x%255; //srediti boje da ne izlaze iz ogranichenja
- int b= y%255;
- dugme.setLabel(String.valueOf(brojac));
- dugme.setBackground(new Color(a , b, a + b));
- add(dugme);
- dugme.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- dugme.setBackground(Color.gray);
- }
- });
- }
- });
- // add(dugme);
- //
- setVisible(true);
- }
- public void paint(Graphics g){
- Font f= new Font("Times Mew Roman", Font.ITALIC, 25);
- g.setFont(f);
- g.drawString("Koordinate x:"+x+",y"+y, 100, 200);
- }
- }
- // @Override
- // public void actionPerformed(ActionEvent e) {
- // System.out.println("Klik");
- // }
- //}
- ---------------------------------
- package grafika;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- /**
- * Created by korisnik on 27.11.2018..
- */
- public class DogadjaDugmeta implements ActionListener{
- @Override
- public void actionPerformed(ActionEvent e) {
- Button b= (Button)e.getSource();
- b.setLabel("Klik");
- }
- }
- -----------------------------
- package Program;
- import grafika.Prozor;
- /**
- * Created by korisnik on 27.11.2018..
- */
- public class Program {
- public static void main(String[] args) {
- Prozor p=new Prozor();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement