Addcp paneladdcontrol borderlayoutnorth

This preview shows page 2 - 5 out of 9 pages.

control.add(cp);panel.add(control, BorderLayout.NORTH);dp.setLayout(new GridLayout());dp.setVisible(true);dp.setBorder(new CompoundBorder(new LineBorder(Color.BLACK),new EmptyBorder(0, 0, 20, 30)));dp.setBackground(Color.WHITE);panel.add(dp, BorderLayout.CENTER);panel.setVisible(true);panel.add(bottom, BorderLayout.SOUTH);add(panel, BorderLayout.PAGE_START);clear.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent ae) {if (clear == ae.getSource()) {itemsDrawn.clear();repaint();}}});undo.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {if (itemsDrawn.size() != 0) {itemsDrawn.remove(itemsDrawn.size() - 1);repaint();}}});}public static void main(String[] args) {
JFrame frame = new JFrame("Java 2D Drawing");frame.setSize(1000, 1000);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);final DrawingApplication drawingApplication = new DrawingApplication();frame.add(drawingApplication, BorderLayout.CENTER);frame.setVisible(true);frame.pack();frame.setLocationRelativeTo(null);}public void mousePressed(MouseEvent e) {throw new UnsupportedOperationException("Not supported yet.");}public void mouseDragged(MouseEvent e) {throw new UnsupportedOperationException("Not supported yet.");}public void mouseReleased(MouseEvent e) {throw new UnsupportedOperationException("Not supported yet.");}public class State {private final Color foreground;private final Color background;private final boolean gradient;private final boolean filled;private final boolean dashed;private final int lineWidth;private final int dashLength;public State(Color foreground, Color background, boolean gradient, boolean filled,boolean dashed, int lineWidth, int dashLength) {this.foreground = foreground;this.background = background;this.gradient = gradient;this.filled = filled;this.dashed = dashed;this.lineWidth = lineWidth;this.dashLength = dashLength;}public Color getForeground() {return foreground;}public Color getBackground() {return background;}public boolean isGradient() {return gradient;}public boolean isFilled() {return filled;}public boolean isDashed() {return dashed;}
public int getLineWidth() {return lineWidth;}public int getDashLength() {return dashLength;}}public class ControlPanel extends JPanel {public final JComboBox shapes;private final JButton foreground;private final JButton background;private final JCheckBox gradient, filled, dashed;private final JTextField lineWidth, dashLength;private final JLabel width, length;private JPanel panel;private drawPanel drawPanel;public ControlPanel(drawPanel pane) {shapes = new JComboBox<>(new String[]{"Rectangle", "Oval", "Line"});foreground = new JButton("1st Color");foreground.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent event) {color1 = JColorChooser.showDialog(null, "Pick your color", Color.BLACK);}});background = new JButton("2nd Color");background.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent event) {

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture