Java - Fallo al finalizar una practica de Java

 
Vista:
sin imagen de perfil

Fallo al finalizar una practica de Java

Publicado por Flenwd (2 intervenciones) el 12/07/2013 13:57:50
Hola, estoy estudiando java y en mi manual vienen unos ejemplos, al ir a finalizar uno me da un error con un else y me gustaria saber donde esta el fallo del codigo, el netbeans me dice que falta un if pero el codigo aparece tal cual.

* Main.java
*
* Created on 29 de junio de 2013, 13:33
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package cuadrosdialogo;

import javax.swing.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;

/**
*
* @author Juan Luis
*/
public class CuadrosDialogo extends javax.swing.JFrame {

/** Creates a new form CuadrosDialogo */
public CuadrosDialogo() {
initComponents();
}
private void btndialogoActionPerformed(java.awt.event.ActionEvent evt)
{
final JDialog ventana = new JDialog (this, "Acerca de..", true);
ventana.getContentPane().add(new JLabel ("Aplicacion SWING",JLabel.CENTER), BorderLayout.SOUTH);
btncerrar.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
ventana.setVisible(false);
}
});
ventana.setSize(200, 200);
ventana.setLocation(100, 100);
ventana.setVisible(true);
}
private void btncolorActionPerformed(java.awt.event.ActionEvent evt){
Color col;
col= JColorChooser.showDialog(this, "Color de fondo", btncolor.getBackground());
if (col != null){
btncolor.setBackground(col);
}
}
private void btnmaximizarActionPerformed(java.awt.evet.ActionEvent evt){
int ancho, alto;
ancho = getToolkit().getScreenSize().width;
alto = getTooljit().getScreenSize().height - 30;
this.setSize(ancho, alto);
this.setLocation(0, 0);
}
private void btnframeAvtionPerformed(java.awt.event.ActionEven evt){
JFileChoseer fd;
fd=new JFileChoseer();
int respuesta=-1;
respuesta = JOptionPane.showConfirmDialog(this, "¿Desea abrir?");
if (respuesta == JOptionPane.OK_OPTION)
{
//ABRIR
fd.setDialogType(JFileChooser.OPEN_DIALOG);
fd.setDialogTitle("Abrir un archivo");
fd.setCurrentDirectory(new File("C:\\"));
respuesta = fd.showOpenDialog (this);
if (respuesta == JFileChooser.APROVE_OPTION) {
this.lblmsj.setText("Archivo abierto"+fd.getSelectedFile());
} else
{
this.lblmsj.setText("Acción CANCELADA");
}
} else if (respuesta == JOptionPane.CANCEL_OPTION) {
//GUARDAR
fd.setDialogType(JFileChooser.SAVE_DIALOG);
fd.setDialogTitle("Guaradar archivo");
fd.setApproveButtonText("Guardar como...");
respuesta = fd.showSaveDialog(this);
if (respuesta == JFileChooser.APPROVE_OPTION)
{
this.lblmsj.setText("Archivo Guaradado " + fd.getSelectedFile());
} else
{
this.lblmsj.setText("Accion CANCELADA");
}
}
}
private void btnOptionPaneActionPerformed(java.awt.event.ActionEvent evt) {
int icono = -1;
String titulo, mensaje;
titulo = this.txttitulo.getText();
mensaje = this.txtmensaje.getText();
if (this.rdbadvertencia.isSelected())
{
icono = JOptionPane.WARNING_MESSAGE;
}
else if (this.rdbinformacion.isSelected())
{
icono = JOptionPane.INFORMATION_MESSAGE;
}
else if (this.rdbinterrogacion.isSelected())
{
icono = JOptionPane.QUESTION_MESSAGE;
}
else if (this.rdbsinicono.isSelected())
{
icono = JOptionPane.PLAIN_MESSAGE;
}
else
{
icono = JOptionPane.ERROR_MESSAGE;
}
if (this.rbdconfirmacion.isSelected())
{
JOptionPane.showConfirmDialog(this, mensaje, titulo, JOptionPane.YES_NO_CANCEL_OPTION);
}
else if (this.rbdentrada.isSelected());
{
//Primero muestra una ventana que captura un texto y luego lo muestra en otra
String s="";
s= JOptionPane.showInputDialog(this, mensaje, titulo, icono);
JOptionPane.showMessageDialog(this, s, titulo, icono);
} else
{
JOptionPane.showMessageDialog(this, mensaje, titulo, icono);
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Fallo al finalizar una practica de Java

Publicado por exonent (5 intervenciones) el 12/07/2013 19:20:01
" else if " no es necesario poner elsif como lo sería en PL por ejemplo. Intenta quitarlos todos y lanzarlo. El problema estará en eso. De todas formas, sangra el contenido que siempre será mas útil.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Fallo al finalizar una practica de Java

Publicado por Tom (1831 intervenciones) el 15/07/2013 16:25:02
} else if (this.rbdentrada.isSelected());

Bonito ';' al final.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Fallo al finalizar una practica de Java

Publicado por Flenwd (2 intervenciones) el 16/07/2013 00:28:58
Bueno, probe las dos soluciones que me facilitasteis y nada. Asique revise el codigo y vi que faltaban algunas lineas, el fallo de copiar, PERDON. Pero aun asi no funciona me da otro error distinto.

* Main.java
*
* Created on 29 de junio de 2013, 13:33
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package cuadrosdialogo;

import javax.swing.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;

/**
*
* @author Juan Luis
*/
public class CuadrosDialogo extends javax.swing.JFrame {

/** Creates a new form CuadrosDialogo */
public CuadrosDialogo() {
initComponents();
}
private void btndialogoActionPerformed(java.awt.event.ActionEvent evt)
{
final JDialog ventana = new JDialog (this, "Acerca de..", true);
ventana.getContentPane().add(new JLabel ("Aplicacion SWING",JLabel.CENTER), BorderLayout.CENTER);
JButton btncerrar = new JButton("Cerrar");
ventana.grtContentPane().add(btncerrar, BorderLayout.SOUTH);
btncerrar.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
ventana.setVisible(false);
}
});
ventana.setSize(200, 200);
ventana.setLocation(100, 100);
ventana.setVisible(true);
}
private void btncolorActionPerformed(java.awt.event.ActionEvent evt){
Color col;
col= JColorChooser.showDialog(this, "Color de fondo", btncolor.getBackground());
if (col != null){
btncolor.setBackground(col);
}
}
private void btnmaximizarActionPerformed(java.awt.evet.ActionEvent evt){
int ancho, alto;
ancho = getToolkit().getScreenSize().width;
alto = getTooljit().getScreenSize().height - 30;
this.setSize(ancho, alto);
this.setLocation(0, 0);
}
private void btnframeActionPerformed(java.awt.event.ActionEvent evt){
JFrame fr;
fr = new JFrame();
fr.setVisible(true);
}
private void btnarchivoAvtionPerformed(java.awt.event.ActionEven evt){
JFileChoseer fd;
fd=new JFileChoseer();
int respuesta=-1;
respuesta = JOptionPane.showConfirmDialog(this, "¿Desea abrir?");
if (respuesta == JOptionPane.OK_OPTION)
{
//ABRIR
fd.setDialogType(JFileChooser.OPEN_DIALOG);
fd.setDialogTitle("Abrir un archivo");
fd.setCurrentDirectory(new File("C:\\"));
respuesta = fd.showOpenDialog (this);
if (respuesta == JFileChooser.APROVE_OPTION) {
this.lblmsj.setText("Archivo abierto"+fd.getSelectedFile());
} else
{
this.lblmsj.setText("Acción CANCELADA");
}
} else if (respuesta == JOptionPane.CANCEL_OPTION) {
//GUARDAR
fd.setDialogType(JFileChooser.SAVE_DIALOG);
fd.setDialogTitle("Guardar archivo");
fd.setApproveButtonText("Guardar como...");
respuesta = fd.showSaveDialog(this);
if (respuesta == JFileChooser.APPROVE_OPTION)
{
this.lblmsj.setText("Archivo Guaradado " + fd.getSelectedFile());
} else
{
this.lblmsj.setText("Acción CANCELADA");
}
}
}
private void btnOptionPaneActionPerformed(java.awt.event.ActionEvent evt) {
int icono = -1;
String titulo, mensaje;
titulo = this.txttitulo.getText();
mensaje = this.txtmensaje.getText();
if (this.rdbadvertencia.isSelected())
{
icono = JOptionPane.WARNING_MESSAGE;
}
else if (this.rdbinformacion.isSelected())
{
icono = JOptionPane.INFORMATION_MESSAGE;
}
else if (this.rdbinterrogacion.isSelected())
{
icono = JOptionPane.QUESTION_MESSAGE;
}
else if (this.rdbsinicono.isSelected())
{
icono = JOptionPane.PLAIN_MESSAGE;
}
else
{
icono = JOptionPane.ERROR_MESSAGE;
}
if (this.rbdconfirmacion.isSelected())
{
JOptionPane.showConfirmDialog(this, mensaje, titulo, JOptionPane.YES_NO_CANCEL_OPTION);
}
else if (this.rbdentrada.isSelected())
{
//Primero muestra una ventana que captura un texto y luego lo muestra en otra
String s="";
s= JOptionPane.showInputDialog(this, mensaje, titulo, icono);
JOptionPane.showMessageDialog(this, s, titulo, icono);
} else
{
JOptionPane.showMessageDialog(this, mensaje, titulo, icono);
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
}


Y el fallo es este:
init:
deps-clean:
Deleting directory C:\Users\Juan Luis\Trabajos\Java\CuadrosDialogo\build
clean:
init:
deps-jar:
Created dir: C:\Users\Juan Luis\Trabajos\Java\CuadrosDialogo\build\classes
Compiling 1 source file to C:\Users\Juan Luis\Trabajos\Java\CuadrosDialogo\build\classes
C:\Users\Juan Luis\Trabajos\Java\CuadrosDialogo\src\cuadrosdialogo\Main.java:1: error: class, interface, or enum expected
* Main.java
1 error
GENERACIÓN INCORRECTA (tiempo total: 0 segundos)


De todas maneras uso el netBeans 5.0 , no se si tendra que ver, aunque hace tiempo estuve haciendo un curso de Visual Basic y la diferencia de la versión si daba problemas a la hora de hacer los ejercicios.


Si me aconsejais una plataforma mejor para proseguir, lo agradeceria.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar