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

public class Fan { public static void main(String args[]) { JFrame frame = new J

ID: 3610431 • Letter: P

Question

public class Fan {
public static void main(String args[]) {
    JFrame frame = new JFrame("Tick Slider");
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JSliderjSliderOne = new JSlider( JSlider.HORIZONTAL, 0, 3, 0);

   jSliderOne.setPaintLabels(true);

   Hashtable<Integer, JLabel> table = new Hashtable<Integer,JLabel>();
    table.put (0, new JLabel("off"));
    table.put (1, new JLabel("low"));
    table.put (2, new JLabel("medium"));
    table.put (3, new JLabel("high"));

   jSliderOne.setLabelTable (table);

   frame.add(jSliderOne, BorderLayout.NORTH);
    frame.setSize(500, 100);
    frame.setVisible(true);
   
   
    JFrame draw = new JFrame();
    draw.getContentPane().add(newdrawlineGUI());
   draw.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    draw.setSize(200,200);
    draw.setVisible(true);
   
   
}
public static class drawlineGUI extends JPanel
{
public void paint(Graphics g)
{
    g.drawLine(100,10,100,100);  //vertical
    
       g.drawLine(50,50,150,50);   //horizontal starting fromsame point
   }


}}

Explanation / Answer

please rate - thanks using an array you can create as many positions for the "fanblades" as you want. see positionh and positionv if use 1 column get 1 set of lines, if use other column get otherposition of blades, add more columns add more fan positions message me if needed hope this gets you started import java.util.*; import java.awt.*; import javax.swing.*; public class Fan { static int [][]positionv={{100,125},                     {10, 25},                          {100,75},                          {100,75},                         };    static int [][]positionh={{50,75},                     {50,25},                          {150,125},                          {50,75},                         };                       public static void main(String args[]) {     JFrame frame = new JFrame("Tick Slider");    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     JSlider jSliderOne = new JSlider(JSlider.HORIZONTAL, 0, 3, 0);     jSliderOne.setPaintLabels(true);     Hashtable table = newHashtable();     table.put (0, new JLabel("off"));     table.put (1, new JLabel("low"));     table.put (2, new JLabel("medium"));     table.put (3, new JLabel("high"));     jSliderOne.setLabelTable (table);     frame.add(jSliderOne, BorderLayout.NORTH);     frame.setSize(500, 100);     frame.setVisible(true);        JFrame draw = new JFrame();    draw.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     draw.setSize(200,200);     draw.getContentPane().add(newdrawlineGUI());     draw.setVisible(true);    } public static class drawlineGUI extends JPanel { public void paint(Graphics g) { int i=1;    g.drawLine(positionv[0][i],positionv[1][i],positionv[2][i],positionv[3][i]);  //vertical    g.drawLine(positionh[0][i],positionh[1][i],positionh[2][i],positionh[3][i]);  //horizontal starting from same point     } }}