All pastes #538114 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-06-04 23:16 UTC
rendered paste body
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.event.MouseListener.*;
import java.awt.event.MouseEvent.*;



public class tic  extends JFrame implements MouseListener
{
	// buttions

	private Icon x= new ImageIcon("x.jpg");
	private Icon o= new ImageIcon("o.jpg");
	private JButton x1 = new JButton (x);
	private JButton o1 = new JButton (o);
	private JButton  one = new JButton();
	private JButton two = new JButton();
	private JButton three = new JButton();
	private JButton four = new JButton();
	private JButton five = new JButton();
	private JButton six = new JButton();
	private JButton seven = new JButton();
	private JButton eight = new JButton();
	private JButton nine = new JButton();

	public tic ()
	{
		super("tic");
		setSize(200, 200);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		GridLayout grid = new GridLayout(3, 3);
		Container pane = getContentPane();
		pane.setLayout(grid);


		pane.add(one);
        pane.add(two);
        pane.add(three);
        pane.add(four);
        pane.add(five);
        pane.add(six);
        pane.add(seven);
        pane.add(eight);
        pane.add(nine);
        setVisible(true);

        one.addMouseListener(this);
        two.addMouseListener(this);
        three.addMouseListener(this);
        four.addMouseListener(this);
        five.addMouseListener(this);
        six.addMouseListener(this);
        seven.addMouseListener(this);
        eight.addMouseListener(this);
        nine.addMouseListener(this);




	}






	public void mouseClicked(MouseEvent e)
	{
			//one
			if(e.getClickCount() == 2)
			{
			one.setIcon(o);

			}
			else
			{
			one.setIcon(x);

			}

			//two
			if(e.getClickCount() == 2)
			{
			two.setIcon(o);
			}
			else
			{
			two.setIcon(x);
			}

			//three
			/*if(e.getClickCount() == 2)
			{
			three.setIcon(o);
			}
			else
			{
			three.setIcon(x);
			}

			// four
			if(e.getClickCount() == 2)
			{
			four.setIcon(o);
			}
			else
			{
			four.setIcon(x);
			}

			//five
			if(e.getClickCount() == 2)
			{
			five.setIcon(o);
			}
			else
			{
			five.setIcon(x);
			}

			//six
			if(e.getClickCount() == 2)
			{
			six.setIcon(o);
			}
			else
			{
			six.setIcon(x);
			}

			//seven
			if(e.getClickCount() == 2)
			{
			seven.setIcon(o);
			}
			else
			{
			seven.setIcon(x);
			}

			//eight
			if(e.getClickCount() == 2)
			{
			eight.setIcon(o);
			}
			else
			{
			eight.setIcon(x);
			}

			//nine
			if(e.getClickCount() == 2)
			{
			nine.setIcon(o);
			}
			else
			{
			nine.setIcon(x);
			}*/

    //      Invoked when the mouse button has been clicked (pressed and released) on a component.
	}

 	public void mouseEntered(MouseEvent e)
 	{}//          Invoked when the mouse enters a component.

 	public void mouseExited(MouseEvent e)
    {}//      Invoked when the mouse exits a component.
 	public void mousePressed(MouseEvent e)
    {


	}//      Invoked when a mouse button has been pressed on a component.
 	public void mouseReleased(MouseEvent e)
    {


	}//      Invoked when a mouse button has been released on a component.



    public static void main(String[] arguments)
    {
        new tic();
    }

	}