View Single Post
  #3 (permalink)  
Old 03-26-2008, 12:51 AM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,022
hardwired is on a distinguished road
Code:
public class ShuffleBoard extends JFrame { // If Board is a model class and not part // of the componeent hierarchy. Board board = new Board("Shuffleboard"); BoardCanvas boardCanvas; ShuffleTest() { boardCanvas = new BoardCanvas(); this.add(boardCanvas); board.seLocation(100, 100); board.setResizable(false); board.setVisible(true); } } class Board { // This could be some kind of model class. // If so you may not need a reference to // it in the ShuffleBoard class. // If it is designed as part of the component // hierarchy see below. } class BoardCanvas extends JPanel { protected void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.black); for (Weight w : weights) { g.fillOval(200, 200, 50, 50); // g.drawString("Test", 100, 100); System.out.println("Bleh"); } } }
If Board is part of the component hierarchy:
Code:
public class ShuffleTest extends JFrame { Board board = new Board("Shuffleboard"); ShuffleTest() { this.add(board); board.seLocation(100, 100); board.setResizable(false); board.setVisible(true); } } class Board extends Some_JComponent { BoardCanvas boardCanvas; Board() { boardCanvas = new BoardCanvas(); this.add(boardCanvas); } }
Reply With Quote