Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions