Results 1 to 4 of 4
  1. #1
    albi_87m is offline Member
    Join Date
    Apr 2009
    Posts
    8
    Rep Power
    0

    Question How to add two other parameters?

    In Listing 11.1, add two other parameters of the Alpha class—mode and phaseDelayDuration—to the panel of parameters.


    Java Code:
     
      1 package chapter11;
      2
      3 import java.awt.*;
      4 import java.awt.event.*;
      5 import javax.swing.*;
      6 import javax.media.j3d.*;
      7
      8 public class TestAlpha extends JApplet {
      9   public static void main(String s[]) {
     10     JFrame frame = new JFrame();
     11     frame.setTitle("Alpha");
     12     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     13     JApplet applet = new TestAlpha();
     14     applet.init();
     15     frame.getContentPane().add(applet);
     16     frame.pack();
     17     frame.setVisible(true);
     18   }
     19
     20   Alpha alpha = new Alpha();
     21   Plot plot;
     22   JTextField tfLoopCount;
     23   JTextField tfTriggerTime;
     24   JTextField tfAlphaAtZeroDuration;
     25   JTextField tfAlphaAtOneDuration;
     26   JTextField tfIncreasingAlphaDuration;
     27   JTextField tfDecreasingAlphaDuration;
     28   JTextField tfIncreasingAlphaRampDuration;
     29   JTextField tfDecreasingAlphaRampDuration;
     30
     31   public void init() {
     32     Container cp = this.getContentPane();
     33     cp.setLayout(new BorderLayout());
     34     plot = new Plot();
     35     cp.add(plot, BorderLayout.CENTER);
     36     JPanel p = new JPanel();
     37     p.setBorder(BorderFactory.createTitledBorder(
     38       "Alpha parameters"));
     39     cp.add(p, BorderLayout.SOUTH);
     40     p.setLayout(new GridLayout(5, 4, 10, 5));
     41     p.add(new JLabel("loopCount"));
     42     tfLoopCount = new JTextField("-1");
     43     p.add(tfLoopCount);
     44     p.add(new JLabel("triggerTime"));
     45     tfTriggerTime = new JTextField("0");
     46     p.add(tfTriggerTime);
     47     p.add(new JLabel("alphaAtZeroDuration"));
     48     tfAlphaAtZeroDuration = new JTextField("0");
     49     p.add(tfAlphaAtZeroDuration);
     50     p.add(new JLabel("alphaAtOneDuration"));
     51     tfAlphaAtOneDuration = new JTextField("0");
     52     p.add(tfAlphaAtOneDuration);
     53     p.add(new JLabel("increasingAlphaDuration"));
     54     tfIncreasingAlphaDuration = new JTextField("1000");
     55     p.add(tfIncreasingAlphaDuration);
     56     p.add(new JLabel("decreasingAlphaDuration"));
     57     tfDecreasingAlphaDuration = new JTextField("0");
     58     p.add(tfDecreasingAlphaDuration);
     59     p.add(new JLabel("increasingAlphaRampDuration"));
     60     tfIncreasingAlphaRampDuration = new JTextField("0");
     61     p.add(tfIncreasingAlphaRampDuration);
     62     p.add(new JLabel("decreasingAlphaRampDuration"));
     63     tfDecreasingAlphaRampDuration = new JTextField("0");
     64     p.add(tfDecreasingAlphaRampDuration);
     65     p.add(new JPanel());
     66     JButton button = new JButton("Plot");
     67     p.add(button);
     68     button.addActionListener(new ActionListener() {
     69       public void actionPerformed(ActionEvent ev) {
     70         setAlpha();
     71         repaint();
     72       }
     73     });
     74     p.add(new JPanel());
     75     button = new JButton("Reset");
     76     p.add(button);
     77     button.addActionListener(new ActionListener() {
     78       public void actionPerformed(ActionEvent ev) {
     79         tfLoopCount.setText("-1");
     80         tfTriggerTime.setText("0");
     81         tfAlphaAtZeroDuration.setText("0");
     82         tfAlphaAtOneDuration.setText("0");
     83         tfIncreasingAlphaDuration.setText("1000");
     84         tfDecreasingAlphaDuration.setText("0");
     85         tfIncreasingAlphaRampDuration.setText("0");
     86         tfDecreasingAlphaRampDuration.setText("0");
     87         setAlpha();
     88         repaint();
     89       }
     90     });
     91   }
     92
     93   void setAlpha() {
     94     alpha.setMode
     95       (Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE);
     96     int n = Integer.parseInt(tfLoopCount.getText());
     97     alpha.setLoopCount(n);
     98     n = Integer.parseInt(tfTriggerTime.getText());
     99     alpha.setTriggerTime(n);
    100     n = Integer.parseInt(tfAlphaAtZeroDuration.getText());
    101     alpha.setAlphaAtZeroDuration(n);
    102     n = Integer.parseInt(tfAlphaAtOneDuration.getText());
    103     alpha.setAlphaAtOneDuration(n);
    104     n = Integer.parseInt(tfIncreasingAlphaDuration.getText());
    105     alpha.setIncreasingAlphaDuration(n);
    106     n = Integer.parseInt(tfDecreasingAlphaDuration.getText());
    107     alpha.setDecreasingAlphaDuration(n);
    108     n = Integer.parseInt(tfIncreasingAlphaRampDuration.getText());
    109     alpha.setIncreasingAlphaRampDuration(n);
    110     n = Integer.parseInt(tfDecreasingAlphaRampDuration.getText());
    111     alpha.setDecreasingAlphaRampDuration(n);
    112   }
    113
    114   class Plot extends JPanel {
    115     public Plot() {
    116       this.setBackground(Color.white);
    117       this.setBorder(BorderFactory.createLoweredBevelBorder());
    118       this.setPreferredSize(new Dimension(800,200));
    119     }
    120
    121     public void paintComponent(Graphics g) {
    122       super.paintComponent(g);
    123       long start = alpha.getStartTime();
    124       int x1 = 0;
    125       int y1 = 150;
    126       int x2 = 0;
    127       int y2 = 0;
    128       for (int i = 1; i < 1000; i++) {
    129         x2 = i;
    130         y2 = 150-(int)(100*alpha.value(start+i*10));
    131         g.drawLine(x1, y1,x2, y2);
    132         x1 = x2;
    133         y1 = y2;
    134       }
    135     }
    136   }
    137 }

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    843
    Rep Power
    6

    Default

    Hi,
    can u please explain it clearly?
    Ramya:cool:

  3. #3
    albi_87m is offline Member
    Join Date
    Apr 2009
    Posts
    8
    Rep Power
    0

    Default

    A Java 3D Alpha object includes the following parameters:

    LoopCount: The number of pulses or periods. The value -1 indicates an unlimited number of loops.

    startTime: The absolute time for the initial reference point.

    triggerTime: The time in milliseconds from the startTime for activating the Alpha object.

    phaseDelayDuration: The time in milliseconds for the initial delay from the triggerTime.

    alphaAtZeroDuration: The time in milliseconds for the alpha value to stay at 0.0.

    alphaAtOneDuration: The time in milliseconds for the alpha value to stay at 1.0.

    increasingAlphaDuration: The time in milliseconds for the alpha value to increase from 0.0 to 1.0.

    decreasingAlphaDuration: The time in milliseconds for the alpha value to decrease from 1.0 to 0.0.

    increasingAlphaRampDuration: The time in milliseconds for the alpha value to accelerate during the increasing phase.

    decreasingAlphaRampDuration: The time in milliseconds for the alpha value to accelerate during the decreasing phase.

    The parameters increasingAlphaRampDuration and decreasingAlphaRampDuration define certain smoothing effects on the waveform. The value of increasingAlphaRampDuration specifies an interval of acceleration at the beginning of the increasing phase and an interval of deceleration at the end of the increasing phase. Similarly the value of decreasingAlphaRampDuration specifies an interval of deceleration and acceleration for the decreasing phase.

    The following constructors are available for Alpha objects:

    public Alpha()
    public Alpha(int loopCount, long increasingAlphaDuration)
    public Alpha(int loopCount, long triggerTime,
    long phaseDelayDuration, long
    increasingAlphaDuration, long increasingAlphaRampDuration,
    long alphaAtOneDuration)
    public Alpha(int loopCount, int mode, long triggerTime,
    long phaseDelayDuration, long
    increasingAlphaDuration, long increasingAlphaRampDuration,
    long alphaAtOneDuration, long
    decreaingAlphaDuration, long dereasingAlphaRampDuration,
    long alphaAtZeroDuration)


    The alpha values of an Alpha object can be retrieved with the value methods:

    public float value()
    public float value(long atTime)


    The first method gets the alpha value for the current time. The second method gets the value for the specified time.

    Listing 11.1 plots the waveform of an alpha object (Figure 11.2). Parameters of the alpha can be changed at runtime to show the their effects on the waveform.

    Figure 11.2 >> //i43.tinypic.com/vqgos6.jpg

    The values of an Alpha object are plotted in a panel. Eight parameters for the alpha object can be set through the JTextField objects in the lower panel of the frame. Initially the default parameters are set for the Alpha. The Plot button will redraw the curve using the given parameters. The Reset button resets all parameters to the default.

    The inner class Plot (line 114) extends JPanel and draws the waveform in its paint Component method (line 121). The points are plotted in 10-ms intervals. The method value(long atTime) of the Alpha object is used to obtain the alpha values (line 130).
    Last edited by albi_87m; 05-18-2009 at 01:58 PM. Reason: better explanation

  4. #4
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    843
    Rep Power
    6

Similar Threads

  1. NULL Value Of parameters
    By riders in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 03-14-2008, 03:29 PM
  2. Hiding parameters from URL
    By Saurabh321 in forum New To Java
    Replies: 0
    Last Post: 02-05-2008, 01:43 PM
  3. alphabetizing parameters
    By jjsaw5 in forum New To Java
    Replies: 2
    Last Post: 08-15-2007, 06:43 PM
  4. get parameters in jsp
    By cecily in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 08-05-2007, 05:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •