public ControlPanel(DrawingPanel canvas) { // instance variable draw has been assigned to canvas this.draw = canvas; // adds new Button this.color = new JButton("Add Color"); // assigns a listener with the button this.color.addActionListener(new ColorButton()); // adds button to the JPanel this.add(this.color); // asigns currentColor to a new JPanel this.currentColor = new JPanel(); // adds currentColor to JPanel this.add(this.currentColor); // sets background to default color currentColor.setBackground(draw.getColor()); // adds a new Button this.circle = new JButton("Add Circle"); // asigns a listener to the button this.circle.addActionListener(new CircleButton()); // adds button to the panel this.add(this.circle); // adds new button this.square = new JButton("Add Square"); // asigns this button to a listener this.square.addActionListener(new SquareButton()); // adds button to the panel this.add(this.square); }
{ // Set the layout to the frame in order to show the panels, BorderLayout used. setLayout(new BorderLayout()); // program will stop running when "X" is pressed. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); // set the title for the program. this.setTitle("Financial Modeller - B00540772"); // add the two frames to the frame show that they will show in the correct areas. this.add(drawing, BorderLayout.NORTH); this.add(control, BorderLayout.SOUTH); // add the instructions panel into the frame. this.add(instructions, BorderLayout.CENTER); // set the size of the two panels. drawing.setPreferredSize(new Dimension(900, 350)); control.setPreferredSize(new Dimension(900, 250)); instructions.setPreferredSize(new Dimension(900, 80)); // set the background of the DrawingPanel to highlight the two different panels. drawing.setBackground(Color.WHITE); // call the line wrap method to improve the layout of the text area. instructions.setLineWrap(true); // insert the instructions for the user. instructions.append( "Please use the control panel to enter your financial" + " information. When the information has been entered press 'Start'" + " to run the simulation. The textual output will show each" + " input and output as it happens, and will give you a balance update." + " The graphical output will give you a representation of the changing" + " weekly balance, each second represents" + " one week. Please be aware that if the balance goes above £16000" + " or the duration goes above 52 weeks the graphical output will stop," + " if this happens you can continue to use the textual output." + " If you do not wish to use all of the threads please leave amount AND" + " frequency as '0' and that thread will not start."); // set visible and pack to ensure it will run correctly. pack(); setVisible(true); }