I'm making my own object class Diamond for a school project which extends JPanel. I'm not getting any compile-time or run-time errors, but my object won't appear in the JFrame. Any help?
Here's my Diamond class:
Here's my code for the testing class:
I'm absolutely lost as to what my problem is, as this is my first dive into declaring my own Component class. Any help here?
Here's my Diamond class:
import java.awt.*;
import javax.swing.*;
import java.awt.Color;
import java.awt.Container;
public class Diamond extends javax.swing.JPanel
{
JPanel diamond;
JPanel a1;
JPanel a2;
JPanel a3;
JPanel a4;
JPanel a5;
JPanel a6;
JPanel a7;
JPanel a8;
JPanel a9;
JPanel a10;
JPanel a11;
JPanel b1;
JPanel b2;
JPanel b3;
JPanel b4;
JPanel b5;
JPanel b6;
JPanel b7;
JPanel b8;
JPanel b9;
JPanel b10;
JPanel b11;
JPanel c1;
JPanel c2;
JPanel c3;
JPanel c4;
JPanel c5;
JPanel c6;
JPanel c7;
JPanel c8;
JPanel c9;
JPanel c10;
JPanel c11;
JPanel d1;
JPanel d2;
JPanel d3;
JPanel d4;
JPanel d5;
JPanel d6;
JPanel d7;
JPanel d8;
JPanel d9;
JPanel d10;
JPanel d11;
JPanel e1;
JPanel e2;
JPanel e3;
JPanel e4;
JPanel e5;
JPanel e6;
JPanel e7;
JPanel e8;
JPanel e9;
JPanel e10;
JPanel e11;
JPanel f1;
JPanel f2;
JPanel f3;
JPanel f4;
JPanel f5;
JPanel f6;
JPanel f7;
JPanel f8;
JPanel f9;
JPanel f10;
JPanel f11;
JPanel g1;
JPanel g2;
JPanel g3;
JPanel g4;
JPanel g5;
JPanel g6;
JPanel g7;
JPanel g8;
JPanel g9;
JPanel g10;
JPanel g11;
JPanel h1;
JPanel h2;
JPanel h3;
JPanel h4;
JPanel h5;
JPanel h6;
JPanel h7;
JPanel h8;
JPanel h9;
JPanel h10;
JPanel h11;
JPanel i1;
JPanel i2;
JPanel i3;
JPanel i4;
JPanel i5;
JPanel i6;
JPanel i7;
JPanel i8;
JPanel i9;
JPanel i10;
JPanel i11;
JPanel j1;
JPanel j2;
JPanel j3;
JPanel j4;
JPanel j5;
JPanel j6;
JPanel j7;
JPanel j8;
JPanel j9;
JPanel j10;
JPanel j11;
JPanel k1;
JPanel k2;
JPanel k3;
JPanel k4;
JPanel k5;
JPanel k6;
JPanel k7;
JPanel k8;
JPanel k9;
JPanel k10;
JPanel k11;
public void makeDiamond()
{
diamond = new JPanel(new GridLayout(11,11));
a1 = new JPanel();
a2 = new JPanel();
a3 = new JPanel();
a4 = new JPanel();
a5 = new JPanel();
a6 = new JPanel();
a7 = new JPanel();
a8 = new JPanel();
a9 = new JPanel();
a10 = new JPanel();
a11 = new JPanel();
b1 = new JPanel();
b2 = new JPanel();
b3 = new JPanel();
b4 = new JPanel();
b5 = new JPanel();
b6 = new JPanel();
b7 = new JPanel();
b8 = new JPanel();
b9 = new JPanel();
b10 = new JPanel();
b11 = new JPanel();
c1 = new JPanel();
c2 = new JPanel();
c3 = new JPanel();
c4 = new JPanel();
c5 = new JPanel();
c6 = new JPanel();
c7 = new JPanel();
c8 = new JPanel();
c9 = new JPanel();
c10 = new JPanel();
c11 = new JPanel();
d1 = new JPanel();
d2 = new JPanel();
d3 = new JPanel();
d4 = new JPanel();
d5 = new JPanel();
d6 = new JPanel();
d7 = new JPanel();
d8 = new JPanel();
d9 = new JPanel();
d10 = new JPanel();
d11 = new JPanel();
e1 = new JPanel();
e2 = new JPanel();
e3 = new JPanel();
e4 = new JPanel();
e5 = new JPanel();
e6 = new JPanel();
e7 = new JPanel();
e8 = new JPanel();
e9 = new JPanel();
e10 = new JPanel();
e11 = new JPanel();
f1 = new JPanel();
f2 = new JPanel();
f3 = new JPanel();
f4 = new JPanel();
f5 = new JPanel();
f6 = new JPanel();
f7 = new JPanel();
f8 = new JPanel();
f9 = new JPanel();
f10 = new JPanel();
f11 = new JPanel();
g1 = new JPanel();
g2 = new JPanel();
g3 = new JPanel();
g4 = new JPanel();
g5 = new JPanel();
g6 = new JPanel();
g7 = new JPanel();
g8 = new JPanel();
g9 = new JPanel();
g10 = new JPanel();
g11 = new JPanel();
h1 = new JPanel();
h2 = new JPanel();
h3 = new JPanel();
h4 = new JPanel();
h5 = new JPanel();
h6 = new JPanel();
h7 = new JPanel();
h8 = new JPanel();
h9 = new JPanel();
h10 = new JPanel();
h11 = new JPanel();
i1 = new JPanel();
i2 = new JPanel();
i3 = new JPanel();
i4 = new JPanel();
i5 = new JPanel();
i6 = new JPanel();
i7 = new JPanel();
i8 = new JPanel();
i9 = new JPanel();
i10 = new JPanel();
i11 = new JPanel();
j1 = new JPanel();
j2 = new JPanel();
j3 = new JPanel();
j4 = new JPanel();
j5 = new JPanel();
j6 = new JPanel();
j7 = new JPanel();
j8 = new JPanel();
j9 = new JPanel();
j10 = new JPanel();
j11 = new JPanel();
k1 = new JPanel();
k2 = new JPanel();
k3 = new JPanel();
k4 = new JPanel();
k5 = new JPanel();
k6 = new JPanel();
k7 = new JPanel();
k8 = new JPanel();
k9 = new JPanel();
k10 = new JPanel();
k11 = new JPanel();
diamond.add(a1);
diamond.add(a2);
diamond.add(a3);
diamond.add(a4);
diamond.add(a5);
diamond.add(a6);
diamond.add(a7);
diamond.add(a8);
diamond.add(a9);
diamond.add(a10);
diamond.add(a11);
diamond.add(b1);
diamond.add(b2);
diamond.add(b3);
diamond.add(b4);
diamond.add(b5);
diamond.add(b6);
diamond.add(b7);
diamond.add(b8);
diamond.add(b9);
diamond.add(b10);
diamond.add(b11);
diamond.add(c1);
diamond.add(c2);
diamond.add(c3);
diamond.add(c4);
diamond.add(c5);
diamond.add(c6);
diamond.add(c7);
diamond.add(c8);
diamond.add(c9);
diamond.add(c10);
diamond.add(c11);
diamond.add(d1);
diamond.add(d2);
diamond.add(d3);
diamond.add(d4);
diamond.add(d5);
diamond.add(d6);
diamond.add(d7);
diamond.add(d8);
diamond.add(d9);
diamond.add(d10);
diamond.add(d11);
diamond.add(e1);
diamond.add(e2);
diamond.add(e3);
diamond.add(e4);
diamond.add(e5);
diamond.add(e6);
diamond.add(e7);
diamond.add(e8);
diamond.add(e9);
diamond.add(e10);
diamond.add(e11);
diamond.add(f1);
diamond.add(f2);
diamond.add(f3);
diamond.add(f4);
diamond.add(f5);
diamond.add(f6);
diamond.add(f7);
diamond.add(f8);
diamond.add(f9);
diamond.add(f10);
diamond.add(f11);
diamond.add(g1);
diamond.add(g2);
diamond.add(g3);
diamond.add(g4);
diamond.add(g5);
diamond.add(g6);
diamond.add(g7);
diamond.add(g8);
diamond.add(g9);
diamond.add(g10);
diamond.add(g11);
diamond.add(h1);
diamond.add(h2);
diamond.add(h3);
diamond.add(h4);
diamond.add(h5);
diamond.add(h6);
diamond.add(h7);
diamond.add(h8);
diamond.add(h9);
diamond.add(h10);
diamond.add(h11);
diamond.add(i1);
diamond.add(i2);
diamond.add(i3);
diamond.add(i4);
diamond.add(i5);
diamond.add(i6);
diamond.add(i7);
diamond.add(i8);
diamond.add(i9);
diamond.add(i10);
diamond.add(i11);
diamond.add(j1);
diamond.add(j2);
diamond.add(j3);
diamond.add(j4);
diamond.add(j5);
diamond.add(j6);
diamond.add(j7);
diamond.add(j8);
diamond.add(j9);
diamond.add(j10);
diamond.add(j11);
diamond.add(k1);
diamond.add(k2);
diamond.add(k3);
diamond.add(k4);
diamond.add(k5);
diamond.add(k6);
diamond.add(k7);
diamond.add(k8);
diamond.add(k9);
diamond.add(k10);
diamond.add(k11);
a1.setBackground(Color.WHITE);
a2.setBackground(Color.WHITE);
a3.setBackground(Color.WHITE);
a4.setBackground(Color.WHITE);
a5.setBackground(Color.WHITE);
a6.setBackground(Color.WHITE);
a7.setBackground(Color.WHITE);
a8.setBackground(Color.WHITE);
a9.setBackground(Color.WHITE);
a10.setBackground(Color.WHITE);
a11.setBackground(Color.WHITE);
b1.setBackground(Color.WHITE);
b2.setBackground(Color.WHITE);
b3.setBackground(Color.WHITE);
b4.setBackground(Color.WHITE);
b5.setBackground(Color.WHITE);
b6.setBackground(Color.RED);
b7.setBackground(Color.WHITE);
b8.setBackground(Color.WHITE);
b9.setBackground(Color.WHITE);
b10.setBackground(Color.WHITE);
b11.setBackground(Color.WHITE);
c1.setBackground(Color.WHITE);
c2.setBackground(Color.WHITE);
c3.setBackground(Color.WHITE);
c4.setBackground(Color.WHITE);
c5.setBackground(Color.WHITE);
c6.setBackground(Color.RED);
c7.setBackground(Color.WHITE);
c8.setBackground(Color.WHITE);
c9.setBackground(Color.WHITE);
c10.setBackground(Color.WHITE);
c11.setBackground(Color.WHITE);
d1.setBackground(Color.WHITE);
d2.setBackground(Color.WHITE);
d3.setBackground(Color.WHITE);
d4.setBackground(Color.WHITE);
d5.setBackground(Color.RED);
d6.setBackground(Color.RED);
d7.setBackground(Color.RED);
d8.setBackground(Color.WHITE);
d9.setBackground(Color.WHITE);
d10.setBackground(Color.WHITE);
d11.setBackground(Color.WHITE);
e1.setBackground(Color.WHITE);
e2.setBackground(Color.WHITE);
e3.setBackground(Color.WHITE);
e4.setBackground(Color.WHITE);
e5.setBackground(Color.RED);
e6.setBackground(Color.RED);
e7.setBackground(Color.RED);
e8.setBackground(Color.WHITE);
e9.setBackground(Color.WHITE);
e10.setBackground(Color.WHITE);
e11.setBackground(Color.WHITE);
f1.setBackground(Color.WHITE);
f2.setBackground(Color.WHITE);
f3.setBackground(Color.WHITE);
f4.setBackground(Color.RED);
f5.setBackground(Color.RED);
f6.setBackground(Color.RED);
f7.setBackground(Color.RED);
f8.setBackground(Color.RED);
f9.setBackground(Color.WHITE);
f10.setBackground(Color.WHITE);
f11.setBackground(Color.WHITE);
g1.setBackground(Color.WHITE);
g2.setBackground(Color.WHITE);
g3.setBackground(Color.WHITE);
g4.setBackground(Color.RED);
g5.setBackground(Color.RED);
g6.setBackground(Color.RED);
g7.setBackground(Color.RED);
g8.setBackground(Color.RED);
g9.setBackground(Color.WHITE);
g10.setBackground(Color.WHITE);
g11.setBackground(Color.WHITE);
h1.setBackground(Color.WHITE);
h2.setBackground(Color.WHITE);
h3.setBackground(Color.WHITE);
h4.setBackground(Color.WHITE);
h5.setBackground(Color.RED);
h6.setBackground(Color.RED);
h7.setBackground(Color.RED);
h8.setBackground(Color.WHITE);
h9.setBackground(Color.WHITE);
h10.setBackground(Color.WHITE);
h11.setBackground(Color.WHITE);
i1.setBackground(Color.WHITE);
i2.setBackground(Color.WHITE);
i3.setBackground(Color.WHITE);
i4.setBackground(Color.WHITE);
i5.setBackground(Color.WHITE);
i6.setBackground(Color.RED);
i7.setBackground(Color.WHITE);
i8.setBackground(Color.WHITE);
i9.setBackground(Color.WHITE);
i10.setBackground(Color.WHITE);
i11.setBackground(Color.WHITE);
j1.setBackground(Color.WHITE);
j2.setBackground(Color.WHITE);
j3.setBackground(Color.WHITE);
j4.setBackground(Color.WHITE);
j5.setBackground(Color.WHITE);
j6.setBackground(Color.RED);
j7.setBackground(Color.WHITE);
j8.setBackground(Color.WHITE);
j9.setBackground(Color.WHITE);
j10.setBackground(Color.WHITE);
j11.setBackground(Color.WHITE);
k1.setBackground(Color.WHITE);
k2.setBackground(Color.WHITE);
k3.setBackground(Color.WHITE);
k4.setBackground(Color.WHITE);
k5.setBackground(Color.WHITE);
k6.setBackground(Color.WHITE);
k7.setBackground(Color.WHITE);
k8.setBackground(Color.WHITE);
k9.setBackground(Color.WHITE);
k10.setBackground(Color.WHITE);
k11.setBackground(Color.WHITE);
}
public void paint(Graphics g)
{
diamond.setVisible(true);
a1.setVisible(true);
a2.setVisible(true);
a3.setVisible(true);
a4.setVisible(true);
a5.setVisible(true);
a6.setVisible(true);
a7.setVisible(true);
a8.setVisible(true);
a9.setVisible(true);
a10.setVisible(true);
a11.setVisible(true);
b1.setVisible(true);
b2.setVisible(true);
b3.setVisible(true);
b4.setVisible(true);
b5.setVisible(true);
b6.setVisible(true);
b7.setVisible(true);
b8.setVisible(true);
b9.setVisible(true);
b10.setVisible(true);
b11.setVisible(true);
c1.setVisible(true);
c2.setVisible(true);
c3.setVisible(true);
c4.setVisible(true);
c5.setVisible(true);
c6.setVisible(true);
c7.setVisible(true);
c8.setVisible(true);
c9.setVisible(true);
c10.setVisible(true);
c11.setVisible(true);
d1.setVisible(true);
d2.setVisible(true);
d3.setVisible(true);
d4.setVisible(true);
d5.setVisible(true);
d6.setVisible(true);
d7.setVisible(true);
d8.setVisible(true);
d9.setVisible(true);
d10.setVisible(true);
d11.setVisible(true);
e1.setVisible(true);
e2.setVisible(true);
e3.setVisible(true);
e4.setVisible(true);
e5.setVisible(true);
e6.setVisible(true);
e7.setVisible(true);
e8.setVisible(true);
e9.setVisible(true);
e10.setVisible(true);
e11.setVisible(true);
f1.setVisible(true);
f2.setVisible(true);
f3.setVisible(true);
f4.setVisible(true);
f5.setVisible(true);
f6.setVisible(true);
f7.setVisible(true);
f8.setVisible(true);
f9.setVisible(true);
f10.setVisible(true);
f11.setVisible(true);
g1.setVisible(true);
g2.setVisible(true);
g3.setVisible(true);
g4.setVisible(true);
g5.setVisible(true);
g6.setVisible(true);
g7.setVisible(true);
g8.setVisible(true);
g9.setVisible(true);
g10.setVisible(true);
g11.setVisible(true);
h1.setVisible(true);
h2.setVisible(true);
h3.setVisible(true);
h4.setVisible(true);
h5.setVisible(true);
h6.setVisible(true);
h7.setVisible(true);
h8.setVisible(true);
h9.setVisible(true);
h10.setVisible(true);
h11.setVisible(true);
i1.setVisible(true);
i2.setVisible(true);
i3.setVisible(true);
i4.setVisible(true);
i5.setVisible(true);
i6.setVisible(true);
i7.setVisible(true);
i8.setVisible(true);
i9.setVisible(true);
i10.setVisible(true);
i11.setVisible(true);
j1.setVisible(true);
j2.setVisible(true);
j3.setVisible(true);
j4.setVisible(true);
j5.setVisible(true);
j6.setVisible(true);
j7.setVisible(true);
j8.setVisible(true);
j9.setVisible(true);
j10.setVisible(true);
j11.setVisible(true);
k1.setVisible(true);
k2.setVisible(true);
k3.setVisible(true);
k4.setVisible(true);
k5.setVisible(true);
k6.setVisible(true);
k7.setVisible(true);
k8.setVisible(true);
k9.setVisible(true);
k10.setVisible(true);
k11.setVisible(true);
}
}
Here's my code for the testing class:
import java.awt.*;
import javax.swing.*;
import java.awt.Component;
public class DiamondTesting
{
public static void main(String[] args)
{
JFrame frm = new JFrame();
Diamond yes = new Diamond();
Diamond no = new Diamond();
frm.setLayout(new GridLayout(2,1));
yes.makeDiamond();
no.makeDiamond();
frm.add(yes);
frm.add(no);
no.repaint();
yes.repaint();
frm.setVisible(true);
}
}
I'm absolutely lost as to what my problem is, as this is my first dive into declaring my own Component class. Any help here?