/Users/petercappello/NetBeansProjects/56-2014/56-2014-1-Clique-OO/src/clique/Clique.java |
package clique;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
@author
public class Clique
{
private static final int IMAGE_SIZE = Node.IMAGE_SIZE;
private final Image image;
private final ImageIcon imageIcon;
private final JLabel jLabel;
private final JFrame jFrame;
private final int nNodes;
private final Node[] nodeArray;
Clique()
{
image = new BufferedImage( IMAGE_SIZE, IMAGE_SIZE, BufferedImage.TYPE_INT_ARGB );
imageIcon = new ImageIcon( image );
jLabel = new JLabel( imageIcon );
jFrame = new JFrame( "Clique" );
jFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
Container container = jFrame.getContentPane();
container.setLayout( new BorderLayout() );
container.add( jLabel, BorderLayout.CENTER );
jFrame.pack();
nNodes = getInt( "What is the size of the clique [3 - 30]?" );
Node.initialize( nNodes );
nodeArray = new Node[ nNodes ];
for (int nodeN = 0; nodeN < nNodes; nodeN++ )
{
nodeArray[ nodeN ] = new Node( nodeN );
}
}
private int getInt( String promptString )
{
String intString = JOptionPane.showInputDialog( promptString );
return Integer.parseInt( intString );
}
Paint the clique representation onto the Image.
private void paint()
{
Graphics graphics = image.getGraphics();
for ( Node node : nodeArray )
{
node.drawEdges( graphics, nodeArray );
}
for ( Node node : nodeArray )
{
node.draw( graphics );
}
}
@param args
public static void main(String[] args)
{
Clique clique = new Clique();
clique.paint();
clique.view();
}
private void view() { jFrame.setVisible( true ); }
}