Board=JPanel, Schack=JFrame

This commit is contained in:
lov3b
2022-03-01 18:39:24 +01:00
parent a66a3e625a
commit 2bb09a0f94
7 changed files with 134 additions and 149 deletions

View File

@ -5,57 +5,33 @@ import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Board extends JFrame
{
public class Board extends JPanel {
ArrayList<Piece> pieces = new ArrayList<>();
public Board()
{
setTitle("Schack");
setAlwaysOnTop(true);
setResizable(false);
setContentPane(cp);
cp.setPreferredSize(new Dimension(800, 800) );
pack();
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
public Board() {
setPreferredSize(new Dimension(800, 800));
}
JPanel cp = new JPanel()
{
public void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
g2.scale(100, 100);
g2.setBackground(Color.WHITE);
g2.setColor(Color.BLACK);
for (int i = 0; i < 8; i += 2) {
for (int j = 0; j < 8; j += 2) {
g.fillRect(i, j, 1, 1);
}
}
for (int i = 1; i < 8; i += 2) {
for (int j = 1; j < 8; j += 2) {
g.fillRect(i, j, 1, 1);
}
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.scale(100, 100);
g2.setBackground(Color.WHITE);
g2.setColor(Color.BLACK);
for (int i = 0; i < 8; i += 2) {
for (int j = 0; j < 8; j += 2) {
g.fillRect(i, j, 1, 1);
}
}
};
// for(Piece p : pieces){
// p.draw();
// }
public static void main(String[] args)
{
new Board();
for (int i = 1; i < 8; i += 2) {
for (int j = 1; j < 8; j += 2) {
g.fillRect(i, j, 1, 1);
}
}
}
}

View File

@ -9,8 +9,8 @@ package schack;
*
* @author lovbil251
*/
public interface DiagonalWalk
{
public interface DiagonalWalk {
public void walDiagonal();
}

View File

@ -1,6 +1,8 @@
package schack;
public final class King extends Piece{
public final class King extends Piece {
public boolean isSeen(){return true;}
public boolean isSeen() {
return true;
}
}

View File

@ -4,13 +4,14 @@ import java.awt.Point;
import java.util.ArrayList;
public class Piece {
public Point position;
public boolean isValidMove(Point p, ArrayList<Piece> pieces){return true;}
void draw()
{
public Point position;
public boolean isValidMove(Point p, ArrayList<Piece> pieces) {
return true;
}
void draw() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

View File

@ -1,35 +1,28 @@
package schack;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
/**
*
* @author Love Billenius & Simon Hansson
*/
public class Schack extends JFrame
{
public class Schack extends JFrame {
public Dimension size = new Dimension(800, 800);
public Schack()
{
setSize(size);
public Schack() {
setTitle("Schack");
setAlwaysOnTop(true);
setBackground(Color.black);
setResizable(false);
setContentPane(new Board());
pack();
setVisible(true);
}
private void drawSquares(Graphics g){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
public static void main(String[] args) {
new Schack();
}