Tutaj jest reszta kodu bez klasy Cell
public class ramka extends JFrame {
JButton button1, button2;
JTextField textField1, textField2,textField3, textField4;
JLabel label1, label2,label3, label4;
ArrayList<Cell>ListaGłówna;
static public void main(String[] args) {
ArrayList<Cell> ListaGłówna=tworzenieListy(5,5);
connectingCells(ListaGłówna, 5);
new ramka();
}
public ramka()
{
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("My First Frame");
/////////////////////////////////Panel1///////////////////////////////////////////
JPanel thePanel1 = new JPanel();
//thePanel1.setLayout(new FlowLayout(FlowLayout.LEFT, 30,20));
Box theBox = Box.createHorizontalBox();
label1 = new JLabel("Wiersz");
textField1 = new JTextField("5",5);
thePanel1.add(textField1);
label2 = new JLabel("Kolumna");
thePanel1.add(label2);
textField2 = new JTextField("5",5);
thePanel1.add(textField2);
button1 = new JButton("Generuj");
ListenForButton lForButton =new ListenForButton();
button1.addActionListener(lForButton);
thePanel1.add(button1);
label3 = new JLabel("Start");
thePanel1.add(label3);
textField3 = new JTextField("",5);
thePanel1.add(textField3);
label4 = new JLabel("Koniec");
thePanel1.add(label4);
textField4 = new JTextField("",5);
thePanel1.add(textField4);
button2 = new JButton("Szukaj");
button2.addActionListener(lForButton);
theBox.add(label1);
theBox.add(textField1);
theBox.add(label2);
theBox.add(textField2);
theBox.add(button1);
theBox.add(label3);
theBox.add(textField3);
theBox.add(label4);
theBox.add(textField4);
theBox.add(button2);
thePanel1.add(theBox);
this.add(thePanel1, BorderLayout.SOUTH);
/////////////////////////////Panel2////////////////////////////////////////
Rysowanie thePanel2 = new Rysowanie(ListaGłówna);
this.add(thePanel2 ,BorderLayout.CENTER);
this.pack();
this.setVisible(true);
}
private class ListenForButton implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==button1) {
repaint();
}
}
}
static public ArrayList<Cell> tworzenieListy( int x, int y ) {
ArrayList<Cell> ListaGłówna=new ArrayList<Cell>(x*y);
int wspX=0;
int wspY=0;
int wiersz=x;
for(int i=1; i<=x*y; i++) {
if(i==wiersz+1) {
wspX=0;
wspY+=40;
wiersz+=wiersz;
}
Cell to = new Cell(i,wspX,wspY);
ListaGłówna.add(to);
wspX+=40;
}
return ListaGłówna;
}
static public void connectingCells(ArrayList<Cell> ListaGłowna, int x) {
int wiersz=x;
for(Cell tokio : ListaGłowna) {
if(tokio.getName()==wiersz && tokio.getName()!=ListaGłowna.size() ){ // Połączenia dla ostatniej kolumny
tokio.setConnectionForLastColumn(ListaGłowna, x);
wiersz=wiersz+x;
}
else if(tokio.getName() >= (ListaGłowna.size()-x +1) && tokio.getName()!=ListaGłowna.size()) { //Połączenia dla ostatniego wiersza
tokio.setConnectionForLastRow(ListaGłowna);
}
else if(tokio.getName()!=ListaGłowna.size()) { //Ustawnianie dla całej reszty
tokio.setConnectionForReminder(ListaGłowna, x);
}
}
}
}