package applets; import java.applet.*; import java.awt.*; import java.awt.image.*; import java.io.*; import java.util.Date; import java.net.URL; import shout3d.core.*; import shout3d.*; public class FuncSlidersApp extends Shout3DApplet{ String s1 = "Change Intensity"; String s2 = "Red Component"; Scrollbar horizScroll1; Scrollbar horizScroll2; public void init(){ super.init() ; setLayout(new BorderLayout()); Panel buttonsPanel = new Panel() ; Label sLabel1 = new Label(s1); Label sLabel2 = new Label(s2); buttonsPanel.setLayout(new GridLayout(13, 1, 5, 5)) ; horizScroll1 = new Scrollbar( Scrollbar.HORIZONTAL, 50, 10 , 0, 100); horizScroll2 = new Scrollbar(Scrollbar.HORIZONTAL, 50, 10 , 0, 100); System.out.println( "Layout is " + getLayout() ) ; buttonsPanel.add(horizScroll1); buttonsPanel.add(sLabel1); buttonsPanel.add(horizScroll2); buttonsPanel.add(sLabel2); add( "East", buttonsPanel); } public void initShout3DPanel(){ panel = new FunctionSliders(this); } private boolean isScrollEvent(int eventID) { return(eventID == Event.SCROLL_LINE_UP || eventID == Event.SCROLL_LINE_DOWN || eventID == Event.SCROLL_PAGE_UP || eventID == Event.SCROLL_PAGE_DOWN || eventID == Event.SCROLL_ABSOLUTE); } public boolean handleEvent(Event event) { if (event.target == horizScroll1 && isScrollEvent(event.id)) { changeIntensity(horizScroll1.getValue()); return(true); } else if (event.target == horizScroll2 && isScrollEvent(event.id)) { changeRedComponent(horizScroll2.getValue()); return(true); } else return(super.handleEvent(event)); } public void changeIntensity(int lightIntensity){ DirectionalLight light_source; if ((light_source = (DirectionalLight) getNodeByName("Variable_Light") ) == null) throw new Shout3DException("could not find node Variable_Light"); if (light_source != null){ light_source.intensity.setValue((float)lightIntensity/(float)100.0); } } public void changeRedComponent(int redComponent){ Material object_material; if ((object_material = (Material) getNodeByName("Red_mat") ) == null) throw new Shout3DException("could not find node Variable_Light"); if (object_material != null){ object_material.diffuseColor.getValue()[0] = (float)redComponent/100.0f; object_material.diffuseColor.setValue (object_material.diffuseColor.getValue()); } } }