<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MixInformatico.com &#187; metodos</title>
	<atom:link href="http://www.mixinformatico.com/tag/metodos/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mixinformatico.com</link>
	<description>Reforzando tus ideas</description>
	<lastBuildDate>Sat, 31 Jul 2010 00:47:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Tutorial Java 3.- Metodos, Clases, Menu Grafico JOptionPane, Uso de Switch.</title>
		<link>http://www.mixinformatico.com/2010/03/25/tutorial-java-3-metodos-clases-menu-grafico-joptionpane-uso-de-switch/</link>
		<comments>http://www.mixinformatico.com/2010/03/25/tutorial-java-3-metodos-clases-menu-grafico-joptionpane-uso-de-switch/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 18:14:06 +0000</pubDate>
		<dc:creator>dementexmaster</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[metodos]]></category>
		<category><![CDATA[objetos]]></category>
		<category><![CDATA[tutorial 3]]></category>

		<guid isPermaLink="false">http://www.mixinformatico.com/?p=8929</guid>
		<description><![CDATA[Bueno con lo que hemos visto en el tutorial 1 y 2 vamos a poder hacer lo que el tutorial 3 implica crearemos un menu con JOptionPane de la libreria swing el menu lo creariamos de la siguiente manera en la clase principal: 1 2 3 4 5 6 7 8 9 10 11 12 [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Bueno con lo que hemos visto en el tutorial 1 y 2 vamos a poder hacer lo que el tutorial 3 implica crearemos un menu con JOptionPane de la libreria swing el menu lo creariamos de la siguiente manera en la clase principal:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.swing.*</span><span style="color: #339933;">;</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Tutorial3 <span style="color: #009900;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #003399;">String</span> recibido <span style="color: #339933;">=</span> <span style="color: #003399;">JOptionPane</span>.<span style="color: #006633;">showInputDialog</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Menu<span style="color: #000099; font-weight: bold;">\n</span> &quot;</span> <span style="color: #339933;">+</span>
 <span style="color: #0000ff;">&quot;1.-Sumar&quot;</span> <span style="color: #339933;">+</span>
 <span style="color: #0000ff;">&quot;2.-Restar&quot;</span> <span style="color: #339933;">+</span>
 <span style="color: #0000ff;">&quot;3.-Salir&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000066; font-weight: bold;">int</span> minumero <span style="color: #339933;">=</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>recibido<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000000; font-weight: bold;">switch</span><span style="color: #009900;">&#40;</span>minumero<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span>
 <span style="color: #666666; font-style: italic;">//Aqui entrara si se ingresa 1</span>
 <span style="color: #666666; font-style: italic;">//Que en este caso es la suma</span>
 <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
 <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">:</span>
 <span style="color: #666666; font-style: italic;">//Aqui entrara si se ingresa 2</span>
 <span style="color: #666666; font-style: italic;">//Que es el caso de la resta</span>
 <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><span id="more-8929"></span><br />
Una vez teniendo el menu nos disponemos a crear una nueva clase a la cual yo le pondre el nombre libreria, ustedes le pueden poner el nombre que les guste y en esta crearemos los metodos restar y sumar:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> libreria<span style="color: #009900;">&#123;</span>
 <span style="color: #666666; font-style: italic;">//Aqui le ingresar los parametros int x, int y que serian los numeros a evaluar</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> sumar<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> x, <span style="color: #000066; font-weight: bold;">int</span> y<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
 <span style="color: #000066; font-weight: bold;">int</span> resultado <span style="color: #339933;">=</span> x<span style="color: #339933;">+</span>y<span style="color: #339933;">;</span>
 <span style="color: #003399;">JOptionPane</span>.<span style="color: #006633;">showMessageDialog</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span>, <span style="color: #0000ff;">&quot;El resultado de la suma es: &quot;</span><span style="color: #339933;">+</span>resultado<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> restar<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> x, <span style="color: #000066; font-weight: bold;">int</span> y<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
 <span style="color: #000066; font-weight: bold;">int</span> resultado <span style="color: #339933;">=</span> x<span style="color: #339933;">-</span>y<span style="color: #339933;">;</span>
 <span style="color: #003399;">JOptionPane</span>.<span style="color: #006633;">showMessageDialog</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span>, <span style="color: #0000ff;">&quot;El resultado de la resta es: &quot;</span><span style="color: #339933;">+</span>resultado<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Ahora solo falta llamarlos en la clase principal, esto lo haremos creando un objeto de la clase libreria el objeto se crea de la siguiente manera:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">libreria obj <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> libreria<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>ya que el objeto lo nombremos obj mandamos llamar nuestros metodos de la siguiente manera:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">obj.<span style="color: #006633;">sumar</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span>,<span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
obj.<span style="color: #006633;">restar</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">6</span>,<span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>En el codigo final nos quedaria de la siguiente manera:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.swing.*</span><span style="color: #339933;">;</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Tutorial3 <span style="color: #009900;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #003399;">String</span> recibido <span style="color: #339933;">=</span> <span style="color: #003399;">JOptionPane</span>.<span style="color: #006633;">showInputDialog</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Menu<span style="color: #000099; font-weight: bold;">\n</span> &quot;</span> <span style="color: #339933;">+</span>
 <span style="color: #0000ff;">&quot;1.-Sumar&quot;</span> <span style="color: #339933;">+</span>
 <span style="color: #0000ff;">&quot;2.-Restar&quot;</span> <span style="color: #339933;">+</span>
 <span style="color: #0000ff;">&quot;3.-Salir&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000066; font-weight: bold;">int</span> minumero <span style="color: #339933;">=</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>recibido<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000000; font-weight: bold;">switch</span><span style="color: #009900;">&#40;</span>minumero<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span>
       <span style="color: #666666; font-style: italic;">//Aqui 5 y 6 serian los parametros a evaluar (sumar)</span>
      obj.<span style="color: #006633;">sumar</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span>,<span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
 <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">:</span>
     <span style="color: #666666; font-style: italic;">//Aqui 5 y 6 serian los parametros a evaluar (restar)</span>
      obj.<span style="color: #006633;">restar</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span>,<span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p style="text-align: justify;">Los numeros se podrian ingresar de forma manual por el usuario el tutorial mas completo esta en youtube aqui les dejo las 2 partes que lo conforman:</p>
<p style="text-align: justify;">parte 1:</p>
<p style="text-align: justify;">[youtube]http://www.youtube.com/watch?v=ZHTBbDVzyE8[/youtube]</p>
<p style="text-align: justify;">parte2:</p>
<p style="text-align: justify;">[youtube]http://www.youtube.com/watch?v=_nqdt0RQ2x0[/youtube]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mixinformatico.com/2010/03/25/tutorial-java-3-metodos-clases-menu-grafico-joptionpane-uso-de-switch/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.705 seconds -->

