import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.IOException;
public class main implements Runnable {
int rows;
int columns;
int LiczbaORGANIZMOW = 0;
JLabel flagCounter;
JButton[][] buttons;
public static void main(String[] args) throws IOException,
ClassNotFoundException {
// TODO Auto-generated method stub
new main().run();
}
public main() throws IOException, ClassNotFoundException {
Swiat elo = new Swiat();
rows = 21;
columns = 21;
buttons = new JButton[rows][columns];
flagCounter = new JLabel("Liczba Organizmow: " + elo.liczbaaOrg);
JFrame frame = new JFrame("Obiektowka");
Container topCon = new Container();
Container botCon = new Container();
JPanel pane = new JPanel();
JPanel p = new JPanel();
JButton New = new JButton();
JButton Wczytaj = new JButton();
JButton Zapisz = new JButton();
JButton Tura = new JButton();
JButton Czysc = new JButton();
botCon.setSize(5, 5);
topCon.setLayout(new BorderLayout());
botCon.setLayout(new BorderLayout());
topCon.setSize(500, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(235, 235, 235, 235);
New.setSize(50, 50);
New.setBounds(50, 50, 50, 50);
New.setText("Nowa Tura");
New.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
UtworzSwiat(elo);
}
});
New.setVisible(true);
Wczytaj.setSize(50, 50);
Wczytaj.setBounds(50, 50, 50, 50);
Wczytaj.setText("Wczytaj");
Wczytaj.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
resetBoard(elo);
}
});
Wczytaj.setVisible(true);
Zapisz.setSize(50, 50);
Zapisz.setBounds(50, 50, 50, 50);
Zapisz.setText("Zapisz");
Zapisz.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Zapisz(elo);
}
});
Zapisz.setVisible(true);
Tura.setSize(50, 50);
Tura.setBounds(50, 50, 50, 50);
Tura.setText("Kolejna Tura");
Tura.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
WykonajTure(elo);
}
});
Tura.setVisible(true);
Czysc.setSize(50, 50);
Czysc.setBounds(50, 50, 50, 50);
Czysc.setText("Czyszczenie");
Czysc.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
resetBoard(elo);
}
});
Czysc.setVisible(true);
pane.add(flagCounter);
pane.add(New);
pane.add(Wczytaj);
pane.add(Zapisz);
pane.add(Tura);
pane.add(Czysc);
pane.setBounds(100, 100, 100, 100);
pane.setSize(100, 100);
frame.setVisible(true);
topCon.add(pane);
p.setLayout(new GridLayout(rows, columns, 0, 0));
for (int x = 0; x < rows; x++) {
for (int y = 0; y < columns; y++) {
if (x == 0 && y == 0) {
buttons[x][y] = new JButton();
buttons[x][y].setVisible(true);
p.add(buttons[x][y]);
}
else if (x == 0) {
buttons[x][y] = new JButton();
buttons[x][y].setVisible(true);
buttons[x][y].setText(Integer.toString(y - 1));
p.add(buttons[x][y]);
} else if (y == 0) {
buttons[x][y] = new JButton();
buttons[x][y].setVisible(true);
buttons[x][y].setText("as");
buttons[x][y].setText(Integer.toString(x - 1));
p.add(buttons[x][y]);
} else {
buttons[x][y] = new JButton();
buttons[x][y].setVisible(true);
buttons[x][y]
.setFont(new Font("Lucida Sans", Font.BOLD, 12));
buttons[x][y].setBackground(Color.white);
p.add(buttons[x][y]);
}
}
}
frame.add(p);
p.setVisible(true);
botCon.add(p);
botCon.setVisible(true);
topCon.setVisible(true);
frame.add(botCon, BorderLayout.CENTER);
frame.add(topCon, BorderLayout.NORTH);
frame.setBounds(200, 100, columns * 20, rows * 20);
pane.addKeyListener(new KAdapter());
pane.requestFocus();
frame.setVisible(true);
}
//funkjce
@Override
public void run() {
}
}
class KAdapter extends KeyAdapter implements KeyListener {
@Override
public void keyPressed(KeyEvent e) {
System.out.println("Wczytaj ruch :");
int key = e.getKeyCode();
if (key == KeyEvent.VK_LEFT) {
System.out.println("elo lewo ");
}
if (key == KeyEvent.VK_RIGHT) {
}
if (key == KeyEvent.VK_UP) {
}
if (key == KeyEvent.VK_DOWN) {
}
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
}