Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help me with these last 2 steps. //DrawPanel.java import javax.swing.*; import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import static com.sun.java.accessibility.util.AWTEventMonitor. addActionListener ; public class

Help me with these last 2 steps.

image text in transcribed

//DrawPanel.java

import javax.swing.*; import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import static com.sun.java.accessibility.util.AWTEventMonitor.addActionListener; public class DrawPanel implements Runnable { static int width = 250; static int height = 250; JFrame application; public void run() { application = new JFrame(); application.setLayout(new BorderLayout()); application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); application.add(new IDrawPanel(),BorderLayout.CENTER); application.setSize(width, height); application.setVisible(true); application.add(new JButton("Change"),BorderLayout.SOUTH); } public static void main(String[] args) { DrawPanel dp = new DrawPanel(); SwingUtilities.invokeLater(dp); } class IDrawPanel extends JPanel implements ComponentListener { int steps = 15; Color clr = new Color(63, 102, 192); int wid, hgt; IDrawPanel() { addComponentListener(this); } public void paint(Graphics gr) { int /*hgt, wid,*/ x1, y1, x2, y2,x3, y3, hst, vst; Graphics2D g2 = (Graphics2D)gr; g2.setColor(clr); //wid = getWidth();  //hgt = getHeight();  hst = wid/steps; vst = hgt/steps; if(0== hst || 0 == vst) { g2.fillRect(0,0,wid,hgt); return; } x1 = y1 = 0; x3 = wid - 1; y3 = hgt - 1; for (x2 = hst, y2=hgt-vst; //x2 and y2 are initiated here, new for me.  x2 wid && y2 >0; x2 += hst, y2 -=vst) { g2.drawLine(x1, y1, x2, y2); g2.drawLine(x2, y2, x3, y3); } //g2.drawLine(0,0,wid/2,hgt/2);   } @Override public void componentResized(ComponentEvent e) { wid = getWidth(); hgt = getHeight(); System.out.println("width" + wid + ", height:" +hgt); } @Override public void componentMoved(ComponentEvent e) { } @Override public void componentShown(ComponentEvent e) { } @Override public void componentHidden(ComponentEvent e) { } } } 
Make IDrawPanel an ActionListener. Use the button ActionEvent to set a flag to alternate between two drawings. Make IDrawPanel an ActionListener. Use the button ActionEvent to set a flag to alternate between two drawings

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

DB2 11 The Database For Big Data And Analytics

Authors: Cristian Molaro, Surekha Parekh, Terry Purcell, Julian Stuhler

1st Edition

ISBN: 1583473858, 978-1583473856

Students also viewed these Databases questions

Question

Can you think of four ways to end a letter effectively?

Answered: 1 week ago

Question

Outline the employee's role in the succession management process.

Answered: 1 week ago

Question

Where those not participating, encouraged to participate?

Answered: 1 week ago

Question

3. Who would the members be?

Answered: 1 week ago