package view; import java.awt.*; import java.awt.event.*; import javax.swing.*; /** * Contains a JPanel where the body parts are painted. */ public class HangmanFrame extends JFrame { IPaintAdapter _paintAdapter; // to do all the painting of the model. BorderLayout borderLayout1 = new BorderLayout(); JPanel displayPanel = new JPanel() { // IT'S BEST TO OVERRIDE paintComponent instead of paint(): public void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.black); g.fillRect(0,220,200,5); // base of scaffold g.fillRect(0,0,70,5); // top of scaffold g.fillRect(0,0,5,220); // side of scaffold if(_paintAdapter != null) { _paintAdapter.paint(g); } } }; public HangmanFrame() { jbInit(); } /**Component initialization*/ private void jbInit() { Container contentPane = getContentPane(); contentPane.setLayout(borderLayout1); setSize(400, 300); setLocation(100, 100); setTitle("Hangman Game"); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); displayPanel.setBackground(Color.white); contentPane.add(displayPanel, BorderLayout.CENTER); } /** * There is only the IPaintAdapter here in this simplified version. */ public void addAdapters(IPaintAdapter pa) { _paintAdapter = pa; } }