[webbeans-commits] Webbeans SVN: r2394 - in examples/trunk/se: number-guess and 13 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Fri Apr 10 19:03:06 EDT 2009


Author: peteroyle
Date: 2009-04-10 19:03:06 -0400 (Fri, 10 Apr 2009)
New Revision: 2394

Added:
   examples/trunk/se/number-guess/
   examples/trunk/se/number-guess/pom.xml
   examples/trunk/se/number-guess/src/
   examples/trunk/se/number-guess/src/etc/
   examples/trunk/se/number-guess/src/etc/header.txt
   examples/trunk/se/number-guess/src/main/
   examples/trunk/se/number-guess/src/main/java/
   examples/trunk/se/number-guess/src/main/java/org/
   examples/trunk/se/number-guess/src/main/java/org/jboss/
   examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/
   examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/
   examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/
   examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/
   examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/numberguess/
   examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/numberguess/Game.java
   examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/numberguess/Generator.java
   examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/numberguess/MaxNumber.java
   examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/numberguess/MessageGenerator.java
   examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/numberguess/NumberGuessFrame.java
   examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/numberguess/Random.java
   examples/trunk/se/number-guess/src/main/resources/
   examples/trunk/se/number-guess/src/main/resources/beans.xml
   examples/trunk/se/number-guess/src/main/resources/log4j.properties
   examples/trunk/se/number-guess/src/test/
   examples/trunk/se/number-guess/src/test/java/
Log:
WebBeans SE Number Guess Swing Example, initial import


Property changes on: examples/trunk/se/number-guess
___________________________________________________________________
Name: svn:ignore
   + nb-configuration.xml
nbactions.xml
target


Added: examples/trunk/se/number-guess/pom.xml
===================================================================
--- examples/trunk/se/number-guess/pom.xml	                        (rev 0)
+++ examples/trunk/se/number-guess/pom.xml	2009-04-10 23:03:06 UTC (rev 2394)
@@ -0,0 +1,107 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <parent>
+        <artifactId>parent</artifactId>
+        <groupId>org.jboss.webbeans</groupId>
+        <version>1.0.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>org.jboss.webbeans</groupId>
+    <artifactId>number-guess-se</artifactId>
+    <packaging>jar</packaging>
+    <name>Number Guess SE</name>
+    <url>http://maven.apache.org</url>
+
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>2.0.2</version>
+                <configuration>
+                    <source>1.5</source>
+                    <target>1.5</target>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>jalopy-maven-plugin</artifactId>
+                <version>1.0-alpha-1</version>
+                <!-- This wipes out UNDO in IDEs. Run manually instead.
+                <executions>
+                    <execution>
+                        <phase>compile</phase>
+                        <goals>
+                            <goal>format</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                -->
+            </plugin>
+            <plugin>
+                <groupId>com.google.code.maven-license-plugin</groupId>
+                <artifactId>maven-license-plugin</artifactId>
+                <version>1.4.0</version>
+                <configuration>
+                    <basedir>${basedir}</basedir>
+                    <header>${basedir}/src/etc/header.txt</header>
+                    <quiet>false</quiet>
+                    <failIfMissing>true</failIfMissing>
+                    <aggregate>false</aggregate>
+                    <encoding>UTF-8</encoding>
+                </configuration>
+                <executions>
+                    <execution>
+                        <phase>compile</phase>
+                        <goals>
+                            <goal>format</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+    <repositories>
+        <repository>
+            <id>repository.jboss.org</id>
+            <name>JBoss Repository</name>
+            <url>http://repository.jboss.org/maven2</url>
+            <releases>
+            </releases>
+            <snapshots>
+                <enabled>false</enabled>
+            </snapshots>
+        </repository>
+        <repository>
+            <id>snapshots.jboss.org</id>
+            <name>JBoss Snapshots Repository</name>
+            <url>http://snapshots.jboss.org/maven2</url>
+            <releases>
+                <enabled>false</enabled>
+            </releases>
+            <snapshots>
+                <updatePolicy>always</updatePolicy>
+            </snapshots>
+        </repository>
+        <repository>
+            <id>repository.codehaus.org</id>
+            <name>Codehaus Repository</name>
+            <url>http://repository.codehaus.org</url>
+        </repository>
+    </repositories>
+
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>3.8.1</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.jboss.webbeans</groupId>
+            <artifactId>se-module</artifactId>
+            <version>1.0.0-SNAPSHOT</version>
+            <scope>compile</scope>
+        </dependency>
+    </dependencies>
+</project>

Added: examples/trunk/se/number-guess/src/etc/header.txt
===================================================================
--- examples/trunk/se/number-guess/src/etc/header.txt	                        (rev 0)
+++ examples/trunk/se/number-guess/src/etc/header.txt	2009-04-10 23:03:06 UTC (rev 2394)
@@ -0,0 +1,14 @@
+JBoss, Home of Professional Open Source
+Copyright 2008, Red Hat Middleware LLC, and individual contributors
+by the @authors tag. See the copyright.txt in the distribution for a
+full listing of individual contributors.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+http://www.apache.org/licenses/LICENSE-2.0
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.


Property changes on: examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/numberguess
___________________________________________________________________
Name: svn:ignore
   + NumberGuessFrame_NB.form
NumberGuessFrame_NB.java


Added: examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/numberguess/Game.java
===================================================================
--- examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/numberguess/Game.java	                        (rev 0)
+++ examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/numberguess/Game.java	2009-04-10 23:03:06 UTC (rev 2394)
@@ -0,0 +1,141 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.example.numberguess;
+
+import java.io.Serializable;
+
+import javax.annotation.PostConstruct;
+import javax.context.ApplicationScoped;
+import javax.inject.Current;
+
+/**
+ * This class contains the pure logic of the Number Guess game.
+ * On initialization a random number will be selected. Multiple "guesses"
+ * as to what that number might be can be made using the 'check' method. The
+ * user wins if they can guess the selected number in the alloted amount of
+ * tries.
+ * 
+ * @author Peter Royle
+ */
+ at ApplicationScoped
+public class Game
+    implements Serializable
+{
+    public static final int MAX_NUM_GUESSES = 10;
+    
+    private Integer number;
+    private int guess = 0;
+    private int smallest = 0;
+    @MaxNumber private int maxNumber;
+    private int biggest;
+    private int remainingGuesses = MAX_NUM_GUESSES;
+    private boolean validNumberRange = true;
+
+    @Current Generator rndGenerator;
+
+    public Game()
+    {
+    }
+
+    public int getNumber()
+    {
+        return number;
+    }
+
+    public int getGuess()
+    {
+        return guess;
+    }
+
+    public void setGuess( int guess )
+    {
+        this.guess = guess;
+    }
+
+    public int getSmallest()
+    {
+        return smallest;
+    }
+
+    public int getBiggest()
+    {
+        return biggest;
+    }
+
+    public int getRemainingGuesses()
+    {
+        return remainingGuesses;
+    }
+
+    public boolean isValidNumberRange()
+    {
+        return validNumberRange;
+    }
+
+    public boolean isGameWon()
+    {
+        return guess == number;
+    }
+
+    public boolean isGameLost()
+    {
+        return guess != number && remainingGuesses <= 0;
+    }
+
+    public boolean check()
+    {
+        boolean result = false;
+
+        if ( checkNewNumberRangeIsValid() )
+        {
+            if ( guess > number )
+            {
+                biggest = guess - 1;
+            }
+
+            if ( guess < number )
+            {
+                smallest = guess + 1;
+            }
+
+            if ( guess == number )
+            {
+                result = true;
+            }
+
+            remainingGuesses--;
+        }
+
+        return result;
+    }
+
+    private boolean checkNewNumberRangeIsValid()
+    {
+        return validNumberRange = ( ( guess >= smallest ) && ( guess <= biggest ) );
+    }
+
+    @PostConstruct
+    public void reset()
+    {
+        this.smallest = 0;
+        this.guess = 0;
+        this.remainingGuesses = 10;
+        this.biggest = maxNumber;
+        this.number = rndGenerator.next();
+        System.out.println( "psst! the number is " + this.number );
+    }
+}

Added: examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/numberguess/Generator.java
===================================================================
--- examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/numberguess/Generator.java	                        (rev 0)
+++ examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/numberguess/Generator.java	2009-04-10 23:03:06 UTC (rev 2394)
@@ -0,0 +1,48 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.example.numberguess;
+
+import java.io.Serializable;
+
+import javax.context.ApplicationScoped;
+import javax.inject.Produces;
+
+ at ApplicationScoped
+public class Generator
+    implements Serializable
+{
+    private static final long serialVersionUID = -7213673465118041882L;
+    private java.util.Random random = new java.util.Random( System.currentTimeMillis() );
+    private int maxNumber = 100;
+
+    java.util.Random getRandom()
+    {
+        return random;
+    }
+
+    @Produces @Random
+    int next()
+    {
+        return getRandom().nextInt( maxNumber );
+    }
+
+    @Produces @MaxNumber
+    int getMaxNumber()
+    {
+        return maxNumber;
+    }
+}

Added: examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/numberguess/MaxNumber.java
===================================================================
--- examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/numberguess/MaxNumber.java	                        (rev 0)
+++ examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/numberguess/MaxNumber.java	2009-04-10 23:03:06 UTC (rev 2394)
@@ -0,0 +1,35 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.example.numberguess;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+import javax.inject.BindingType;
+ at Target( {TYPE, METHOD, PARAMETER, FIELD} )
+ at Retention( RUNTIME )
+ at Documented
+ at BindingType
+public @interface MaxNumber
+{
+}

Added: examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/numberguess/MessageGenerator.java
===================================================================
--- examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/numberguess/MessageGenerator.java	                        (rev 0)
+++ examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/numberguess/MessageGenerator.java	2009-04-10 23:03:06 UTC (rev 2394)
@@ -0,0 +1,70 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.example.numberguess;
+
+import javax.inject.Current;
+
+/**
+ * This class generates on demand appropriate messages depending on the current
+ * state of the injected instance of Game.
+ * @author Peter Royle
+ */
+public class MessageGenerator
+{
+    @Current Game game;
+
+    public String getChallengeMessage()
+    {
+        StringBuilder chalengeMsg = new StringBuilder( "I'm thinking of a number between " );
+        chalengeMsg.append( game.getSmallest() );
+        chalengeMsg.append( " and " );
+        chalengeMsg.append( game.getBiggest() );
+        chalengeMsg.append( ". Can you guess what it is?" );
+
+        return chalengeMsg.toString();
+    }
+
+    public String getResultMessage()
+    {
+        if ( game.isGameWon() )
+        {
+            return "You guess it! The number was " + game.getNumber();
+        } else if ( game.isGameLost() )
+        {
+            return "You are fail! The number was " + game.getNumber();
+        } else if ( ! game.isValidNumberRange() )
+        {
+            return "Invalid number range!";
+        } else if ( game.getRemainingGuesses() == Game.MAX_NUM_GUESSES )
+        {
+            return "What is your first guess?";
+        } else
+        {
+            String direction = null;
+
+            if ( game.getGuess() < game.getNumber() )
+            {
+                direction = "Higher";
+            } else
+            {
+                direction = "Lower";
+            }
+
+            return direction + "! You have " + game.getRemainingGuesses() + " guesses left.";
+        }
+    }
+}

Added: examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/numberguess/NumberGuessFrame.java
===================================================================
--- examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/numberguess/NumberGuessFrame.java	                        (rev 0)
+++ examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/numberguess/NumberGuessFrame.java	2009-04-10 23:03:06 UTC (rev 2394)
@@ -0,0 +1,195 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.example.numberguess;
+
+import java.awt.CardLayout;
+
+import javax.event.Observes;
+import javax.inject.Current;
+import javax.inject.manager.Deployed;
+import javax.inject.manager.Manager;
+
+/**
+ * Swing-based number guess example, main application frame.
+ * @author Peter Royle
+ */
+public class NumberGuessFrame
+    extends javax.swing.JFrame
+{
+    private @Current Game game;
+    private @Current MessageGenerator msgGenerator;
+
+    /** Creates new form NumberGuessFrame */
+    public NumberGuessFrame()
+    {
+    }
+
+    public void start( @Observes @Deployed Manager manager )
+    {
+        java.awt.EventQueue.invokeLater( new Runnable()
+            {
+                public void run()
+                {
+                    initComponents();
+                    setVisible( true );
+                }
+            } );
+    }
+
+    /** This method is called to initialize the form.
+     */
+    @SuppressWarnings( "unchecked" )
+    private void initComponents() {
+
+        borderPanel = new javax.swing.JPanel();
+        gamePanel = new javax.swing.JPanel();
+        inputsPanel = new javax.swing.JPanel();
+        buttonPanel = new javax.swing.JPanel();
+        guessButton = new javax.swing.JButton();
+        replayBtn = new javax.swing.JButton();
+        guessText = new javax.swing.JTextField();
+        remainingGuessesPanel = new javax.swing.JPanel();
+        guessremainLabel = new javax.swing.JLabel();
+        guessesLeftBar = new javax.swing.JProgressBar();
+        mainMsgPanel = new javax.swing.JPanel();
+        mainLabel = new javax.swing.JLabel();
+        messageLabel = new javax.swing.JLabel();
+
+        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+        getContentPane().setLayout(new java.awt.CardLayout());
+
+        borderPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10, 10, 10));
+        borderPanel.setLayout(new java.awt.CardLayout());
+
+        gamePanel.setLayout(new java.awt.BorderLayout(6, 6));
+
+        inputsPanel.setLayout(new java.awt.BorderLayout(8, 8));
+
+        buttonPanel.setLayout(new java.awt.CardLayout());
+
+        guessButton.setText("Guess");
+        guessButton.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                guessButtonActionPerformed(evt);
+            }
+        });
+        buttonPanel.add(guessButton, "card2");
+
+        replayBtn.setText("Replay!");
+        replayBtn.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                replayBtnActionPerformed(evt);
+            }
+        });
+        buttonPanel.add(replayBtn, "card3");
+
+        inputsPanel.add(buttonPanel, java.awt.BorderLayout.LINE_END);
+        inputsPanel.add(guessText, java.awt.BorderLayout.CENTER);
+
+        gamePanel.add(inputsPanel, java.awt.BorderLayout.CENTER);
+
+        remainingGuessesPanel.setLayout(new java.awt.BorderLayout(8, 8));
+
+        guessremainLabel.setText("Guesses remaining:  ");
+        remainingGuessesPanel.add(guessremainLabel, java.awt.BorderLayout.LINE_START);
+
+        guessesLeftBar.setMaximum(Game.MAX_NUM_GUESSES);
+        guessesLeftBar.setValue(Game.MAX_NUM_GUESSES);
+        guessesLeftBar.setPreferredSize(new java.awt.Dimension(10, 14));
+        remainingGuessesPanel.add(guessesLeftBar, java.awt.BorderLayout.CENTER);
+
+        gamePanel.add(remainingGuessesPanel, java.awt.BorderLayout.PAGE_END);
+
+        mainMsgPanel.setLayout(new java.awt.GridLayout(2, 1, 6, 6));
+
+        mainLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
+        mainLabel.setText(msgGenerator.getChallengeMessage());
+        mainMsgPanel.add(mainLabel);
+
+        messageLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
+        messageLabel.setText(msgGenerator.getResultMessage());
+        mainMsgPanel.add(messageLabel);
+
+        gamePanel.add(mainMsgPanel, java.awt.BorderLayout.PAGE_START);
+
+        borderPanel.add(gamePanel, "card2");
+
+        getContentPane().add(borderPanel, "card2");
+
+        pack();
+    }
+
+    private void guessButtonActionPerformed( java.awt.event.ActionEvent evt )
+    {
+        int guess = -1;
+
+        try
+        {
+           guess = Integer.parseInt(guessText.getText());
+        } catch (NumberFormatException nfe)
+        {
+           //noop
+        }
+
+        game.setGuess( guess );
+        game.check();
+        refreshUI();
+
+        if ( game.isGameWon() || game.isGameLost() )
+        {
+            switchButtons();
+        }
+    }
+
+    private void replayBtnActionPerformed( java.awt.event.ActionEvent evt )
+    {
+       game.reset();
+       refreshUI();
+       switchButtons();
+    }
+
+    private void switchButtons()
+    {
+        CardLayout buttonLyt = (CardLayout) buttonPanel.getLayout();
+        buttonLyt.next( buttonPanel );
+    }
+
+    private void refreshUI()
+    {
+        mainLabel.setText( msgGenerator.getChallengeMessage() );
+        messageLabel.setText( msgGenerator.getResultMessage() );
+        guessText.setText( "" );
+        guessesLeftBar.setValue( game.getRemainingGuesses() );
+        guessText.requestFocus();
+    }
+
+    // swing components
+    private javax.swing.JPanel borderPanel;
+    private javax.swing.JPanel buttonPanel;
+    private javax.swing.JPanel gamePanel;
+    private javax.swing.JButton guessButton;
+    private javax.swing.JTextField guessText;
+    private javax.swing.JProgressBar guessesLeftBar;
+    private javax.swing.JLabel guessremainLabel;
+    private javax.swing.JPanel inputsPanel;
+    private javax.swing.JLabel mainLabel;
+    private javax.swing.JPanel mainMsgPanel;
+    private javax.swing.JLabel messageLabel;
+    private javax.swing.JPanel remainingGuessesPanel;
+    private javax.swing.JButton replayBtn;
+
+}

Added: examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/numberguess/Random.java
===================================================================
--- examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/numberguess/Random.java	                        (rev 0)
+++ examples/trunk/se/number-guess/src/main/java/org/jboss/webbeans/environment/se/example/numberguess/Random.java	2009-04-10 23:03:06 UTC (rev 2394)
@@ -0,0 +1,35 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.example.numberguess;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+import javax.inject.BindingType;
+ at Target( {TYPE, METHOD, PARAMETER, FIELD} )
+ at Retention( RUNTIME )
+ at Documented
+ at BindingType
+public @interface Random
+{
+}

Added: examples/trunk/se/number-guess/src/main/resources/beans.xml
===================================================================
--- examples/trunk/se/number-guess/src/main/resources/beans.xml	                        (rev 0)
+++ examples/trunk/se/number-guess/src/main/resources/beans.xml	2009-04-10 23:03:06 UTC (rev 2394)
@@ -0,0 +1,19 @@
+<!--
+
+    JBoss, Home of Professional Open Source
+    Copyright 2008, Red Hat Middleware LLC, and individual contributors
+    by the @authors tag. See the copyright.txt in the distribution for a
+    full listing of individual contributors.
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+    http://www.apache.org/licenses/LICENSE-2.0
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+
+-->
+<beans></beans>

Added: examples/trunk/se/number-guess/src/main/resources/log4j.properties
===================================================================
--- examples/trunk/se/number-guess/src/main/resources/log4j.properties	                        (rev 0)
+++ examples/trunk/se/number-guess/src/main/resources/log4j.properties	2009-04-10 23:03:06 UTC (rev 2394)
@@ -0,0 +1,25 @@
+#
+# JBoss, Home of Professional Open Source
+# Copyright 2008, Red Hat Middleware LLC, and individual contributors
+# by the @authors tag. See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Set root logger level to DEBUG and its only appender to A1.
+log4j.rootLogger=WARN, A1
+
+# A1 is set to be a ConsoleAppender.
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+
+# A1 uses PatternLayout.
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n




More information about the weld-commits mailing list