Created
October 7, 2014 17:46
-
-
Save 89515522549/63bee0d7d12b4dd40d10 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by 1 on 07.10.2014. | |
*/ | |
import java.awt.*; | |
import java.awt.event.*; | |
import java.util.*; | |
import javax.swing.*; | |
public abstract class ChessBoard extends JFrame implements MouseListener, MouseMotionListener | |
{ | |
JLayeredPane layeredPane; | |
JPanel chessBoard; | |
JLabel chessPiece; | |
int xAdjustment; | |
int yAdjustment; | |
public ChessBoard() | |
{ | |
Dimension boardSize = new Dimension(600, 600); | |
// Use a Layered Pane for this this application | |
layeredPane = new JLayeredPane(); | |
getContentPane().add(layeredPane); | |
layeredPane.setPreferredSize( boardSize ); | |
layeredPane.addMouseListener( this ); | |
layeredPane.addMouseMotionListener( this ); | |
// Add a chess board to the Layered Pane | |
chessBoard = new JPanel(); | |
layeredPane.add(chessBoard, JLayeredPane.DEFAULT_LAYER); | |
chessBoard.setLayout( new GridLayout(8, 8) ); | |
chessBoard.setPreferredSize( boardSize ); | |
chessBoard.setBounds(0, 0, boardSize.width, boardSize.height); | |
for (int i = 0; i < 64; i++) | |
{ | |
JPanel square = new JPanel( new BorderLayout() ); | |
chessBoard.add( square ); | |
int row = (i / 8) % 2; | |
if (row == 0) | |
square.setBackground( i % 2 == 0 ? Color.red : Color.white ); | |
else | |
square.setBackground( i % 2 == 0 ? Color.white : Color.red ); | |
} | |
// Add a few pieces to the board | |
JLabel piece = new JLabel( new ImageIcon("dukewavered.gif") ); | |
JPanel panel = (JPanel)chessBoard.getComponent( 0 ); | |
panel.add( piece ); | |
piece = new JLabel( new ImageIcon("dukewavered.gif") ); | |
panel = (JPanel)chessBoard.getComponent( 15 ); | |
panel.add( piece ); | |
} | |
public void mouseClicked(MouseEvent e) {} | |
public void mouseMoved(MouseEvent e) {} | |
public void mouseEntered(MouseEvent e) {} | |
public void mouseExited(MouseEvent e) {} | |
public static void main(String[] args) | |
{ | |
JFrame frame = new ChessBoard() { | |
@Override | |
public void mousePressed(MouseEvent e) { | |
} | |
@Override | |
public void mouseReleased(MouseEvent e) { | |
} | |
@Override | |
public void mouseDragged(MouseEvent e) { | |
} | |
}; | |
frame.setDefaultCloseOperation( DISPOSE_ON_CLOSE ); | |
frame.pack(); | |
frame.setResizable( false ); | |
frame.setLocationRelativeTo( null ); | |
frame.setVisible(true); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GIF89a2 3 p� !� � , 2 3 � 3 f � � � + +3 +f +� +� +� U U3 Uf U� U� U� � �3 �f �� �� �� � �3 �f �� �� �� � �3 �f ՙ �� �� � �3 �f �� �� ��3 3 33 f3 �3 �3 �3+ 3+33+f3+�3+�3+�3U 3U33Uf3U�3U�3U�3� 3�33�f3��3��3��3� 3�33�f3��3��3��3� 3�33�f3ՙ3��3��3� 3�33�f3��3��3��f f 3f ff �f �f �f+ f+3f+ff+�f+�f+�fU fU3fUffU�fU�fU�f� f�3f�ff��f��f��f� f�3f�ff��f��f��f� f�3f�ffՙf��f��f� f�3f�ff��f��f��� � 3� f� �� ̙ ��+ �+3�+f�+��+̙+��U �U3�Uf�U��U̙U��� ��3��f�����̙���� ��3��f�����̙���� ��3��f�ՙ��̙���� ��3��f�����̙��� � 3� f� �� �� ��+ �+3�+f�+��+��+��U �U3�Uf�U��U��U�̀ ̀3̀f̀�̀�̀�̪ ̪3̪f̪�̪�̪��� ��3��f�ՙ�������� ��3��f���������� � 3� f� �� �� ��+ �+3�+f�+��+��+��U �U3�Uf�U��U��U��� ��3��f����������� ��3��f����������� ��3��f�ՙ�������� ��3��f��������� � � H����*\Ȱ�Ç#J�H��ŋ)�ȑcƆC��xP�ɑ$��\�#˗] �"͛o⌨�'Ϟ;� r(хF�*L��(S�H�E(ujɪ3�b}�u�ʮ^M� r,Y�f�:=�6mX�l7B�[�a\�gsn��U�ӏSMY�*a�_+^̸��ǐ#Kƨl2Bbh ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.swing.*; | |
import java.awt.*; | |
import java.awt.event.MouseEvent; | |
/** | |
* Created by 1 on 07.10.2014. | |
*/ | |
public class mousw { | |
/* | |
** Add the selected chess piece to the dragging layer so it can be moved | |
*/ | |
public void mousePressed(MouseEvent e) | |
{ | |
} | |
/* | |
** Move the chess piece around | |
*/ | |
public void mouseDragged(MouseEvent me) | |
{ | |
} | |
/* | |
** Drop the chess piece back onto the chess board | |
*/ | |
public void mouseReleased(MouseEvent e) | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment