<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>Sharing Community - Java</title>
        <description>We don t talk the talk, we let our programs do the talking</description>
        <link>http://www.cppjj.com/forum/list.php?6</link>
        <lastBuildDate>Thu, 09 Sep 2010 07:05:13 -0600</lastBuildDate>
        <generator>Phorum 5.2.9a</generator>
        <item>
            <guid>http://www.cppjj.com/forum/read.php?6,75,75#msg-75</guid>
            <title>JavaOne + Develope (no replies)</title>
            <link>http://www.cppjj.com/forum/read.php?6,75,75#msg-75</link>
            <description><![CDATA[ JavaOne + Develope (September 19 - 23, 2010 San Francisco)<br />
<br />
<a href="http://www.oracle.com/us/javaonedevelop/063292.html" rel="nofollow" >Java Developer Conference</a>]]></description>
            <dc:creator>admin</dc:creator>
            <category>Java</category>
            <pubDate>Tue, 08 Jun 2010 02:07:45 -0600</pubDate>
        </item>
        <item>
            <guid>http://www.cppjj.com/forum/read.php?6,48,48#msg-48</guid>
            <title>Java Applet (no replies)</title>
            <link>http://www.cppjj.com/forum/read.php?6,48,48#msg-48</link>
            <description><![CDATA[ <pre class="bbcode">
<pre class="bbcode"></pre>
/* This program is to determine if a given 3 lengths can form a triangle or not<br />
	It's a Java Applet program where you can put it on a web simply by applying<br />
	the class in the same directory as your index.html and put this code on it<br />
	<APPLET CODE = "Your-.class file" WIDTH=300 HEIGHT=200></APPLET><br />
	<br />
	JApplet is very similar to GUI<br />
	<br />
*/	<br />
<br />
import java.awt.*;<br />
import java.awt.event.*;<br />
import javax.swing.*;<br />
<br />
/* Here instead of extends JFrame we would extends JApplet<br />
	Notice when we decleare in JApplet we don't put the " J "<br />
	Like we did in JFrame. Also we don't need the setSize,<br />
	setVisible, and setDefaultCloseOperation.<br />
	<br />
*/<br />
<br />
public class Triangle extends JApplet implements ActionListener<br />
{<br />
	private Panel panel;<br />
	private Panel panel2;<br />
	private Panel panel3;<br />
	private Label messageLabel;<br />
	private Label messageLabel2;<br />
	private Label messageLabel3;<br />
	private TextField text1;<br />
	private TextField text2;<br />
	private TextField text3;<br />
	private Button button;<br />
	private Button button1;<br />
	public static int SCROLLBARS_BOTH;<br />
<br />
	public void init()<br />
	{<br />
<br />
		setLayout(new GridLayout(2,3));<br />
		<br />
		messageLabel = new Label("a");<br />
		text1 = new TextField(10);<br />
		<br />
		messageLabel2 = new Label("b");<br />
		text2 = new TextField(10);<br />
		<br />
		messageLabel3 = new Label("c");<br />
		text3 = new TextField(10);<br />
		<br />
		messageLabel.setBackground(Color.yellow);<br />
		messageLabel.setForeground(Color.blue);<br />
		button = new Button("Clear");<br />
		button.addActionListener(this);<br />
		button.setActionCommand("Clear");<br />
		button1 = new Button("Finish");<br />
		button1.addActionListener(this);<br />
		button1.setActionCommand("Finish");<br />
		<br />
		panel = new Panel();<br />
		panel2 = new Panel();<br />
		panel3 = new Panel();<br />
		<br />
		panel.add(messageLabel);<br />
		panel2.add(messageLabel2);<br />
		panel3.add(messageLabel3);<br />
		<br />
		panel.add(text1);<br />
		panel2.add(text2);<br />
		panel3.add(text3);<br />
		<br />
		/* This sets a textarea, it will appear on the bottom right<br />
			We set the textarea editable to be false so user can not change the text area<br />
			<br />
		*/<br />
		<br />
		TextArea textarea = new TextArea("This program is to determine \nif the given 3 lengths\n" +<br />
													"can form a triangle or not" ,20, 30, SCROLLBARS_BOTH);<br />
		textarea.setEditable(false);<br />
		<br />
		add(panel);<br />
		add(panel2);<br />
		add(panel3);<br />
		add(button);<br />
		add(button1);<br />
		add(textarea);<br />
		<br />
	}<br />
	/* This creates two events for the buttons<br />
		One is for clear and the other even is for enter<br />
		When the user clicks on clear it will reset the text area<br />
		When the user clicks on enter it will tell them the answer<br />
		<br />
	*/<br />
	<br />
		public void actionPerformed(ActionEvent e)<br />
		{<br />
			String s = e.getActionCommand();<br />
			if(s.equals("Clear"))<br />
			{<br />
				text1.setText("");<br />
				text2.setText("");<br />
				text3.setText("");<br />
			}<br />
			if(s.equals("Finish"))<br />
			{<br />
<br />
					String L1, L2, L3;<br />
					double length1, length2, length3,sum,sum1;<br />
					double sum2;<br />
			/* We have a handling exception if the user enters nothing<br />
				it will catches the exception and does nothing<br />
				<br />
			*/<br />
					<br />
				try{<br />
						String title = "Triangle";<br />
						L1 = text1.getText();<br />
						L2 = text2.getText();<br />
						L3 = text3.getText();<br />
						length1 = Double.parseDouble(L1);<br />
						length2 = Double.parseDouble(L2);<br />
						length3 = Double.parseDouble(L3);<br />
						sum = length1 + length2;<br />
						sum1 = length1 + length3;<br />
						sum2 = length2 + length3;<br />
					 <br />
						if(sum&gt;length3)<br />
						{<br />
							if((sum1 &gt; length2) && (sum2 &gt; length1))<br />
							{<br />
							<br />
								JOptionPane.showMessageDialog(null,"yes those length can create a triangle");<br />
							}<br />
						}<br />
						else<br />
				<br />
						JOptionPane.showMessageDialog(null,"no, it is not possible to create a triangle with the given length");<br />
					}<br />
					catch(NumberFormatException ae)<br />
					{<br />
					}<br />
			}<br />
		<br />
	}<br />
}<br />
</pre>]]></description>
            <dc:creator>admin</dc:creator>
            <category>Java</category>
            <pubDate>Tue, 24 Feb 2009 14:25:12 -0700</pubDate>
        </item>
        <item>
            <guid>http://www.cppjj.com/forum/read.php?6,43,43#msg-43</guid>
            <title>Simple Recursion Program (no replies)</title>
            <link>http://www.cppjj.com/forum/read.php?6,43,43#msg-43</link>
            <description><![CDATA[ import java.util.*;<br />
<br />
public class RecurivePower<br />
{<br />
	public static void main(String[] args)<br />
	{<br />
		int x, n;<br />
		<br />
		Scanner key = new Scanner(System.in);<br />
		<br />
		System.out.println("Enter a number: ");<br />
		x = key.nextInt();<br />
		<br />
		System.out.println("Entere the power: ");<br />
		n = key.nextInt();<br />
		<br />
		System.out.println("The square root of " + x + " is " + rpower(x, n));// passing x and n <br />
		<br />
	}<br />
	<br />
	static int rpower(int y, int m)<br />
	{<br />
		if (m==0) return 1; // base case<br />
		else return y*rpower(y, m-1);//recursive case<br />
	}<br />
}<br />
<br />
<br />
output:<br />
<br />
Enter a number: <br />
2<br />
Entere the power: <br />
2<br />
The square root of 2 is 4]]></description>
            <dc:creator>jj</dc:creator>
            <category>Java</category>
            <pubDate>Fri, 06 Feb 2009 13:56:24 -0700</pubDate>
        </item>
        <item>
            <guid>http://www.cppjj.com/forum/read.php?6,42,42#msg-42</guid>
            <title>GUI Draw Program (no replies)</title>
            <link>http://www.cppjj.com/forum/read.php?6,42,42#msg-42</link>
            <description><![CDATA[ <pre class="bbcode">
// version 1 = version 0 + some drawing

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;
import javax.swing.border.BevelBorder;
/**
  *  The draw application.
  */
public class Draw extends JFrame {
   /**
     * The easel for this application.
     */
	  
	  public static void main(String[] args) { 
      Draw draw = new Draw() ; 
      draw.setSize(300,375) ; 
      draw.setLocation(500,500) ; 
      draw.setVisible(true) ;
		 
   }
   DrawPanel2 drawPanel ;
	
	
   public Draw() { 
      super("Draw") ; 
      // create menubar
		
		this.addWindowListener(new WindowAdapter()
		{
			public void windowclosing(WindowEvent e) 
			{
				System.exit(0);
			}
		});
		
		Container contentPane = this.getContentPane();
		
		contentPane.setLayout(new BorderLayout());
		
		drawPanel = new DrawPanel2();
		drawPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
		drawPanel.setBackground(Color.white);
		contentPane.add(drawPanel, BorderLayout.CENTER);
		
		JMenuBar menubar = new JMenuBar();
		this.setJMenuBar(menubar);
	
		JMenu filemenu = new JMenu("File");
		JMenu colormenu = new JMenu("Color");
		menubar.add(filemenu);
		menubar.add(colormenu);
		
		Action clear = new ClearAction();
		Action quit = new QuitAction();
		Action select = new SelectColorAction();

		
		filemenu.add(clear);
		filemenu.add(quit);
		colormenu.add(select);

		
      // create toolbar 
		JToolBar toolbar = new JToolBar();
		toolbar.add(clear);
		toolbar.add(select);
		toolbar.add(quit);
		contentPane.add(toolbar, BorderLayout.NORTH);
		
		JToolBar colors = new JToolBar();
		colors.setOrientation(SwingConstants.VERTICAL);
		contentPane.add(colors, BorderLayout.WEST);   

   }
    

	class ClearAction extends AbstractAction
	{
		public ClearAction()
	{
		super("Clear");
		}
		public void actionPerformed(ActionEvent e)
		{
			drawPanel.clear();
		}
	}

class QuitAction extends AbstractAction
{
	public QuitAction()
	{
		super("Quit");
	}
	public void actionPerformed(ActionEvent e)
	{
		int response = JOptionPane.showConfirmDialog(Draw.this, "Do you Really want to Quit?");
		
		if(response == JOptionPane.YES_OPTION)
			System.exit(0);
	}
}

	class ColorAction extends AbstractAction
	{
		Color color;
		
		public ColorAction(Color color)
		{
			this.color = color;
			putValue(Action.SMALL_ICON, new ColorIcon(color));

		}
		
		public void actionPerformed(ActionEvent e)
		{
			drawPanel.setColor(color);
		}
	}
	
	static class ColorIcon implements Icon {
    Color color;

    public ColorIcon(Color color) {
      this.color = color;
    }

    // These two methods specify the size of the icon
    public int getIconHeight() {
      return 16;
    }

    public int getIconWidth() {
      return 16;
    }

    // This method draws the icon
    public void paintIcon(Component c, Graphics g, int x, int y) {
      g.setColor(color);
      g.fillRect(x, y, 16, 16);
    }
  }
	class SelectColorAction extends AbstractAction
	{
		public SelectColorAction(){
		super("Select Color");
		}
		
		public void actionPerformed(ActionEvent e)
		{
			Color color = JColorChooser.showDialog(Draw.this, 
			"Select Drawing Color", drawPanel.getColor());
			if(color!=null)
			drawPanel.setColor(color);
		}
	}
}


//////////////////////////////////////////////////
/**
  *  The  drawing panel.
  */
class DrawPanel2 extends JPanel {
  public DrawPanel2() {
 
    setPreferredSize(new Dimension(450, 200));

   
    addMouseListener(new MouseAdapter() {
      public void mousePressed(MouseEvent e) {
        moveto(e.getX(), e.getY()); // Move to click position
        requestFocus(); // Take keyboard focus
      }
    });


    addMouseMotionListener(new MouseMotionAdapter() {
      public void mouseDragged(MouseEvent e) {
        lineto(e.getX(), e.getY()); 
      }
    });


  }
  protected int last_x, last_y;

  
  public void moveto(int x, int y) {
    last_x = x;
    last_y = y;
  }

  
  public void lineto(int x, int y) {
    Graphics g = getGraphics();
    g.setColor(color); 
    g.drawLine(last_x, last_y, x, y); 
    moveto(x, y);
  }

  
  public void clear() {
    repaint();
  }

  Color color = Color.black;

  public void setColor(Color color) {
    this.color = color;
  }

  public Color getColor() {
    return color;
  }

}
</pre>]]></description>
            <dc:creator>admin</dc:creator>
            <category>Java</category>
            <pubDate>Wed, 04 Feb 2009 13:50:04 -0700</pubDate>
        </item>
        <item>
            <guid>http://www.cppjj.com/forum/read.php?6,41,41#msg-41</guid>
            <title>simple program how to append files:)-D:)-D (no replies)</title>
            <link>http://www.cppjj.com/forum/read.php?6,41,41#msg-41</link>
            <description><![CDATA[ <pre class="bbcode">
//needed to create an empty text called bday.txt
//


import javax.swing.*;
import java.io.*;

public class Bday
{
	public static void main(String[] args)throws IOException
	{
		
		try
		{
				FileWriter fw = new FileWriter("bday.txt", true);
				PrintWriter pw = new PrintWriter(fw);
				
				String name = JOptionPane.showInputDialog("Enter the person's name");
				name = name.toLowerCase();
				
				pw.println(name);
				
				String bday = JOptionPane.showInputDialog("Enter the person's bday as 1311986");
				
				pw.println(bday);
				
				pw.close();
				
				
			
		}
		catch (NullPointerException e)
		{
		}
			
	}
}
</pre>]]></description>
            <dc:creator>admin</dc:creator>
            <category>Java</category>
            <pubDate>Wed, 04 Feb 2009 00:15:29 -0700</pubDate>
        </item>
        <item>
            <guid>http://www.cppjj.com/forum/read.php?6,39,39#msg-39</guid>
            <title>GUI simple color push buttons (1 reply)</title>
            <link>http://www.cppjj.com/forum/read.php?6,39,39#msg-39</link>
            <description><![CDATA[ <pre class="bbcode">
import javax.swing.* ; 
import java.awt.* ;
import java.awt.event.* ;

/**
 	A simple push button GUI
  */
public class PushButton 
          extends JComponent {

   /**
     *  The state of this PushButton.
     */ 
   private boolean state ; 

   /**
     *  The text associated with this PushButton.
     */
   private String text ; 

   /**
     *  Command string associated with this?
     */
   private String actionCommand ; 

   /**
     *  The ActionListeners associated with this PushButton
     */
   protected ActionListener listeners  ;

   /**
     *  Construct from text.
     */
   public PushButton(String txt) {
      this.text = txt ; 
      this.state = false ; 
      this.addMouseListener(new MouseAdapter() {
         public void mousePressed(MouseEvent e) {
            if (state) state = false ;
            else state = true ;
            repaint() ;
            /////////////////////// generate ActionEvent
            if (listeners != null)
               listeners.actionPerformed(
                  new ActionEvent(PushButton.this,
                                  e.getID() ,
                                  PushButton.this.getActionCommand())) ;
         }
      }) ;
   }

   /*** Set the action command. */
   public void setActionCommand(String ac) { 
      this.actionCommand = ac ; 
   }

   /*** Get the action command. */
   public String getActionCommand() { 
      return actionCommand ; 
   }

   /*** Add an action listener to this PushButton. */
   public void addActionListener(ActionListener l) {
      listeners = AWTEventMulticaster.add(listeners,l) ;
   }

   /*** Remove an action listener from this PushButton. */
   public void removeActionListener(ActionListener l) {
      listeners = AWTEventMulticaster.remove(listeners,l) ;
   }

   /*** Return the text on this PushButton. */
   public String getText() { 
      return this.text ; 
   }

   /*** Set the text on this PushButton. */
   public void setText(String txt) { 
      this.text = txt ; 
   }

   /**
     *  Inquire about the state of this PushButton.
     */
   public boolean getSelected() { 
      return this.state ; 
   }

   /** 
     * What dimension does the text have?
     */
   protected Dimension getTextBounds(Graphics g) { 
      g.setFont(this.getFont()) ; 
      FontMetrics fm = g.getFontMetrics(this.getFont()) ;
      int w = fm.stringWidth(this.text), 
          h = fm.getHeight() ;   
      return new Dimension(w,h) ; 
   }



   public Dimension getPreferredSize() {  // ?
      FontMetrics fm = getFontMetrics(getFont());
		return new Dimension(fm.stringWidth(text)+30, fm.getAscent() + fm.getDescent() + 30);
		   
   }

   public Dimension getMinimumSize() { // ?
      return this.getPreferredSize() ; 
   }

   public Dimension getMaximumSize() { // ?
      return this.getPreferredSize() ; 
   }



   /**
     *  Paint the PushButton, depending upon state.
     */
   public void paintComponent(Graphics g) {
      if (!state) paintUp(g) ; 
      else paintDown(g) ;
   }

   public void paintUp(Graphics g) {
      Dimension d = this.getSize() ;
		int width, height;
		int x,y;
      int w = d.width - 1 ;
      int h = d.height - 1 ;
		Font F = g.getFont();
		FontMetrics fm = g.getFontMetrics(F);
		width = fm.stringWidth("Color");
		height = fm.getAscent();
		
		x= getSize().width/2 - width/2;
		
		y = getSize().height / 2 + height / 2;
      g.setColor(Color.blue) ;
      g.drawLine(0,0,w-1,0) ;
      g.drawLine(0,1,0,h-1) ;
      g.setColor(Color.blue) ;
      g.drawLine(1,h-1,w-1,h-1) ;
      g.drawLine(w-1,1,w-1,h-2) ;
      g.setColor(Color.blue) ;
      g.drawLine(1,h,w,h) ;
      g.drawLine(w,1,w,h-1) ;  
      g.setColor(this.getForeground()) ;
		g.drawString(this.getText(), x, y);  
      g.dispose() ;
   }

   public void paintDown(Graphics g) {
      Dimension d = this.getSize() ;
      int w = d.width - 1 ;
      int h = d.height - 1 ;
		int width, height;
		int x,y;
		Font F = g.getFont();
		FontMetrics fm = g.getFontMetrics(F);
		width = fm.stringWidth("Red");
		height = fm.getAscent();
		
		x= getSize().width/2 - width/2;
		
		y = getSize().height / 2 + height / 2;
      g.setColor(this.getBackground()) ;  /// background color
      g.fillRect(0,0,w,h) ; 
      g.setColor(Color.white) ;
      g.drawLine(0,0,0,h-1) ;
      g.drawLine(1,0,w-1,0) ;
      g.setColor(Color.blue);
      g.drawLine(1,1,1,h-2) ;
      g.drawLine(1,1,w-2,1) ;
      g.setColor(Color.lightGray) ;
      g.drawLine(2,h-1,2,h-1) ;  // just one square
      g.drawLine(w-1,1,w-1,1) ;
      g.setColor(Color.white) ;
      g.drawLine(0,h,w,h) ;
      g.drawLine(w,0,w,h-1) ;
		g.drawString(this.getText(), x, y);
      g.dispose() ;
   }

   /**
     * Test stub, from command line. 
     */
   public static void main(String[] args) { 
      PBtest pbt = new PBtest() ; 
      pbt.setSize(300,375) ; 
      pbt.setLocation(500,500) ; 
      pbt.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE) ; 
      pbt.setVisible(true) ; 
   }


}  // end of PushButton class

/////////////////////////////////// test user 

/**
  *    Set up three PushButtons to control color of a panel.
  */
class PBtest extends JFrame 
            implements ActionListener {
      
   JPanel midpane ; 
   PushButton pb1, pb2, pb3 ; 

   public PBtest() { 
      super.setTitle("PushButton Test (R/G/B)") ; 
      midpane = new JPanel() ; 
      JToolBar toolbar = new JToolBar() ;
      pb1 = 
         new PushButton("Red") ; 
      ///// REMOVE later
      pb1.setPreferredSize(new Dimension(30,30)) ; 
      /////
      pb1.setActionCommand("red") ; 
      pb1.addActionListener(this) ; 
		pb1.setBackground(Color.red);
      pb1.setForeground(Color.red) ;
		pb1.setFont(new Font("Serif", Font.ITALIC, 40)); 
      pb2 = 
         new PushButton("Green") ;
      pb2.addActionListener(this) ; 
      pb2.setActionCommand("green") ;
		pb2.setBackground(Color.green);
      pb2.setForeground(Color.green) ;
		pb2.setFont(new Font("MONOSPACED", Font.PLAIN, 20)); 
      pb3 = 
         new PushButton("Blue") ;
      pb3.addActionListener(this) ; 
      pb3.setActionCommand("blue") ; 
      pb3.setBackground(Color.blue) ;
		pb3.setForeground(Color.blue);
		pb3.setFont(new Font("Serif", Font.BOLD, 10)); 
      toolbar.add(pb1) ; 
      toolbar.add(new JToolBar.Separator()) ;   
      toolbar.add(pb2) ; 
      toolbar.add(new JToolBar.Separator()) ;   
      toolbar.add(pb3) ; 
      this.getContentPane().setLayout(new BorderLayout()) ; 
      this.getContentPane().add(toolbar, BorderLayout.NORTH) ; 
      this.getContentPane().add(midpane, BorderLayout.CENTER) ; 
      this.setVisible(true) ; 
      this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE) ;
   }
   public void actionPerformed(ActionEvent a) {  
      int r = (pb1.getSelected() ? 255 : 0), 
          g = (pb2.getSelected() ? 255 : 0),
          b = (pb3.getSelected() ? 255 : 0) ;
      midpane.setBackground(new Color(r,g,b)) ; 
      midpane.repaint() ; 
   }

}
</pre>]]></description>
            <dc:creator>admin</dc:creator>
            <category>Java</category>
            <pubDate>Sat, 31 Jan 2009 00:12:01 -0700</pubDate>
        </item>
        <item>
            <guid>http://www.cppjj.com/forum/read.php?6,37,37#msg-37</guid>
            <title>&gt;:D&lt;How to convert ur java.class file into .exe file (no replies)</title>
            <link>http://www.cppjj.com/forum/read.php?6,37,37#msg-37</link>
            <description><![CDATA[ [<a href="http://www.syncedit.com/" rel="nofollow" >www.syncedit.com</a>]<br />
<br />
A free software JavaLauncher, it can convert your .class file into an application file where you can use it on other computers.]]></description>
            <dc:creator>admin</dc:creator>
            <category>Java</category>
            <pubDate>Sun, 25 Jan 2009 16:47:15 -0700</pubDate>
        </item>
        <item>
            <guid>http://www.cppjj.com/forum/read.php?6,36,36#msg-36</guid>
            <title>Guess Random number game java (no replies)</title>
            <link>http://www.cppjj.com/forum/read.php?6,36,36#msg-36</link>
            <description><![CDATA[ <pre class="bbcode">
import java.util.Scanner;
import javax.swing.JOptionPane;
import java.util.Random;

public class RadnomNumber
{
	public static void main(String[] args)
	{
		int n = 0;
		int guess;
		Scanner key = new Scanner(System.in);
		Random randomNumbers = new Random();
		
		int secret = randomNumbers.nextInt(100);
		
		JOptionPane.showMessageDialog(null, "A secret number between 1-100 generated...");
		
		
		do
		{
			String input = JOptionPane.showInputDialog("Enter your guess? ");
			guess = Integer.parseInt(input);
			
			if (secret == guess)
			{
				JOptionPane.showMessageDialog(null,"Correct in " + n + 1 + " guessess.\n");
				break;
			}
			else if (guess == 0)
			{
				JOptionPane.showMessageDialog(null, "The secret number is " + secret +".\n");
			}
			else if(secret &lt; guess)
			{
				JOptionPane.showMessageDialog(null,"Guess is too high...");
			}
			else if(secret &gt; guess)
			{
				JOptionPane.showMessageDialog(null,"Guess is too low...");
			}
			
				n++;
			}while((n&lt;8) && (guess!=0));
			if(n==8)
			{
					JOptionPane.showMessageDialog(null,"Too many guesses, the secret number is " + secret);
			}
		}
	}
</pre>]]></description>
            <dc:creator>admin</dc:creator>
            <category>Java</category>
            <pubDate>Fri, 23 Jan 2009 16:41:32 -0700</pubDate>
        </item>
        <item>
            <guid>http://www.cppjj.com/forum/read.php?6,31,31#msg-31</guid>
            <title>Simple GUI (1 reply)</title>
            <link>http://www.cppjj.com/forum/read.php?6,31,31#msg-31</link>
            <description><![CDATA[ // The purpose of this program is to have people to compete with friends<br />
// see how fast they can do multiplication, and addition<br />
//<br />
<br />
import javax.swing.*;<br />
import java.awt.*;<br />
import java.awt.event.*;<br />
import java.util.Date;<br />
import java.util.Random;<br />
import java.io.*;<br />
<br />
//Creates  a window<br />
//<br />
<br />
public class Calculator extends JFrame<br />
{<br />
	private final int WINDOW_WIDTH = 800;<br />
	private final int WINDOW_HEIGHT = 400;<br />
	private JPanel panel;<br />
	private JLabel messagelabel;<br />
	private JTextField TextFile;<br />
	<br />
	//This is the function for multiplication<br />
	//If the user clicks on multiplication<br />
	//This function will be activated<br />
	//<br />
	public void Multiplication()<br />
	{<br />
		Date d1 = new Date();//needed to keep track of time<br />
		int x, y, sum;<br />
		int n = 0;<br />
		int userAnswer;<br />
		String input;<br />
		<br />
		Random randomNumbers = new Random();//declares randomNumbers as random<br />
		<br />
		x = randomNumbers.nextInt(9);//x holds random number between 0 and 9<br />
		y = randomNumbers.nextInt(9);//y holds random number between 0 and 9<br />
		<br />
		//A forloop that will terminated after 30 seconds<br />
		//JOptionPane is used here to interact with the user<br />
		//It will show the user what are they trying to add<br />
		//It asks the user to enter an answer<br />
		//Then shows them another equation after they've entered the answer<br />
		//<br />
		<br />
			for (int seconds = 0; seconds &lt;= 30; seconds++)<br />
			{<br />
				x = randomNumbers.nextInt(9);<br />
				y = randomNumbers.nextInt(9);<br />
					<br />
				input = JOptionPane.showInputDialog(x + "x" + y + "=");<br />
					<br />
				sum = x * y;<br />
					<br />
				userAnswer = Integer.parseInt(input);//Turn the user input into an integer<br />
				<br />
				//Determines if the user's answer is correct or not<br />
				//If the user's answer is correct we increment n<br />
				//If the user's answer is incorrect we decrement n<br />
				//<br />
					<br />
				if ( userAnswer == sum)<br />
				{<br />
					n++;<br />
				}<br />
				<br />
				else<br />
				{<br />
					n--;<br />
				}<br />
				<br />
			}<br />
		//keep tracks of time<br />
		//	<br />
		Date d2 = new Date();<br />
		long elapsed_time = d2.getTime() - d1.getTime();<br />
	<br />
		//Determines if the user beat the high score or not<br />
		//<br />
		<br />
		if ( n &gt;= 28 && elapsed_time &lt; 40000)<br />
		{<br />
			JOptionPane.showMessageDialog(null, "Good job you beat the high score");<br />
		}<br />
		else<br />
		{<br />
			JOptionPane.showMessageDialog(null, "you did not beat the high score & your score is " + n + "& time is " + elapsed_time);<br />
		}<br />
		<br />
	<br />
		System.exit(0);<br />
	}<br />
	<br />
	//This is the addition method<br />
	//This method will be call if the user click on addition<br />
	//All the fuction is the same as the multiplication<br />
	//So you can go back and look at the multiplication<br />
	//<br />
	public void Addition()<br />
	{<br />
		Date d1 = new Date();<br />
		int x, y, sum;<br />
		int n = 0;<br />
		int userAnswer;<br />
		String input;<br />
		<br />
		Random randomNumbers = new Random();<br />
		<br />
		x = randomNumbers.nextInt(20);<br />
		y = randomNumbers.nextInt(20);<br />
		<br />
			for (int seconds = 0; seconds &lt;= 30; seconds++)<br />
			{<br />
				x = randomNumbers.nextInt(20);<br />
				y = randomNumbers.nextInt(20);<br />
					<br />
				input = JOptionPane.showInputDialog(x +"+" + y + "=");<br />
					<br />
				sum = x + y;<br />
					<br />
				userAnswer = Integer.parseInt(input);<br />
					<br />
				if ( userAnswer == sum)<br />
				{<br />
					n++;<br />
				}<br />
				<br />
				else<br />
				{<br />
					n--;<br />
				}<br />
				<br />
			}<br />
			<br />
		Date d2 = new Date();<br />
		long elapsed_time = d2.getTime() - d1.getTime();<br />
	<br />
	<br />
		if ( n &gt;= 28 && elapsed_time &lt; 40000)<br />
		{<br />
			JOptionPane.showMessageDialog(null, "Good job you beat JJ's high score");<br />
		}<br />
		else<br />
		{<br />
			JOptionPane.showMessageDialog(null, "you did not beat the high score & your score is " + n + "& time is " + elapsed_time);<br />
		}<br />
		<br />
	<br />
		System.exit(0);<br />
	}<br />
	<br />
	//This is the calculator panel<br />
	//We will add this to the window<br />
	//<br />
<br />
	public Calculator() <br />
	{<br />
		<br />
		setTitle("JJ's Math Game");//Sets the title for the window<br />
		<br />
		setSize(WINDOW_WIDTH, WINDOW_HEIGHT);//Sets the size of the window<br />
		<br />
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//Determines what will happen if the user click on X<br />
		setLayout(new GridLayout(1,1));//The layout of the window<br />
		<br />
		JButton button1 = new JButton ("Multiplication");//Creates button1<br />
																		//It will be display as Multiplication<br />
																		<br />
		JButton button2 = new JButton("Addition");//Creates button2<br />
																//It will be display as Addition<br />
																<br />
	<br />
		button1.addActionListener(new Button1Listener());//Adds button1 so when user click something will happen<br />
		button2.addActionListener(new Button2Listener());//Adds button2 so when user click something will happen<br />
		<br />
		add(button1);//Adds button1 to the window<br />
		add(button2);//Adds button2 to the window<br />
			<br />
		setVisible(true);//Set the Window visible<br />
	}<br />
	<br />
	//This is the implementation for Multiplication<br />
	//It determines what will happen if the user click on something<br />
	//<br />
	<br />
   class Button1Listener implements ActionListener<br />
	{<br />
		public void actionPerformed(ActionEvent e)<br />
		{<br />
			String actionCommand = e.getActionCommand();//e.getActionCommand is a built in fuction from java<br />
									<br />
												<br />
			//If the user clicks on Multiplication<br />
			//The method Multiplication will be call<br />
			//Then it will be display<br />
			//<br />
			if (actionCommand.equals("Multiplication"))<br />
			{<br />
				Multiplication();<br />
			}<br />
			<br />
		}<br />
	}<br />
	<br />
	//This is the implementation for Addition<br />
	//It determines what will happen if the user click on something<br />
	//<br />
	<br />
	public class Button2Listener implements ActionListener<br />
	{<br />
		public void actionPerformed(ActionEvent e)<br />
		{<br />
			String actionCommand1 = e.getActionCommand();<br />
			<br />
			//If the user clicks on Addition<br />
			//The method Addition will be call<br />
			//Then it will be display<br />
			//<br />
			if (actionCommand1.equals("Addition"))<br />
			{<br />
				Addition();<br />
			}<br />
		}<br />
	}<br />
	<br />
	//This is the main method<br />
	//<br />
	public static void main(String[] args)<br />
	{<br />
	<br />
			new Calculator();//Instant window for Calculator<br />
	}<br />
}]]></description>
            <dc:creator>admin</dc:creator>
            <category>Java</category>
            <pubDate>Mon, 12 Jan 2009 10:46:32 -0700</pubDate>
        </item>
        <item>
            <guid>http://www.cppjj.com/forum/read.php?6,28,28#msg-28</guid>
            <title>generates Random name (2 replies)</title>
            <link>http://www.cppjj.com/forum/read.php?6,28,28#msg-28</link>
            <description><![CDATA[ //The goal of this program is to generate random Strings<br />
<br />
import java.util.Scanner;<br />
import java.io.*;<br />
import java.util.Random;<br />
<br />
public class RandomName<br />
{<br />
	public static void main(String[] args) throws IOException<br />
	{<br />
<br />
		Scanner key = new Scanner(System.in);<br />
		Random randomNumbers = new Random();<br />
		<br />
		int n = 0;<br />
		String[] names= new String[50];<br />
		int index = 0;<br />
		<br />
		// Asking user to enter a name of a file to read<br />
		//<br />
		<br />
		System.out.println("Enter a file name: ");<br />
		String fileName = key.nextLine();<br />
		<br />
		//Opens the file from user<br />
		//<br />
		<br />
		File file = new File(fileName);<br />
		Scanner outputFile = new Scanner(file);<br />
<br />
		while(outputFile.hasNext())<br />
		{<br />
			names[index] = outputFile.nextLine();<br />
			<br />
			index++;<br />
			<br />
			n++;<br />
		}<br />
		<br />
		// opens a file from user to read<br />
		//<br />
		<br />
		System.out.println("Enter a file to write in: ");<br />
		String writeFile = key.nextLine();<br />
		<br />
		FileWriter fwriter = new FileWriter(writeFile, true);<br />
		PrintWriter pw = new PrintWriter (fwriter);<br />
		<br />
		//prints out the number of people in the file<br />
		//Store into an array<br />
		//prints out a random name from the file<br />
		<br />
		System.out.println("Number of people: " + n );<br />
		int x = randomNumbers.nextInt(50);<br />
		<br />
		System.out.println("\n" + names[x]);<br />
		pw.println(names[x]);<br />
		<br />
		System.out.println("what do you want to do ");<br />
		String command = key.nextLine();<br />
		<br />
		//contine to loop the program<br />
		//Write to the file<br />
		//<br />
		<br />
		while(!command.equals("exit"))<br />
		{<br />
			x = randomNumbers.nextInt(35);<br />
			System.out.println("\n" + names[x]);<br />
			System.out.println("what do you want to do: ");<br />
			command = key.nextLine();<br />
			pw.println(names[x]);<br />
		}<br />
		<br />
		pw.close();<br />
		outputFile.close();<br />
		<br />
		//Exit the program if user enter exit<br />
		//<br />
		<br />
		if(command.equals("exit"))<br />
		{<br />
			System.exit(0);<br />
		}<br />
	}<br />
		<br />
}]]></description>
            <dc:creator>admin</dc:creator>
            <category>Java</category>
            <pubDate>Sun, 21 Mar 2010 00:45:40 -0600</pubDate>
        </item>
        <item>
            <guid>http://www.cppjj.com/forum/read.php?6,19,19#msg-19</guid>
            <title>Multiplication Game (no replies)</title>
            <link>http://www.cppjj.com/forum/read.php?6,19,19#msg-19</link>
            <description><![CDATA[ import javax.swing.JOptionPane;<br />
import java.util.Date;<br />
import java.util.Random;<br />
<br />
public class RandomGame<br />
{<br />
	public static void main(String[] args)<br />
	{<br />
		random();<br />
	}<br />
		public static void random()<br />
		{<br />
			Date d1 = new Date();<br />
			int x, y, sum;<br />
			int n = 0;<br />
			int userAnswer;<br />
			String input;<br />
		<br />
			Random randomNumbers = new Random();<br />
		<br />
			x = randomNumbers.nextInt(9);<br />
			y = randomNumbers.nextInt(9);<br />
		<br />
			for (int seconds = 0; seconds &lt;= 30; seconds++)<br />
			{<br />
				x = randomNumbers.nextInt(9);<br />
				y = randomNumbers.nextInt(9);<br />
					<br />
				input = JOptionPane.showInputDialog(x + "x" + y + "=");<br />
					<br />
				sum = x * y;<br />
					<br />
				userAnswer = Integer.parseInt(input);<br />
					<br />
				if ( userAnswer == sum)<br />
				{<br />
					n++;<br />
				}<br />
				<br />
				else<br />
				{<br />
					n--;<br />
				}<br />
				<br />
			}<br />
			<br />
		Date d2 = new Date();<br />
		long elapsed_time = d2.getTime() - d1.getTime();<br />
	<br />
	<br />
		if ( n &gt;= 28 && elapsed_time &lt; 40000)<br />
		{<br />
			JOptionPane.showMessageDialog(null, "Good job you beat the high score");<br />
		}<br />
		else<br />
		{<br />
			JOptionPane.showMessageDialog(null, "srry you did not beat the high score & your score is " + n + "& time is " + elapsed_time);<br />
		}<br />
		<br />
	<br />
		System.exit(0);<br />
	}<br />
}]]></description>
            <dc:creator>jj</dc:creator>
            <category>Java</category>
            <pubDate>Mon, 05 Jan 2009 11:34:52 -0700</pubDate>
        </item>
        <item>
            <guid>http://www.cppjj.com/forum/read.php?6,18,18#msg-18</guid>
            <title>handling Exceptions (no replies)</title>
            <link>http://www.cppjj.com/forum/read.php?6,18,18#msg-18</link>
            <description><![CDATA[ import java.io.*;<br />
import java.util.*;<br />
<br />
public class openFile<br />
{<br />
	public static void main(String[] args)throws IOException<br />
	{<br />
		<br />
		String fileName;<br />
		Scanner key = new Scanner(System.in);<br />
		<br />
		<br />
		System.out.println("Enter the name of a file: ");<br />
		fileName = key.nextLine();<br />
		<br />
		File file = new File(fileName);<br />
		Scanner outPut = new Scanner(file);<br />
		<br />
		int even = 0;<br />
		int odd = 0;<br />
		<br />
		while(outPut.hasNext())<br />
		{<br />
			try // <br />
			{<br />
				int k = outPut.nextInt();<br />
				<br />
				if(k%2==0)<br />
				{<br />
					even++;<br />
				}<br />
				else<br />
				{<br />
					odd++;<br />
				}<br />
				<br />
			}<br />
									 			<br />
			catch (InputMismatchException e)<br />
			{<br />
				outPut.nextLine();<br />
			}<br />
			<br />
		<br />
		}<br />
		<br />
		System.out.println("even " + even);<br />
		System.out.println("odd " + odd);<br />
	outPut.close();		<br />
	}<br />
<br />
}]]></description>
            <dc:creator>jj</dc:creator>
            <category>Java</category>
            <pubDate>Mon, 05 Jan 2009 11:31:21 -0700</pubDate>
        </item>
    </channel>
</rss>
