Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.s

ID: 3610219 • Letter: I

Question

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.JOptionPane;
import java.awt.Graphics;
import javax.swing.JApplet;

public class NumberGraphics extends JApplet
{

int Number;

public void init()
{
String inputStr;

inputStr = JOptionPane. showInputDialog("Enter a number: ");
Number = Integer.parseInt(inputStr);
}

public void paint(Graphics g)
{

super.paint(g);

switch (Number)
{

case 1:
g.fillRect(60, 20, 100, 40);
break;

case 2:
g.fillRect(20, 20, 100, 40);
g.fillRect(80, 60, 40, 40);
g.fillRect(20, 80, 100, 40);
g.fillRect(20, 160, 100, 40);
break;

case 3:
g.fillRect(20, 20, 100, 40);
g.fillRect(80, 60, 40, 40);
g.fillRect(20, 80, 100, 40);
g.fillRect(20, 120, 40, 40);
g.fillRect(20, 160, 100, 40);
break;

case 4:
g.fillRect(20, 20, 40, 60);
g.fillRect(80, 20, 40, 60);
g.fillRect(20, 80, 100, 40);
g.fillRect(80, 120, 40, 60);
break;

case 5:
g.fillRect(20, 20, 100, 40);
g.fillRect(80, 140, 40, 40);
g.fillRect(20, 180, 100, 40);
break;

case 6:
g.fillRect(20, 20, 100, 40);
g.fillRect(20, 60, 40, 40);
g.fillRect(20, 100, 100, 40);
g.fillRect(20, 140, 40, 40);
g.fillRect(80, 140, 40, 40);
g.fillRect(20, 180, 100, 40);
break;

case 7:
g.fillRect(20, 20, 100, 40);
g.fillRect(80, 60, 40, 1800);
break;

case 8:
g.fillRect(20, 20, 100, 40);
g.fillRect(20, 60, 40, 40);
g.fillRect(80, 60, 40, 40);
g.fillRect(20, 100, 100, 40);
g.fillRect(20, 140, 40, 40);
g.fillRect(80, 140, 40, 40);
g.fillRect(20, 180, 100, 40);
break;

case 9:
g.fillRect(20, 20, 100, 40);
g.fillRect(20, 60, 40, 40);
g.fillRect(80, 60, 40, 40);
g.fillRect(20, 100, 100, 40);
g.fillRect(80, 140, 40, 180);
break;
case 0:
g.fillRect(20, 20, 100, 40);
g.fillRect(20, 60, 40, 160);
g.fillRect(80, 60, 40, 160);
g.fillRect(20, 120, 40, 40);
g.fillRect(20, 180, 100, 40);
break;

}
}
}

Explanation / Answer

please rate - thanks glad you made changes-- check your digits - your 5 is no good import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.event.*; import javax.swing.JOptionPane; import java.awt.Graphics; import javax.swing.JApplet; public class NumberGraphics extends JApplet implementsActionListener { int Number,colorcode=4; JRadioButton redButton   = new JRadioButton("red" ,true); JRadioButton blueButton    = newJRadioButton("blue"   , false); JRadioButton greenButton = new JRadioButton("green", false); JRadioButton blackButton    = newJRadioButton("black"   , false); JRadioButton yellowButton = new JRadioButton("yellow", false); JRadioButton grayButton    = newJRadioButton("gray"   , false); JRadioButton orangeButton = new JRadioButton("orange", false); JRadioButton cyanButton    = newJRadioButton("cyan"   , false); public void init() { String inputStr; JPanel radioPanel = new JPanel(); radioPanel.setLayout(new GridLayout(8, 1)); radioPanel.add(redButton); radioPanel.add(greenButton); radioPanel.add(blueButton); radioPanel.add(blackButton); radioPanel.add(orangeButton); radioPanel.add(grayButton); radioPanel.add(yellowButton); radioPanel.add(cyanButton); ButtonGroup group=new ButtonGroup(); group.add(redButton); group.add(greenButton); group.add(blueButton); group.add(blackButton); group.add(orangeButton); group.add(grayButton); group.add(yellowButton); group.add(cyanButton); radioPanel.setBorder(BorderFactory.createTitledBorder(           BorderFactory.createEtchedBorder(), "Color")); JPanel windowPanel=new JPanel(new BorderLayout(0,10)); windowPanel.add(radioPanel,BorderLayout.EAST);          add(windowPanel); redButton.addActionListener(this);           greenButton.addActionListener(this); blueButton.addActionListener(this); blackButton.addActionListener(this); orangeButton.addActionListener(this); grayButton.addActionListener(this); yellowButton.addActionListener(this); cyanButton.addActionListener(this);               inputStr = JOptionPane. showInputDialog("Enter a number: "); Number = Integer.parseInt(inputStr); } public void actionPerformed(ActionEvente)            {StringinputString;           if(redButton.isSelected())              colorcode=1;           elseif(greenButton.isSelected())                colorcode=2;           elseif(blueButton.isSelected())                colorcode=3;           elseif(blackButton.isSelected())                colorcode=4;            elseif(orangeButton.isSelected())                 colorcode=5;            elseif(grayButton.isSelected())                colorcode=6;            elseif(yellowButton.isSelected())                  colorcode=7;            elseif(cyanButton.isSelected())                  colorcode=8;                repaint();           } public void paint (Graphics g) { super.paint(g); switch(colorcode) {case 1: g.setColor(Color.red);          break; case 2: g.setColor(Color.green);          break; case 3: g.setColor(Color.blue);          break; case 4: g.setColor(Color.black);          break; case 5: g.setColor(Color.orange);          break; case 6: g.setColor(Color.gray);          break; case 7: g.setColor(Color.yellow);          break; case 8: g.setColor(Color.cyan);          break; }           switch (Number) { case 1: g.fillRect(60, 20, 100, 40); break; case 2: g.fillRect(20, 20, 100, 40); g.fillRect(80, 60, 40, 40); g.fillRect(20, 80, 100, 40); g.fillRect(20, 160, 100, 40); break; case 3: g.fillRect(20, 20, 100, 40); g.fillRect(80, 60, 40, 40); g.fillRect(20, 80, 100, 40); g.fillRect(20, 120, 40, 40); g.fillRect(20, 160, 100, 40); break; case 4: g.fillRect(20, 20, 40, 60); g.fillRect(80, 20, 40, 60); g.fillRect(20, 80, 100, 40); g.fillRect(80, 120, 40, 60); break; case 5: g.fillRect(20, 20, 100, 40); g.fillRect(80, 140, 40, 40); g.fillRect(20, 180, 100, 40); break; case 6: g.fillRect(20, 20, 100, 40); g.fillRect(20, 60, 40, 40); g.fillRect(20, 100, 100, 40); g.fillRect(20, 140, 40, 40); g.fillRect(80, 140, 40, 40); g.fillRect(20, 180, 100, 40); break; case 7: g.fillRect(20, 20, 100, 40); g.fillRect(80, 60, 40, 1800); break; case 8: g.fillRect(20, 20, 100, 40); g.fillRect(20, 60, 40, 40); g.fillRect(80, 60, 40, 40); g.fillRect(20, 100, 100, 40); g.fillRect(20, 140, 40, 40); g.fillRect(80, 140, 40, 40); g.fillRect(20, 180, 100, 40); break; case 9: g.fillRect(20, 20, 100, 40); g.fillRect(20, 60, 40, 40); g.fillRect(80, 60, 40, 40); g.fillRect(20, 100, 100, 40); g.fillRect(80, 140, 40, 180); break; case 0: g.fillRect(20, 20, 100, 40); g.fillRect(20, 60, 40, 160); g.fillRect(80, 60, 40, 160); g.fillRect(20, 120, 40, 40); g.fillRect(20, 180, 100, 40); break; } } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote