import javax.swing.*; import java.awt.*; public class Drawing { private void buildUI(Container container) { container.setLayout( new BoxLayout(container, BoxLayout.PAGE_AXIS) ); CoordinateArea coordinateArea = new CoordinateArea(this); // see below container.add(coordinateArea); } private static void createAndShowGUI() { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("DrawThingsDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Drawing controller = new Drawing(); controller.buildUI(frame.getContentPane()); frame.pack(); frame.setVisible(true); } public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } } ); // end of invokeLater } // end of main @SuppressWarnings("serial") public static class CoordinateArea extends JComponent { //Point point = null; Drawing controller; Dimension preferredSize = new Dimension(800,675); // choose size!! Color gridColor; public CoordinateArea(Drawing controller) { this.controller = controller; //Add border of 10 pixels at L and bottom, and 4 pixels at the top and R. setBorder(BorderFactory.createMatteBorder(24,10,70,4,Color.RED)); setBackground(Color.BLACK); setOpaque(true); } // end of constructor public Dimension getPreferredSize() { return preferredSize; } public void paintComponent(Graphics g) { if (isOpaque()) { g.setColor(getBackground()); //Paint bg if we're opaque. g.fillRect(0, 0, getWidth(), getHeight()); } g.setColor(Color.GREEN); //Paint colour , even ...drawGrid(g, 20); below g.drawLine(78,200,400,538); //the numbers are in the order x_1,y_1,x_2,y_2 for the // x and y coords of the starting point (1) and end point (2) g.setColor(Color.ORANGE); g.fillRect(13, 423, 367, 107); // the numbers are in the same order, but this // time for the coords of the diagonal int [] xcoords, ycoords; xcoords = new int[10]; ycoords = new int[xcoords.length]; for (int i=0; i