Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import java.awt.FlowLayout;
- import java.awt.event.MouseEvent;
- public class MainClass{
- public static void main(String[] a){
- JFrame f = new JFrame("Projekt JPWP 2010");
- f.setLayout(new FlowLayout());
- f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- Przycisk przycisk1 = new Przycisk("images/blue.gif", "Niebieska odkryta", "Niebieska zakryta");
- Przycisk przycisk2 = new Przycisk("images/red.gif", "Czerwona odkryta", "Czerwona zakryta");
- f.setSize(350,200);
- f.setVisible(true);
- f.add(przycisk1);
- f.add(przycisk2);
- }
- }
- -------------------------
- import java.awt.FlowLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.MouseEvent;
- import javax.swing.Icon;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.JTextField;
- import javax.swing.SwingUtilities;
- import javax.swing.event.MouseInputListener;
- class Przycisk extends JPanel implements MouseInputListener{
- String tekst1;
- String tekst2;
- int zmienna = 0;
- boolean sprawdz_odkrycie = false;
- boolean sprawdz_miejsce = false;
- public Przycisk(String on, String odkryta, String zakryta){
- Icon enabled = new ImageIcon(on);
- Icon disabled = new ImageIcon("images/black.gif");
- /*
- jakas madra funkcja na odwracanie kart?
- ta niby dziala, ale jak zrobic repaint buttonow tak zeby dzialalo?
- Icon ikona = disabled;
- if (zmienna==2) {
- ikona = enabled;
- }
- */
- JButton przycisk = new JButton(enabled);
- przycisk.addMouseListener(this);
- tekst1 = odkryta;
- tekst2 = zakryta;
- add(przycisk);
- }
- public void mouseClicked(MouseEvent e) {
- if (sprawdz_miejsce == true)
- if (sprawdz_odkrycie==true) {
- System.out.println(tekst2);
- sprawdz_odkrycie = false;
- } else {
- System.out.println(tekst1);
- sprawdz_odkrycie = true;
- }
- }
- public void mouseEntered(MouseEvent e) {
- sprawdz_miejsce=true;
- }
- public void mouseExited(MouseEvent e) {
- sprawdz_miejsce=false;
- }
- /* nie uzywany syf aczkolwiek potrzebny */
- public void mousePressed(MouseEvent e) {}
- public void mouseReleased(MouseEvent e) {}
- public void mouseDragged(MouseEvent arg0) {}
- public void mouseMoved(MouseEvent arg0) {}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement