Question: How would I put this into code? Override the paintComponent() method in JButton by adding this method to the Cell class as follows: @Override public
How would I put this into code? Override the paintComponent() method in JButton by adding this method to the Cell class as follows: @Override public void paintComponent(Graphics g) { //paint the basic button first super.paintComponent(g); int offset = 5; Graphics2D g2 = (Graphics2D) g; g2.setStroke(new BasicStroke(5)); // now paint 0 or X if required switch(content) { case NOUGHT: //Draw O g2.setColor(Color.RED); g2.drawOval(offset,offset, this.getWidth() - offset * 2, this.getHeight() - offset * 2); break; case CROSS: //Draw X g2.setColor(Color.BLACK); g2.drawLine(offset, offset, this.getWidth() - offset , this.getHeight() - offset ); g2.drawLine(this.getWidth() - offset, offset, offset, this.getHeight()- offset); break; } } If your code has errors, make sure you use the necessary import statements! This code uses the enhanced Graphics2D class, a subclass of Graphics provided with Java2D, to set the stroke thickness to more than one pixel
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
