Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.41 KB | None | 0 0
  1. import javax.swing.JFrame;
  2. import javax.swing.JPanel;
  3.  
  4. import java.awt.FlowLayout;
  5. import java.awt.event.MouseEvent;
  6. public class MainClass{
  7.  
  8.   public static void main(String[] a){
  9.     JFrame f = new JFrame("Projekt JPWP 2010");
  10.     f.setLayout(new FlowLayout());
  11.     f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  12.     Przycisk przycisk1 = new Przycisk("images/blue.gif", "Niebieska odkryta", "Niebieska zakryta");
  13.     Przycisk przycisk2 = new Przycisk("images/red.gif", "Czerwona odkryta", "Czerwona zakryta");
  14.     f.setSize(350,200);
  15.     f.setVisible(true);
  16.     f.add(przycisk1);
  17.     f.add(przycisk2);
  18.     }
  19.  }
  20.  
  21. -------------------------
  22.  
  23.  
  24. import java.awt.FlowLayout;
  25. import java.awt.event.ActionEvent;
  26. import java.awt.event.ActionListener;
  27. import java.awt.event.MouseEvent;
  28.  
  29. import javax.swing.Icon;
  30. import javax.swing.ImageIcon;
  31. import javax.swing.JButton;
  32. import javax.swing.JFrame;
  33. import javax.swing.JPanel;
  34. import javax.swing.JTextField;
  35. import javax.swing.SwingUtilities;
  36. import javax.swing.event.MouseInputListener;
  37.  
  38.  
  39. class Przycisk extends JPanel implements MouseInputListener{
  40.  String tekst1;
  41.  String tekst2;
  42.  int zmienna = 0;
  43.  boolean sprawdz_odkrycie = false;
  44.  boolean sprawdz_miejsce = false;
  45.  public Przycisk(String on, String odkryta, String zakryta){
  46.    
  47.     Icon enabled = new ImageIcon(on);
  48.     Icon disabled = new ImageIcon("images/black.gif");
  49.      /*
  50.      jakas madra funkcja na odwracanie kart?
  51.     ta niby dziala, ale jak zrobic repaint buttonow tak zeby dzialalo?
  52.    
  53.     Icon ikona = disabled;
  54.     if (zmienna==2) {
  55.         ikona = enabled;
  56.     }
  57.     */
  58.     JButton przycisk = new JButton(enabled);
  59.     przycisk.addMouseListener(this);
  60.    
  61.     tekst1 = odkryta;
  62.     tekst2 = zakryta;
  63.    
  64.     add(przycisk);
  65.  
  66.   }
  67.  
  68.   public void mouseClicked(MouseEvent e) {
  69.       if (sprawdz_miejsce == true)
  70.             if (sprawdz_odkrycie==true) {
  71.                 System.out.println(tekst2);
  72.                 sprawdz_odkrycie = false;
  73.             } else {
  74.                 System.out.println(tekst1);
  75.                 sprawdz_odkrycie = true;   
  76.             }
  77.   }
  78.   public void mouseEntered(MouseEvent e) {
  79.       sprawdz_miejsce=true;
  80.   }
  81.   public void mouseExited(MouseEvent e) {
  82.       sprawdz_miejsce=false;
  83.   }
  84.  
  85.   /* nie uzywany syf aczkolwiek potrzebny */
  86.   public void mousePressed(MouseEvent e) {}
  87.   public void mouseReleased(MouseEvent e) {}
  88.   public void mouseDragged(MouseEvent arg0) {}
  89.   public void mouseMoved(MouseEvent arg0) {}
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement