FanControl.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class FanControl extends JPanel{
private JButton btnStart = new JButton("Start");
private JButton btnStop = new JButton("Stop");
private JButton btnReverse = new JButton("Reverse");
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
public Fan fan = new Fan();
private JScrollBar jscbHort = new JScrollBar(JScrollBar.HORIZONTAL);
public FanControl(){
setLayout(new BorderLayout());
p1.setLayout(new GridLayout(1,3,0,0));
p1.add(btnStart);
p1.add(btnStop);
p1.add(btnReverse);
p2.setLayout(new GridLayout(1,1,0,0));
p2.add(jscbHort);
add(p1,BorderLayout.NORTH);
add(fan,BorderLayout.CENTER);
add(p2,BorderLayout.SOUTH);
btnStart.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
fan.start();
}
});
btnStop.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
fan.stop();
}
});
btnReverse.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
fan.reverse();
}
});
jscbHort.addAdjustmentListener(new AdjustmentListener(){
public void adjustmentValueChanged(AdjustmentEvent ae){
double value = jscbHort.getValue();
double maximumValue = jscbHort.getMaximum();
int delay = p2.getWidth() - (int)(value * p2.getWidth()/maximumValue);
delay = delay/10;
System.out.println(delay);
fan.setSpeed(delay);
}
});
}
}
import java.awt.*;
import java.awt.event.*;
public class FanControl extends JPanel{
private JButton btnStart = new JButton("Start");
private JButton btnStop = new JButton("Stop");
private JButton btnReverse = new JButton("Reverse");
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
public Fan fan = new Fan();
private JScrollBar jscbHort = new JScrollBar(JScrollBar.HORIZONTAL);
public FanControl(){
setLayout(new BorderLayout());
p1.setLayout(new GridLayout(1,3,0,0));
p1.add(btnStart);
p1.add(btnStop);
p1.add(btnReverse);
p2.setLayout(new GridLayout(1,1,0,0));
p2.add(jscbHort);
add(p1,BorderLayout.NORTH);
add(fan,BorderLayout.CENTER);
add(p2,BorderLayout.SOUTH);
btnStart.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
fan.start();
}
});
btnStop.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
fan.stop();
}
});
btnReverse.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
fan.reverse();
}
});
jscbHort.addAdjustmentListener(new AdjustmentListener(){
public void adjustmentValueChanged(AdjustmentEvent ae){
double value = jscbHort.getValue();
double maximumValue = jscbHort.getMaximum();
int delay = p2.getWidth() - (int)(value * p2.getWidth()/maximumValue);
delay = delay/10;
System.out.println(delay);
fan.setSpeed(delay);
}
});
}
}
FanControlApplet.java
import java.awt.*;
import javax.swing.*;
public class FanControlApplet extends JApplet{
FanControl fanControl = new FanControl();
public void init(){
add(fanControl);
}
public static void main(String []args){
JFrame frame = new JFrame("Fan Control");
FanControlApplet applet = new FanControlApplet();
applet.init();
frame.add(applet);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
import javax.swing.*;
public class FanControlApplet extends JApplet{
FanControl fanControl = new FanControl();
public void init(){
add(fanControl);
}
public static void main(String []args){
JFrame frame = new JFrame("Fan Control");
FanControlApplet applet = new FanControlApplet();
applet.init();
frame.add(applet);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}