Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import java.awt.image.BufferedImage;
- import javax.swing.*;
- import javax.swing.border.EmptyBorder;
- import javax.swing.border.LineBorder;
- import java.util.*;
- public class GridTest extends JFrame implements ActionListener{
- private static ArrayList<Integer> primes;
- private static int maxPrime = 100;
- private static ArrayList<GridCell> gridCells;
- private static int currentIndex;
- private static JPanel gui;
- private static GridTest cb;
- private int size;
- private JButton[][] unitSquares;
- private JPanel xplusnSquare;
- private JLabel message;
- private static JFrame f = new JFrame("(x+n)(x+n)");;
- private boolean thingsSet = false;
- private JToolBar tools;
- public GridTest(int sizeSend) {
- int size = sizeSend;
- initializeVars(size);
- initializeGui();
- }
- public void initializeVars(int size){
- this.gui = new JPanel(new BorderLayout(0,0));
- this.size = size;
- this.unitSquares = new JButton[size][size];
- this.message = new JLabel(gridCells.get(currentIndex).print());
- }
- public static void initializeCells(){
- currentIndex = 0;
- primes = new ArrayList<Integer>();
- for(int i=3; i<maxPrime; i++){
- if(isPrime(i)){
- primes.add(i);
- }
- }
- gridCells = new ArrayList<GridCell>();
- for(int j=0; j<primes.size(); j++){
- for(int k=0; k<j; k++){
- if(primes.get(k) != primes.get(j)){
- GridCell testCell = new GridCell(primes.get(k), primes.get(j));
- if(testCell.oddxplusnsquared() && testCell.n()%2==1){
- //We're only dealing with odd n even x
- gridCells.add(testCell);
- }
- }
- }
- }
- }
- public void setGui(){
- if(thingsSet != true){
- gui.setBorder(new EmptyBorder(5, 5, 5, 5));
- gui.add(tools, BorderLayout.PAGE_START);
- }
- gui.add(xplusnSquare);
- }
- public final void initializeGui() {
- if(tools == null){
- tools = new JToolBar();
- tools.setFloatable(false);
- JButton changeButton = new JButton("Change");
- changeButton.setActionCommand("change");
- changeButton.addActionListener(this);
- tools.add(changeButton);
- tools.addSeparator();
- tools.add(message);
- }
- xplusnSquare = new JPanel(new GridBagLayout());
- xplusnSquare.setBorder(new LineBorder(Color.WHITE));
- Insets buttonMargin = new Insets(0,0,0,0);
- for (int ii = 0; ii < unitSquares.length; ii++) {
- for (int jj = 0; jj < unitSquares[ii].length; jj++) {
- JButton b = new JButton();
- int pixels = 650/size;
- b.setPreferredSize(new Dimension(pixels, pixels));
- ImageIcon icon = new ImageIcon(new BufferedImage(pixels, pixels, BufferedImage.TYPE_INT_ARGB));
- b.setIcon(icon);
- unitSquares[jj][ii] = b;
- GridBagConstraints c = new GridBagConstraints();
- c.gridx = ii;
- c.gridy = jj;
- /*
- * This is where I'm drawing the triangles. It's a whole bunch of code so it could probably be moved to
- * its own method but whatever.
- */
- if(gridCells.get(currentIndex).xplusn() == 3){
- //if it's three then the center will be black and the eight remaining squares will be the triangles
- //these don't need sophisticated border drawing to make triangles out of them
- b.setBorder(BorderFactory.createMatteBorder(1,1,1,1, Color.black)); //directly left of center
- b.setBackground(Color.CYAN);
- //if you're in the middle, make it black
- if(ii==((size-1)/2) && jj==((size-1)/2)){
- b.setBackground(Color.BLACK);
- }
- } else {
- //drawing the triangles
- if(jj==((size-1)/2) && ii==(((size-1)/2)-1)){
- b.setBorder(BorderFactory.createMatteBorder(1,0,1,0, Color.black)); //directly left of center
- } else if(jj==((size-1)/2) && ii<(((size-1)/2)-1) && ii>0){
- b.setBorder(BorderFactory.createMatteBorder(1,0,0,0, Color.black)); //left of center to before left edge
- } else if(((((size-1)/2)-jj)+(((size-1)/2)-ii)==1) && jj>ii && ii>0){
- b.setBorder(BorderFactory.createMatteBorder(0,0,1,1, Color.black)); //diagonal left and down
- } else if(ii==(((size-1)/2)-1) && jj>((size-1)/2) && jj<size-1){
- b.setBorder(BorderFactory.createMatteBorder(0,0,0,1, Color.black)); //downwards directly left of center
- } else if(ii==0 && jj==((size-1)/2)){
- b.setBorder(BorderFactory.createMatteBorder(1,1,0,0, Color.black)); //left edge center corner
- } else if(ii==0 && jj>((size-1)/2) && jj<(size-2)){
- b.setBorder(BorderFactory.createMatteBorder(0,1,0,0, Color.black)); //left edge downwards from center
- } else if(ii==0 && jj==(size-2)){
- b.setBorder(BorderFactory.createMatteBorder(0,1,1,1, Color.black)); //left bottom corner of triangle (2nd last square)
- } else if(ii==0 && jj==(size-1)){
- b.setBorder(BorderFactory.createMatteBorder(0,1,1,0, Color.black)); //left bottom corner
- } else if(ii>0 && ii<(((size-1)/2)-1) && jj==(size-1)){
- b.setBorder(BorderFactory.createMatteBorder(0,0,1,0, Color.black)); //bottom edge before center
- } else if(ii==(((size-1)/2)-1) && jj==(size-1)){
- b.setBorder(BorderFactory.createMatteBorder(0,0,1,1, Color.black)); //bottom left inner corner before center
- } else if(jj==((size-1)/2) && ii==(((size-1)/2)+1)){
- b.setBorder(BorderFactory.createMatteBorder(1,0,1,0, Color.black)); //directly right of center
- } else if(jj==((size-1)/2) && ii>(((size-1)/2)-1) && ii<(size-1)){
- b.setBorder(BorderFactory.createMatteBorder(0,0,1,0, Color.black)); //right of center to before right edge
- } else if(((jj-((size-1)/2))+(ii-((size-1)/2))==1) && jj<ii && jj>0){
- if(ii==(size-1)){
- b.setBorder(BorderFactory.createMatteBorder(1,1,0,1, Color.black)); //diagonal right and up
- } else {
- b.setBorder(BorderFactory.createMatteBorder(1,1,0,0, Color.black)); //diagonal right and up
- }
- } else if(ii==(((size-1)/2)+1) && jj<((size-1)/2) && jj>0){
- b.setBorder(BorderFactory.createMatteBorder(0,1,0,0, Color.black)); //upwards directly right of center
- } else if(ii==(size-1) && jj==((size-1)/2)){
- b.setBorder(BorderFactory.createMatteBorder(0,0,1,1, Color.black)); //right edge center corner
- } else if(ii==(size-1) && jj<0 && jj>(size-2)){
- b.setBorder(BorderFactory.createMatteBorder(0,1,0,0, Color.black)); //right edge upwards from center
- } else if(jj==0 && ii>(((size-1)/2)+1) && ii<(size-1)){
- b.setBorder(BorderFactory.createMatteBorder(1,0,0,0, Color.black)); //top right
- } else if(ii==(size-1) && jj==0){
- b.setBorder(BorderFactory.createMatteBorder(1,0,0,1, Color.black)); //diagonal right and up
- } else if(ii==(((size-1)/2)+1) && jj==0){
- b.setBorder(BorderFactory.createMatteBorder(1,1,0,0, Color.black)); //diagonal right and up
- } else if(ii==(size-1) && jj>1 && jj<((size-1)/2)){
- b.setBorder(BorderFactory.createMatteBorder(0,0,0,1, Color.black)); //diagonal right and up
- } else if(jj==(((size-1)/2)+1) && ii==((size-1)/2)){
- b.setBorder(BorderFactory.createMatteBorder(0,0,0,1, Color.black)); //directly below center
- } else if(jj==(size-1) && ii>=((size-1)/2) && ii<(size-2)){
- b.setBorder(BorderFactory.createMatteBorder(0,0,1,0, Color.black)); //bottom below center
- } else if(jj==(size-1) && ii==(size-2)){
- b.setBorder(BorderFactory.createMatteBorder(1,0,1,1, Color.black)); //directly below center
- } else if(ii-jj==-1 && ii>((size-1)/2) && jj>((size-1)/2)){
- b.setBorder(BorderFactory.createMatteBorder(1,0,0,1, Color.black)); //diagonal right and down
- } else if(jj==(size-1) && ii==(size-1)){
- b.setBorder(BorderFactory.createMatteBorder(0,0,1,1, Color.black)); //bottom right corner
- } else if(jj>((size-1)/2) && jj<(size-1) && ii==(size-1)){
- b.setBorder(BorderFactory.createMatteBorder(0,0,0,1, Color.black)); //right edge downwards
- } else if(jj==0 && ii==0){
- b.setBorder(BorderFactory.createMatteBorder(1,1,0,1, Color.black)); //top corner
- } else if(ii==0 && jj>0 && jj<((size-1)/2)){
- b.setBorder(BorderFactory.createMatteBorder(0,1,0,0, Color.black)); //left top side edge
- } else if(jj==0 && ii>0 && ii<(((size-1)/2)+1)){
- b.setBorder(BorderFactory.createMatteBorder(1,0,0,0, Color.black)); //left top top edge
- } else if(ii==jj && ii>0 && ii<((size-1)/2) && jj>0 && jj<((size-1)/2)){
- b.setBorder(BorderFactory.createMatteBorder(1,0,0,1, Color.black)); //directly below center
- } else {
- b.setBorder(BorderFactory.createMatteBorder(0,0,0,0, Color.black)); //inner parts blank
- }
- /*
- * Now I need to set the colours
- * nn+2d(n-1)+f-1
- * nn is purple (in this case Java.Color.MAGENTA)
- * 2d(n-1) is red
- * f is blue (in this case Java.Color.CYAN)
- */
- b.setBackground(Color.WHITE);
- //nn+2d(n-1)+f-1
- //If n=1 there's no nn because of the -1 (the black square in the middle
- //If n=1 there's no 2d(n-1) since n-1=0
- //So if n=1 you have to fill the whole square with f
- if(gridCells.get(currentIndex).xplusn() != 1){
- //if x+n=1, it's just the one black square, so it's already done
- if(gridCells.get(currentIndex).n() == 1){
- //everything other than the center is f-coloured
- if(!(ii==((size-1)/2) && jj==((size-1)/2))){
- b.setBackground(Color.CYAN);
- }
- } else {
- int offset = (((gridCells.get(currentIndex).n())-1)/2)+1;
- //if n!=1 n's still going to be odd because that's how I set it up
- //it needs to be set up so that the n square is around the outside of the center black square
- //it'll be (n-1)/2 away from the center
- if(ii>=(((size-1)/2)-((gridCells.get(currentIndex).n()-1)/2))
- && ii<=(((size-1)/2)+((gridCells.get(currentIndex).n()-1)/2))
- && jj>=(((size-1)/2)-(gridCells.get(currentIndex).n()-1)/2)
- && jj<=(((size-1)/2)+(gridCells.get(currentIndex).n()-1)/2)){
- //everything here is nn-coloured
- b.setBackground(Color.MAGENTA);
- } else {
- //then somehow I need to figure out how to put f in there
- //everything else will be 2d(n-1) so I guess that'll just be another else excluding center
- //so first I need to find f%8
- int fmod8 = (gridCells.get(currentIndex).f()*-1)%8;
- int fminmod = (gridCells.get(currentIndex).f()*-1)-fmod8;
- int fdiv8 = fminmod/8;
- int nextrowlength = ((gridCells.get(currentIndex).n())+1)/2;
- int n = gridCells.get(currentIndex).n(); //should've done this already
- //fdiv8 is how many to put in each triangle
- //the length of the part of the triangle outside of nn will be (n+1)/2
- //e.g. if n=19, the closest row of the triangles will be (19+1)/2=10 long
- //if f/8 is less than that, you can just go from wherever you drew a line between triangles
- //and keep going in the opposite direction
- //if f/8 is greater than that, you'll need to fill the whole row for eah triangle and then
- //do the same thing you did for f/8<((n+1)/2) but with the next row out
- //man this sounds really hard, fucking hell why am I doing this
- int toput = (gridCells.get(currentIndex).f()*-1);
- if(fdiv8 <= nextrowlength){
- //let's say you're putting 24 in
- //in the first triangle, it'd be the first, the ninth and the seventeenth
- //so you'd go "if you're in that set of squares and the distance from here to origin
- //times 8 +1 (+1 for first triangle) is less than or equal to toput
- if(
- (
- (ii<=((size-1)/2))
- &&
- (ii>(((size-1)/2)-offset))
- &&
- (jj==(((size-1)/2)-offset))
- )
- &&
- (
- (
- (
- (
- (
- (
- (size-1)
- /2)
- -ii)
- *8)
- +1)
- <=toput)
- )){
- b.setBackground(Color.CYAN);
- } else if(
- ( (jj<=(((size-1)/2))-1) && (jj>(((size-1)/2)-(offset+1))) && ii==(((size-1)/2)-offset))
- && (
- ( ((((((size-1)/2)-1)-jj)*8)+2)
- <=toput))
- ){
- b.setBackground(Color.CYAN);
- } else if(
- ( (jj>=(((size-1)/2))) && (jj<(((size-1)/2)+(offset))) && ii==(((size-1)/2)-offset))
- && (
- ( (((jj-((size-1)/2))*8)+3)
- <=toput))
- ){
- b.setBackground(Color.CYAN);
- } else if(
- ( (ii<=(((size-1)/2)-1)) && (ii>(((size-1)/2)-(offset+1))) && jj==(((size-1)/2)+offset))
- && (
- ( ((((((size-1)/2)-1)-ii)*8)+4)
- <=toput))
- ){
- b.setBackground(Color.CYAN);
- } else if(
- ( (ii>=(((size-1)/2))) && (ii<(((size-1)/2)+(offset))) && jj==(((size-1)/2)+offset))
- && (
- ( ((((ii-((size-1)/2)))*8)+5)
- <=toput))
- ){
- b.setBackground(Color.CYAN);
- } else if(
- ( (jj>=(((size-1)/2)+1)) && (jj<(((size-1)/2)+1+(offset))) && ii==(((size-1)/2)+offset))
- && (
- ( (((jj-(((size-1)/2)+1))*8)+6)
- <=toput))
- ){
- b.setBackground(Color.CYAN);
- } else if(
- ( (jj<=(((size-1)/2))) && (jj>(((size-1)/2)-(offset))) && ii==(((size-1)/2)+offset))
- && (
- ( ((((((size-1)/2)-jj))*8)+7)
- <=toput))
- ){
- b.setBackground(Color.CYAN);
- } else if(
- ( (ii>(((size-1)/2))) && (ii<(((size-1)/2)+1+(offset))) && jj==(((size-1)/2)-offset))
- && (
- ( (((ii-(((size-1)/2)+1))*8)+8)
- <=toput))
- ){
- b.setBackground(Color.CYAN);
- }
- } else {
- offset++;
- //in a perfect world, I would make this some kind of recursive function
- //I probably could but why the fuck would I spend that much time on something like this
- //if you're reading this and this looks like poor design to you, (a) I agree and (b) fuck you, either
- //fix it for me or live with it
- //this GUI can only really handle primes up to 97 before taking too long/being too big, and I've
- //gone through each example and found that the furthest f/8 goes in terms of rows away from nn
- //is a third row, so we only need a couple if statements to make the thing work
- //don't like it? fix it yourself. I'm done putting every waking moment into VQC without any help.
- //fill the rows with f-colour
- if(((ii==(((size-1)/2)-((n+1)/2))) && (jj>=((((size-1)/2))-((n+1)/2))) && (jj<=((((size-1)/2))+((n+1)/2))))
- ||((ii==(((size-1)/2)+((n+1)/2))) && (jj>=((((size-1)/2))-((n+1)/2))) && (jj<=((((size-1)/2))+((n+1)/2))))
- ||((jj==(((size-1)/2)-((n+1)/2))) && (ii>=((((size-1)/2))-((n+1)/2))) && (ii<=((((size-1)/2))+((n+1)/2))))
- ||((jj==(((size-1)/2)+((n+1)/2))) && (ii>=((((size-1)/2))-((n+1)/2))) && (ii<=((((size-1)/2))+((n+1)/2))))
- ){
- b.setBackground(Color.CYAN);
- }
- //then take nextrowlength away from fdiv8
- fdiv8-=nextrowlength;
- //then add one to nextrowlength
- nextrowlength++;
- //then check again if fdiv8>nextrowlength
- if(fdiv8 <= nextrowlength){
- toput = toput - ((nextrowlength-1)*8);
- if(
- ( (ii<=((size-1)/2)) && (ii>(((size-1)/2)-offset)) && jj==(((size-1)/2)-offset))
- && (
- ( (((((size-1)/2)-ii)*8)+1)
- <=toput)
- )){
- b.setBackground(Color.CYAN);
- } else if(
- ( (jj<=(((size-1)/2))-1) && (jj>(((size-1)/2)-(offset+1))) && ii==(((size-1)/2)-offset))
- && (
- ( ((((((size-1)/2)-1)-jj)*8)+2)
- <=toput))
- ){
- b.setBackground(Color.CYAN);
- } else if(
- ( (jj>=(((size-1)/2))) && (jj<(((size-1)/2)+(offset))) && ii==(((size-1)/2)-offset))
- && (
- ( (((jj-((size-1)/2))*8)+3)
- <=toput))
- ){
- b.setBackground(Color.CYAN);
- } else if(
- ( (ii<=(((size-1)/2)-1)) && (ii>(((size-1)/2)-(offset+1))) && jj==(((size-1)/2)+offset))
- && (
- ( ((((((size-1)/2)-1)-ii)*8)+4)
- <=toput))
- ){
- b.setBackground(Color.CYAN);
- } else if(
- ( (ii>=(((size-1)/2))) && (ii<(((size-1)/2)+(offset))) && jj==(((size-1)/2)+offset))
- && (
- ( ((((ii-((size-1)/2)))*8)+5)
- <=toput))
- ){
- b.setBackground(Color.CYAN);
- } else if(
- ( (jj>=(((size-1)/2)+1)) && (jj<(((size-1)/2)+1+(offset))) && ii==(((size-1)/2)+offset))
- && (
- ( (((jj-(((size-1)/2)+1))*8)+6)
- <=toput))
- ){
- b.setBackground(Color.CYAN);
- } else if(
- ( (jj<=(((size-1)/2))) && (jj>(((size-1)/2)-(offset))) && ii==(((size-1)/2)+offset))
- && (
- ( ((((((size-1)/2)-jj))*8)+7)
- <=toput))
- ){
- b.setBackground(Color.CYAN);
- } else if(
- ( (ii>(((size-1)/2))) && (ii<(((size-1)/2)+1+(offset))) && jj==(((size-1)/2)-offset))
- && (
- ( (((ii-(((size-1)/2)+1))*8)+8)
- <=toput))
- ){
- b.setBackground(Color.CYAN);
- }
- } else {
- offset++;
- //fill the rows with f-colour
- if(((ii==(((size-1)/2)-(((n+1)/2)+1))) && (jj>=((((size-1)/2))-(((n+1)/2)+1))) && (jj<=((((size-1)/2))+(((n+1)/2)+1))))
- ||((ii==(((size-1)/2)+(((n+1)/2)+1))) && (jj>=((((size-1)/2))-(((n+1)/2)+1))) && (jj<=((((size-1)/2))+(((n+1)/2)+1))))
- ||((jj==(((size-1)/2)-(((n+1)/2)+1))) && (ii>=((((size-1)/2))-(((n+1)/2)+1))) && (ii<=((((size-1)/2))+(((n+1)/2)+1))))
- ||((jj==(((size-1)/2)+(((n+1)/2)+1))) && (ii>=((((size-1)/2))-(((n+1)/2)+1))) && (ii<=((((size-1)/2))+(((n+1)/2)+1))))
- ){
- b.setBackground(Color.CYAN);
- }
- //then take nextrowlength away from fdiv8
- fdiv8-=nextrowlength;
- //then add one to nextrowlength
- nextrowlength++;
- //then check again if fdiv8>nextrowlength
- if(fdiv8 <= nextrowlength){
- toput = toput - ((nextrowlength-1)*8);
- if(
- ( (ii<=((size-1)/2)) && (ii>(((size-1)/2)-offset)) && jj==(((size-1)/2)-offset))
- && (
- ( (((((size-1)/2)-ii)*8)+1)
- <=toput))
- ){
- b.setBackground(Color.CYAN);
- } else if(
- ( (jj<=(((size-1)/2))-1) && (jj>(((size-1)/2)-(offset+1))) && ii==(((size-1)/2)-offset))
- && (
- ( ((((((size-1)/2)-1)-jj)*8)+2)
- <=toput))
- ){
- b.setBackground(Color.CYAN);
- } else if(
- ( (jj>=(((size-1)/2))) && (jj<(((size-1)/2)+(offset))) && ii==(((size-1)/2)-offset))
- && (
- ( (((jj-((size-1)/2))*8)+3)
- <=toput))
- ){
- b.setBackground(Color.CYAN);
- } else if(
- ( (ii<=(((size-1)/2)-1)) && (ii>(((size-1)/2)-(offset+1))) && jj==(((size-1)/2)+offset))
- && (
- ( ((((((size-1)/2)-1)-ii)*8)+4)
- <=toput))
- ){
- b.setBackground(Color.CYAN);
- } else if(
- ( (ii>=(((size-1)/2))) && (ii<(((size-1)/2)+(offset))) && jj==(((size-1)/2)+offset))
- && (
- ( ((((ii-((size-1)/2)))*8)+5)
- <=toput))
- ){
- b.setBackground(Color.CYAN);
- } else if(
- ( (jj>=(((size-1)/2)+1)) && (jj<(((size-1)/2)+1+(offset))) && ii==(((size-1)/2)+offset))
- && (
- ( (((jj-(((size-1)/2)+1))*8)+6)
- <=toput))
- ){
- b.setBackground(Color.CYAN);
- } else if(
- ( (jj<=(((size-1)/2))) && (jj>(((size-1)/2)-(offset))) && ii==(((size-1)/2)+offset))
- && (
- ( ((((((size-1)/2)-jj))*8)+7)
- <=toput))
- ){
- b.setBackground(Color.CYAN);
- } else if(
- ( (ii>(((size-1)/2))) && (ii<(((size-1)/2)+1+(offset))) && jj==(((size-1)/2)-offset))
- && (
- ( (((ii-(((size-1)/2)+1))*8)+8)
- <=toput))
- ){
- b.setBackground(Color.CYAN);
- }
- } else {
- //fill the rows with f-colour
- if(((ii==(((size-1)/2)-(((n+1)/2)+2))) && (jj>=((((size-1)/2))-(((n+1)/2)+2))) && (jj<=((((size-1)/2))+(((n+1)/2)+2))))
- ||((ii==(((size-1)/2)+(((n+1)/2)+2))) && (jj>=((((size-1)/2))-(((n+1)/2)+2))) && (jj<=((((size-1)/2))+(((n+1)/2)+2))))
- ||((jj==(((size-1)/2)-(((n+1)/2)+2))) && (ii>=((((size-1)/2))-(((n+1)/2)+2))) && (ii<=((((size-1)/2))+(((n+1)/2)+2))))
- ||((jj==(((size-1)/2)+(((n+1)/2)+2))) && (ii>=((((size-1)/2))-(((n+1)/2)+2))) && (ii<=((((size-1)/2))+(((n+1)/2)+2))))
- ){
- b.setBackground(Color.CYAN);
- }
- }
- }
- }
- }
- }
- }
- //if you're in the middle, make it black
- if(ii==((size-1)/2) && jj==((size-1)/2)){
- b.setBorder(BorderFactory.createMatteBorder(1,1,1,1, Color.black)); //diagonal left and down
- b.setBackground(Color.BLACK);
- }
- if(b.getBackground() == Color.WHITE){
- b.setBackground(Color.RED);
- }
- }
- xplusnSquare.add(unitSquares[jj][ii], c);
- }
- }
- setGui();
- }
- public void actionPerformed(ActionEvent e) {
- if ("change".equals(e.getActionCommand())) {
- initializeVars(13);
- initializeGui();
- startThing();
- }
- }
- public static boolean isPrime(int n){
- if(n==1 || n==2 || n==4){
- return false;
- }
- for(int i=2; i<n; i++){
- if(n%i==0){
- return false;
- }
- }
- return true;
- }
- public JComponent getGui(){
- return gui;
- }
- public static void main(String[] args) {
- Runnable r = new Runnable() {
- @Override
- public void run() {
- startThing();
- }
- };
- SwingUtilities.invokeLater(r);
- }
- public static void startThing(){
- if(cb != null){ //if you're changing the triangles
- currentIndex++;
- if(currentIndex == gridCells.size()){
- currentIndex = 0;
- }
- cb = new GridTest(gridCells.get(currentIndex).xplusn());
- f.getContentPane().removeAll();
- f.add(cb.getGui());
- f.setMinimumSize(f.getSize());
- f.pack();
- f.setSize(725,725);
- } else { //initial triangles
- initializeCells();
- gui = null;
- cb = new GridTest(gridCells.get(currentIndex).xplusn());
- f.add(cb.getGui());
- f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- f.setLocationByPlatform(true);
- f.pack();
- f.setSize(725,725);
- f.setMinimumSize(f.getSize());
- f.setVisible(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment