Ayuda con Classes y Herencias
Publicado por Angel Escobedo (1 intervención) el 27/01/2007 10:08:00
public class Tragamoneda {
public static void main(String[] args) {
// Crear marco.
TragamonedaFrame frame = new TragamonedaFrame();
// Mostrar frame.
frame.show();
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;//Tablas
import javax.swing.border.*;//Bordes
import java.util.Calendar;//Fecha y Hora
import java.util.Date;
import java.io.*;
public class TragamonedaFrame extends JFrame implements ActionListener {
JPanel pnlPaneles[] = new JPanel[38];//38 paneles contenidos en el arreglo pnlPaneles
JLabel lblEtiquetas[] = new JLabel[60];//100 etiquetas contenidos en el arreglo lblEtiquetas
JComboBox cboComboBox[] = new JComboBox[50];//20 combobox contenidos en el arreglo cboComboBox
JPasswordField txtPassword[] = new JPasswordField[1];//1 Campo de texto password contenidos en el arreglo txtPassword
JToggleButton btnToggle[] = new JToggleButton[20];//20 Botones presionados contenidos en el arreglo btnToggle
JButton btnBotones[] = new JButton[40];//40 botones contenidos en el arreglo btnBotones
JTextField txtTextField[] = new JTextField[30];//28 Campos de texto en el arreglo txtTextField
JTextArea txtTextArea[] = new JTextArea[11];//10 Areas de texto contenidos en el arreglo txtTextArea
JLabel lblFondos[] = new JLabel[10];//10 labels usadas como fondo
int dia, mes, año, hora, minuto, segundo;
int error1,error2;
Icon csesion, salir, retro, inicio, mant, caja, simu, repo, fondo1, mantenimiento, admin,user;
//Indica la posición del Panel actual,indica la opcion y categoria seleccioanda
int Indicador_Panel,Indicador_Opcion,Indicador_Categoria;;
//Variables de la GUI
List Lista_Reporte;
Timer Tiempo;
ButtonGroup Grupo_Opciones,Grupo_Categoria;
//Variables Globales
String Fecha,Hora;
boolean Estado_Tabla;
// Constructor
public TragamonedaFrame() {
setLayout(null);
setSize(new Dimension(800,640));
getContentPane().setBackground(Color.white);
setUndecorated(true);
getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
// Agregar Listener de la ventana(Cerrar ventana).
this.addWindowListener
(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
TragamonedaFrame.this.Close_Frame();
}
});
// CREACIÓN DE LA GUI
//Panel Cerra Sesión ,Salir y Atrás
pnlPaneles[0]= new JPanel();
pnlPaneles[0].setLayout(null);
pnlPaneles[0].setBounds(10,587,90,30);
pnlPaneles[0].setVisible(true);
getContentPane().add(pnlPaneles[0]);
salir= new ImageIcon("icon/salir.jpg");
btnBotones[0]= new JButton(salir);
btnBotones[0].setToolTipText("Salir");
btnBotones[0].setVisible(true);
btnBotones[0].addActionListener(this);
btnBotones[0].setBounds(0,0,30,30);
pnlPaneles[0].add(btnBotones[0]);
csesion= new ImageIcon("icon/csesion.jpg");
btnBotones[1]= new JButton(csesion);
btnBotones[1].setToolTipText("Cerrar Sesión");
btnBotones[1].setBounds(30,0,30,30);
btnBotones[1].addActionListener(this);
btnBotones[1].setVisible(false);
pnlPaneles[0].add(btnBotones[1]);
retro= new ImageIcon("icon/retro.gif");
btnBotones[2]= new JButton(retro);
btnBotones[2].setToolTipText("Retroceder");
btnBotones[2].setBounds(60,0,30,30);
btnBotones[2].addActionListener(this);
btnBotones[2].setVisible(false);
pnlPaneles[0].add(btnBotones[2]);
//Panel de Entrada o Login
pnlPaneles[1]= new JPanel();
pnlPaneles[1].setLayout(null);
pnlPaneles[1].setBounds(255,180,240,120);
pnlPaneles[1].setVisible(true);
getContentPane().add(pnlPaneles[1]);
lblEtiquetas[0]= new JLabel("Usuario :");
lblEtiquetas[0].setBounds(2,2,110,25);
pnlPaneles[1].add(lblEtiquetas[0]);
cboComboBox[0]= new JComboBox();
cboComboBox[0].setBounds(120,2,110,25);
cboComboBox[0].addItem("Administrador");
cboComboBox[0].addItem("Empleado");
cboComboBox[0].addItem("Cliente");
cboComboBox[0].addItemListener(new ItemListener(){
//clase interna anonima
public void itemStateChanged(ItemEvent e){
if(e.getStateChange()==ItemEvent.SELECTED){
if(cboComboBox[0].getSelectedIndex()==2){
txtPassword[0].setVisible(false);
lblEtiquetas[0].setVisible(true);
lblEtiquetas[1].setVisible(false);
}else{
txtPassword[0].setText("");
txtPassword[0].setVisible(true);
lblEtiquetas[0].setVisible(true);
lblEtiquetas[1].setVisible(true);
}
}
}
}
);
}
protected void Close_Frame() {
// Cerrar aplicación
System.exit(1);
}
// Procesa eventos de tipo ActionEvent
public void actionPerformed( ActionEvent e ){
//Timer de la Fecha y Hora
if(e.getSource()== Tiempo){
//Toma la Fecha y Hora del Sistema
Date date = Calendar.getInstance().getTime();
int mes = Integer.parseInt(String.format("%1$tm",date));
Hora = String.format("%tT",date);
Fecha = String.format("%1$td/%1$tm/%1$tY",date);
//Titulo del Frame
/***/setTitle(String.format("Fecha : %1$td de "+ obtener_Mes(mes)+" de %1$tY "+
"Hora : %tT ",date));
}
//Clic en cualquier Botón
else
for(int i = 0; i<btnBotones.length; i++)
if(e.getSource()== btnBotones[i]){
System.out.println("Se Usa Boton Cargado");
BotonPulsado(i);
break;
}
}
//Devuelve el mes
String obtener_Mes(int m){
switch(m){
case 1: return "Enero";
case 2: return "Febrero";
case 3: return "Marzo";
case 4: return "Abril";
case 5: return "Mayo";
case 6: return "Junio";
case 7: return "Julio";
case 8: return "Agosto";
case 9: return "Setiembre";
case 10: return "Octubre";
case 11: return "Noviembre";
case 12: return "Diciembre";
}
return "";
}
void BotonPulsado(int indice){
}
}
este es el error que me arroja la consola :
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
Press any key to continue...
public static void main(String[] args) {
// Crear marco.
TragamonedaFrame frame = new TragamonedaFrame();
// Mostrar frame.
frame.show();
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;//Tablas
import javax.swing.border.*;//Bordes
import java.util.Calendar;//Fecha y Hora
import java.util.Date;
import java.io.*;
public class TragamonedaFrame extends JFrame implements ActionListener {
JPanel pnlPaneles[] = new JPanel[38];//38 paneles contenidos en el arreglo pnlPaneles
JLabel lblEtiquetas[] = new JLabel[60];//100 etiquetas contenidos en el arreglo lblEtiquetas
JComboBox cboComboBox[] = new JComboBox[50];//20 combobox contenidos en el arreglo cboComboBox
JPasswordField txtPassword[] = new JPasswordField[1];//1 Campo de texto password contenidos en el arreglo txtPassword
JToggleButton btnToggle[] = new JToggleButton[20];//20 Botones presionados contenidos en el arreglo btnToggle
JButton btnBotones[] = new JButton[40];//40 botones contenidos en el arreglo btnBotones
JTextField txtTextField[] = new JTextField[30];//28 Campos de texto en el arreglo txtTextField
JTextArea txtTextArea[] = new JTextArea[11];//10 Areas de texto contenidos en el arreglo txtTextArea
JLabel lblFondos[] = new JLabel[10];//10 labels usadas como fondo
int dia, mes, año, hora, minuto, segundo;
int error1,error2;
Icon csesion, salir, retro, inicio, mant, caja, simu, repo, fondo1, mantenimiento, admin,user;
//Indica la posición del Panel actual,indica la opcion y categoria seleccioanda
int Indicador_Panel,Indicador_Opcion,Indicador_Categoria;;
//Variables de la GUI
List Lista_Reporte;
Timer Tiempo;
ButtonGroup Grupo_Opciones,Grupo_Categoria;
//Variables Globales
String Fecha,Hora;
boolean Estado_Tabla;
// Constructor
public TragamonedaFrame() {
setLayout(null);
setSize(new Dimension(800,640));
getContentPane().setBackground(Color.white);
setUndecorated(true);
getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
// Agregar Listener de la ventana(Cerrar ventana).
this.addWindowListener
(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
TragamonedaFrame.this.Close_Frame();
}
});
// CREACIÓN DE LA GUI
//Panel Cerra Sesión ,Salir y Atrás
pnlPaneles[0]= new JPanel();
pnlPaneles[0].setLayout(null);
pnlPaneles[0].setBounds(10,587,90,30);
pnlPaneles[0].setVisible(true);
getContentPane().add(pnlPaneles[0]);
salir= new ImageIcon("icon/salir.jpg");
btnBotones[0]= new JButton(salir);
btnBotones[0].setToolTipText("Salir");
btnBotones[0].setVisible(true);
btnBotones[0].addActionListener(this);
btnBotones[0].setBounds(0,0,30,30);
pnlPaneles[0].add(btnBotones[0]);
csesion= new ImageIcon("icon/csesion.jpg");
btnBotones[1]= new JButton(csesion);
btnBotones[1].setToolTipText("Cerrar Sesión");
btnBotones[1].setBounds(30,0,30,30);
btnBotones[1].addActionListener(this);
btnBotones[1].setVisible(false);
pnlPaneles[0].add(btnBotones[1]);
retro= new ImageIcon("icon/retro.gif");
btnBotones[2]= new JButton(retro);
btnBotones[2].setToolTipText("Retroceder");
btnBotones[2].setBounds(60,0,30,30);
btnBotones[2].addActionListener(this);
btnBotones[2].setVisible(false);
pnlPaneles[0].add(btnBotones[2]);
//Panel de Entrada o Login
pnlPaneles[1]= new JPanel();
pnlPaneles[1].setLayout(null);
pnlPaneles[1].setBounds(255,180,240,120);
pnlPaneles[1].setVisible(true);
getContentPane().add(pnlPaneles[1]);
lblEtiquetas[0]= new JLabel("Usuario :");
lblEtiquetas[0].setBounds(2,2,110,25);
pnlPaneles[1].add(lblEtiquetas[0]);
cboComboBox[0]= new JComboBox();
cboComboBox[0].setBounds(120,2,110,25);
cboComboBox[0].addItem("Administrador");
cboComboBox[0].addItem("Empleado");
cboComboBox[0].addItem("Cliente");
cboComboBox[0].addItemListener(new ItemListener(){
//clase interna anonima
public void itemStateChanged(ItemEvent e){
if(e.getStateChange()==ItemEvent.SELECTED){
if(cboComboBox[0].getSelectedIndex()==2){
txtPassword[0].setVisible(false);
lblEtiquetas[0].setVisible(true);
lblEtiquetas[1].setVisible(false);
}else{
txtPassword[0].setText("");
txtPassword[0].setVisible(true);
lblEtiquetas[0].setVisible(true);
lblEtiquetas[1].setVisible(true);
}
}
}
}
);
}
protected void Close_Frame() {
// Cerrar aplicación
System.exit(1);
}
// Procesa eventos de tipo ActionEvent
public void actionPerformed( ActionEvent e ){
//Timer de la Fecha y Hora
if(e.getSource()== Tiempo){
//Toma la Fecha y Hora del Sistema
Date date = Calendar.getInstance().getTime();
int mes = Integer.parseInt(String.format("%1$tm",date));
Hora = String.format("%tT",date);
Fecha = String.format("%1$td/%1$tm/%1$tY",date);
//Titulo del Frame
/***/setTitle(String.format("Fecha : %1$td de "+ obtener_Mes(mes)+" de %1$tY "+
"Hora : %tT ",date));
}
//Clic en cualquier Botón
else
for(int i = 0; i<btnBotones.length; i++)
if(e.getSource()== btnBotones[i]){
System.out.println("Se Usa Boton Cargado");
BotonPulsado(i);
break;
}
}
//Devuelve el mes
String obtener_Mes(int m){
switch(m){
case 1: return "Enero";
case 2: return "Febrero";
case 3: return "Marzo";
case 4: return "Abril";
case 5: return "Mayo";
case 6: return "Junio";
case 7: return "Julio";
case 8: return "Agosto";
case 9: return "Setiembre";
case 10: return "Octubre";
case 11: return "Noviembre";
case 12: return "Diciembre";
}
return "";
}
void BotonPulsado(int indice){
}
}
este es el error que me arroja la consola :
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
Press any key to continue...
Valora esta pregunta


0