public class Fan { public static void main(String args[]) { JFrame frame = new J
ID: 3610429 • 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 if i is 0 lines will go 1 way if i is 1 it will go the other, nowcode with i=1, message me if any questions by changing the value of i you can add as many positions for thefan as possible, the slider would set a delay for each repaint ofthe fan hope this helps 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.