KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > wingset > ProgressBarExample


1 /*
2  * $Id: ProgressBarExample.java,v 1.4 2005/05/19 13:59:55 neurolabs Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package wingset;
15
16 import org.wings.*;
17
18 import java.awt.event.ActionEvent JavaDoc;
19 import java.awt.event.ActionListener JavaDoc;
20
21 /**
22  * @author <a HREF="mailto:haaf@mercatis.de">Armin Haaf</a>
23  * @version $Revision: 1.4 $
24  */

25 public class ProgressBarExample extends WingSetPane {
26
27     public SComponent createExample() {
28         final SButton forward1Percent = new SButton("+1");
29         final SButton forward10Percent = new SButton("+10");
30         final SButton backward1Percent = new SButton("-1");
31         final SButton backward10Percent = new SButton("-10");
32
33         final SProgressBar progressBar = new SProgressBar(0, 100);
34
35         ActionListener JavaDoc al = new ActionListener JavaDoc() {
36             public void actionPerformed(ActionEvent JavaDoc e) {
37                 int valueChange = 0;
38                 if (e.getSource() == forward1Percent) {
39                     valueChange = 1;
40                 } else if (e.getSource() == forward10Percent) {
41                     valueChange = 10;
42                 } else if (e.getSource() == backward1Percent) {
43                     valueChange = -1;
44                 } else if (e.getSource() == backward10Percent) {
45                     valueChange = -10;
46                 } // end of if ()
47

48                 progressBar.setValue(progressBar.getValue() + valueChange);
49             }
50         };
51         forward1Percent.addActionListener(al);
52         forward10Percent.addActionListener(al);
53         backward1Percent.addActionListener(al);
54         backward10Percent.addActionListener(al);
55
56         progressBar.setUnfilledColor(java.awt.Color.gray);
57         progressBar.setFilledColor(java.awt.Color.red);
58         progressBar.setForeground(java.awt.Color.red);
59         progressBar.setBorderColor(java.awt.Color.black);
60         progressBar.setStringPainted(true);
61         progressBar.setPreferredSize(new SDimension(250,-1));
62         progressBar.setProgressBarDimension(new SDimension(250,12));
63
64         progressBar.setValue(20);
65
66         SContainer panel = new SPanel();
67
68         try {
69             java.net.URL JavaDoc templateURL = getSession().getServletContext().getResource("/templates/ProgressBarExample.thtml");
70             STemplateLayout layout = new STemplateLayout(templateURL);
71             panel.setLayout(layout);
72         } catch (Exception JavaDoc ex) {
73             ex.printStackTrace();
74         }
75
76         panel.add(progressBar, "ProgressBar");
77         panel.add(forward1Percent, "Forward1Percent");
78         panel.add(forward10Percent, "Forward10Percent");
79         panel.add(backward1Percent, "Backward1Percent");
80         panel.add(backward10Percent, "Backward10Percent");
81
82
83         return panel;
84     }
85
86
87 }
88
89
90
Popular Tags