importjavax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabe
ID: 3610304 • Letter: I
Question
importjavax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSlider;
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.setMajorTickSpacing(1);
jSliderOne.setLabelTable (table);
frame.add(jSliderOne, BorderLayout.NORTH);
frame.setSize(500, 100);
frame.setVisible(true);
}
}
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 use the slider to set the time delay between positionchanges. a loop that does nothing can be used for the delay,the faster the fan, the smaller the range of numbers the loopgoes 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 } }}Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.