Questio Details: 1. Create an applet to draw a digit using the method fillRect o
ID: 3610085 • Letter: Q
Question
Questio Details: 1. Create an applet to draw a digit using the methodfillRect of theclass Graphics. For instance, if the input is 6,the applet will display the digit 6. 2. Modify the applet created above in #1 by adding eightradio buttons so the user can change the color of digitdrawn. Questio Details: 1. Create an applet to draw a digit using the methodfillRect of theclass Graphics. For instance, if the input is 6,the applet will display the digit 6. 2. Modify the applet created above in #1 by adding eightradio buttons so the user can change the color of digitdrawn.Explanation / Answer
please rate - thanks part 1 hope it's on time import java.awt.*; import java.applet.*; import java.awt.event.*; public class number extends Applet implements ActionListener {Label xlabel = new Label("number"); TextField xfield = new TextField(5); int num,draw=0; public void init() {add(xlabel); add(xfield); xfield.addActionListener(this); } public void actionPerformed(ActionEvente) {StringinputString; inputString=xfield.getText(); num=Integer.parseInt(inputString); draw=1; repaint(); } public void paint(Graphics g) { g.setColor(Color.red); if(draw==1) { switch(num) {case 8: g.fillRect(20,0,80,10); //top across g.fillRect(20,50,80,10); //middle across g.fillRect(20,100,80,10); //bottom across g.fillRect(20,10,10,50); //left top g.fillRect(90,10,10,50); //right top g.fillRect(20,50,10,50); //left bottom g.fillRect(90,50,10,50); //right bottom break; case 0: g.fillRect(20,0,80,10); //top across g.fillRect(20,100,80,10); //bottom across g.fillRect(20,10,10,50); //left top g.fillRect(90,10,10,50); //right top g.fillRect(20,50,10,50); //left bottom g.fillRect(90,50,10,50); //right bottom break; case 1: g.fillRect(90,10,10,50); //right top g.fillRect(90,50,10,50); //right bottom break; case 2: g.fillRect(20,0,80,10); //top across g.fillRect(20,50,80,10); //middle across g.fillRect(20,100,80,10); //bottomacross g.fillRect(90,10,10,50); //right top g.fillRect(20,50,10,50); //left bottom break; case 3: g.fillRect(20,0,80,10); //top across g.fillRect(20,50,80,10); //middle across g.fillRect(20,100,80,10); //bottom across g.fillRect(90,10,10,50); //right top g.fillRect(90,50,10,50); //right bottom break; case 4: g.fillRect(20,50,80,10); //middle across g.fillRect(90,10,10,50); //right top g.fillRect(90,50,10,50); //right bottom g.fillRect(20,10,10,50); //left top break; case 5: g.fillRect(20,0,80,10); //top across g.fillRect(20,50,80,10); //middle across g.fillRect(20,100,80,10); //bottom across g.fillRect(20,10,10,50); //left top g.fillRect(90,50,10,50); //right bottom break; case 6: g.fillRect(20,0,80,10); //top across g.fillRect(20,50,80,10); //middle across g.fillRect(20,100,80,10); //bottom across g.fillRect(20,10,10,50); //left top g.fillRect(20,50,10,50); //left bottom g.fillRect(90,50,10,50); //right bottom break; case 7: g.fillRect(20,0,80,10); //top across g.fillRect(90,10,10,50); //right top g.fillRect(90,50,10,50); //right bottom break; } } } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.