home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / WDESAMPL.BIN / ScrollTextSample.java < prev    next >
Text File  |  1998-02-26  |  7KB  |  223 lines

  1. /*  
  2.     A basic extension of the java.applet.Applet class
  3.  */
  4.  
  5. import java.awt.*;
  6. import java.applet.*;
  7.  
  8. import symantec.itools.awt.HorizontalSlider;
  9. import symantec.itools.multimedia.ScrollingText;
  10. import symantec.itools.awt.util.spinner.NumericSpinner;
  11. import symantec.itools.awt.DirectionButton;
  12. import symantec.itools.awt.util.spinner.*;
  13. import symantec.itools.multimedia.*;
  14. import symantec.itools.awt.*;
  15. public class ScrollTextSample extends Applet {
  16.     public void init() {
  17.         super.init();
  18.  
  19.         // Take out this line if you don't use symantec.itools.net.RelativeURL
  20.         // symantec.itools.lang.Context.setDocumentBase(getDocumentBase());
  21.  
  22.         //{{INIT_CONTROLS
  23.         setLayout(new CardLayout(0,0));
  24.         setSize(529,240);
  25.         setFont(new Font("Dialog", Font.PLAIN, 12));
  26.         setForeground(new Color(0));
  27.         setBackground(new Color(12632256));
  28.         panel1 = new java.awt.Panel();
  29.         GridBagLayout gridBagLayout;
  30.         gridBagLayout = new GridBagLayout();
  31.         panel1.setLayout(gridBagLayout);
  32.         panel1.setBounds(0,0,529,240);
  33.         add("CardName", panel1);
  34.         textLabel = new java.awt.Label("Scroll Text",Label.RIGHT);
  35.         textLabel.setBounds(138,13,70,23);
  36.         GridBagConstraints gbc;
  37.         gbc = new GridBagConstraints();
  38.         gbc.gridx = 0;
  39.         gbc.gridy = 0;
  40.         gbc.weightx = 1.0;
  41.         gbc.weighty = 1.0;
  42.         gbc.anchor = GridBagConstraints.EAST;
  43.         gbc.fill = GridBagConstraints.NONE;
  44.         gbc.insets = new Insets(0,0,0,0);
  45.         ((GridBagLayout)panel1.getLayout()).setConstraints(textLabel, gbc);
  46.         panel1.add(textLabel);
  47.         textText = new java.awt.TextField(30);
  48.         textText.setText("Visual Cafe from Symantec");
  49.         textText.setBounds(218,13,172,23);
  50.         gbc = new GridBagConstraints();
  51.         gbc.gridx = 1;
  52.         gbc.gridy = 0;
  53.         gbc.weightx = 1.0;
  54.         gbc.weighty = 1.0;
  55.         gbc.anchor = GridBagConstraints.WEST;
  56.         gbc.fill = GridBagConstraints.NONE;
  57.         gbc.insets = new Insets(0,10,0,0);
  58.         ((GridBagLayout)panel1.getLayout()).setConstraints(textText, gbc);
  59.         panel1.add(textText);
  60.         unitLabel = new java.awt.Label("Scroll Unit",Label.RIGHT);
  61.         unitLabel.setBounds(138,70,70,23);
  62.         gbc = new GridBagConstraints();
  63.         gbc.gridx = 0;
  64.         gbc.gridy = 1;
  65.         gbc.weightx = 1.0;
  66.         gbc.weighty = 1.0;
  67.         gbc.anchor = GridBagConstraints.EAST;
  68.         gbc.fill = GridBagConstraints.NONE;
  69.         gbc.insets = new Insets(0,0,0,0);
  70.         ((GridBagLayout)panel1.getLayout()).setConstraints(unitLabel, gbc);
  71.         panel1.add(unitLabel);
  72.         unitSlider = new symantec.itools.awt.HorizontalSlider();
  73.         try {
  74.             unitSlider.setValue(10);
  75.         }
  76.         catch(java.beans.PropertyVetoException e) { }
  77.         try {
  78.             unitSlider.setTickStyle(symantec.itools.awt.HorizontalSlider.TICK_TOP);
  79.         }
  80.         catch(java.beans.PropertyVetoException e) { }
  81.         unitSlider.setBounds(218,60,116,43);
  82.         gbc = new GridBagConstraints();
  83.         gbc.gridx = 1;
  84.         gbc.gridy = 1;
  85.         gbc.weightx = 1.0;
  86.         gbc.weighty = 1.0;
  87.         gbc.anchor = GridBagConstraints.WEST;
  88.         gbc.fill = GridBagConstraints.NONE;
  89.         gbc.insets = new Insets(0,10,0,0);
  90.         ((GridBagLayout)panel1.getLayout()).setConstraints(unitSlider, gbc);
  91.         panel1.add(unitSlider);
  92.         panel5 = new java.awt.Panel();
  93.         panel5.setLayout(new FlowLayout(FlowLayout.CENTER,5,5));
  94.         panel5.setBounds(166,127,196,33);
  95.         gbc = new GridBagConstraints();
  96.         gbc.gridx = 0;
  97.         gbc.gridy = 3;
  98.         gbc.gridwidth = 2;
  99.         gbc.weightx = 1.0;
  100.         gbc.weighty = 1.0;
  101.         gbc.fill = GridBagConstraints.NONE;
  102.         gbc.insets = new Insets(0,0,0,0);
  103.         ((GridBagLayout)panel1.getLayout()).setConstraints(panel5, gbc);
  104.         panel1.add(panel5);
  105.         leftLabel = new java.awt.Label("Scroll Left");
  106.         leftLabel.setBounds(5,5,68,23);
  107.         panel5.add(leftLabel);
  108.         leftButton = new symantec.itools.awt.DirectionButton();
  109.         leftButton.setBounds(78,10,13,13);
  110.         panel5.add(leftButton);
  111.         rightButton = new symantec.itools.awt.DirectionButton();
  112.         try {
  113.             rightButton.setDirection(symantec.itools.awt.DirectionButton.RIGHT);
  114.         }
  115.         catch(java.beans.PropertyVetoException e) { }
  116.         rightButton.setBounds(96,10,13,13);
  117.         panel5.add(rightButton);
  118.         rightLabel = new java.awt.Label("Scroll Right");
  119.         rightLabel.setBounds(114,5,77,23);
  120.         panel5.add(rightLabel);
  121.         scrollText = new symantec.itools.multimedia.ScrollingText();
  122.         try {
  123.             scrollText.setScrollInterval(151);
  124.         }
  125.         catch(java.beans.PropertyVetoException e) { }
  126.         try {
  127.             java.lang.String[] tempString = new java.lang.String[1];
  128.             tempString[0] = new java.lang.String("Visual Cafe from Symantec");
  129.             scrollText.setMessageList(tempString);
  130.         }
  131.         catch(java.beans.PropertyVetoException e) { }
  132.         scrollText.setBounds(90,184,348,43);
  133.         gbc = new GridBagConstraints();
  134.         gbc.gridx = 0;
  135.         gbc.gridy = 4;
  136.         gbc.gridwidth = 2;
  137.         gbc.weightx = 1.0;
  138.         gbc.weighty = 1.0;
  139.         gbc.fill = GridBagConstraints.NONE;
  140.         gbc.insets = new Insets(0,0,0,0);
  141.         ((GridBagLayout)panel1.getLayout()).setConstraints(scrollText, gbc);
  142.         panel1.add(scrollText);
  143.         ((CardLayout) getLayout()).show(this,"CardName");
  144.         //}}
  145.             
  146.         //{{REGISTER_LISTENERS
  147.         Action lAction = new Action();
  148.         rightButton.addActionListener(lAction);
  149.         leftButton.addActionListener(lAction);
  150.         unitSlider.addActionListener(lAction);
  151.         textText.addActionListener(lAction);
  152.         //}}
  153.     }
  154.  
  155.     //{{DECLARE_CONTROLS
  156.     java.awt.Panel panel1;
  157.     java.awt.Label textLabel;
  158.     java.awt.TextField textText;
  159.     java.awt.Label unitLabel;
  160.     symantec.itools.awt.HorizontalSlider unitSlider;
  161.     java.awt.Panel panel5;
  162.     java.awt.Label leftLabel;
  163.     symantec.itools.awt.DirectionButton leftButton;
  164.     symantec.itools.awt.DirectionButton rightButton;
  165.     java.awt.Label rightLabel;
  166.     symantec.itools.multimedia.ScrollingText scrollText;
  167.     //}}
  168.  
  169.     class Action implements java.awt.event.ActionListener
  170.     {
  171.         public void actionPerformed(java.awt.event.ActionEvent event)
  172.         {
  173.             Object object = event.getSource();
  174.             if (object == rightButton)
  175.                 rightButton_actionPerformed(event);
  176.             else if (object == leftButton)
  177.                 leftButton_actionPerformed(event);
  178.             else if (object == unitSlider)
  179.                 unitSlider_actionPerformed(event);
  180.             else if (object == textText)
  181.                 textText_EnterHit(event);
  182.         }
  183.     }
  184.  
  185.     void rightButton_actionPerformed(java.awt.event.ActionEvent event)
  186.     {
  187.         try {
  188.             // to do: place event handler code here.
  189.             if (scrollText != null)
  190.                 scrollText.setScrollDirection(scrollText.SCROLL_RIGHT);
  191.         } catch(Exception e) {}
  192.     }
  193.  
  194.     void leftButton_actionPerformed(java.awt.event.ActionEvent event)
  195.     {
  196.         try {
  197.             // to do: place event handler code here.
  198.             if (scrollText != null)
  199.                 scrollText.setScrollDirection(scrollText.SCROLL_LEFT);
  200.         } catch(Exception e) {}
  201.     }
  202.  
  203.     void unitSlider_actionPerformed(java.awt.event.ActionEvent event)
  204.     {
  205.         try {
  206.             // to do: place event handler code here.
  207.             if (scrollText != null)
  208.                 scrollText.setScrollUnit(unitSlider.getValue());
  209.         } catch(Exception e) {}
  210.     }
  211.  
  212.     void textText_EnterHit(java.awt.event.ActionEvent event)
  213.     {
  214.         try {
  215.             // to do: place event handler code here.
  216.             if (scrollText != null) {
  217.                 String [] str = {textText.getText()};
  218.                 scrollText.setMessageList(str);
  219.             }
  220.         } catch(Exception e) {}
  221.     }
  222. }
  223.