¿Este código se ejecuta en segundo plano ? , me refiero a si registra las teclas aun cuando la aplicación no tenga el foco .
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú
while(getchar() != '\n');
#include<stdio.h>
int main(){
int x[50][50],y,z;
for(y=0;y<5;y++) {
for(z=0;z<2;z++) {
scanf("%d",&x[y][z]);
}
}
for(y=0;y<5;y++) {
for(z=0;z<2;z++) {
printf("%d",x[y][z]);
}
}
getchar();
}
Cita de: athlit en 17 Agosto 2010, 17:33 PM
Podrias explicar a un novato como yo el porque de:
public MyCalendario(){
}
y
public String toString()
¿Que hacen ambos? El primero declaras un metodo vacio? Y el segundo declaras un metodo que devolverá un String y le haces el casting a String? (¿?)
Te agradecería me lo aclararas para lograr entenderlo.
Muchas gracias de antemano.
Un saludo.
MyCalendario calendario = new MyCalendario();
MyCalendario calendario = new MyCalendario();
System.out.println(calendario);
MyCalendario calendario = new MyCalendario();
System.out.println(calendario);
es equivalente a
System.out.println(calendario.toString());
JFrame
|
|-> JTabbedPane
| |-> JPanel(JPanel1)--|-------|
|-> JPanel --- |
| |-> JPanel(JPanelx)----------|
| |----->GestorTabs
| |-> JPanel(JPanely)----------|
|-> JPanel --- |
|-> JPanel(JPanel2)--|-------|
import javax.swing.JLabel;
import java.awt.Dimension;
import javax.swing.JPanel;
public class Ventana2 extends JPanel implements Gestionable {
private JLabel jLabel1;
private Gestor gestor;
public Ventana2(Gestor gestor) {
this.gestor = gestor;
initComponents();
}
private void initComponents() {
jLabel1 = new JLabel();
jLabel1.setPreferredSize(new Dimension(200, 25));
jLabel1.setText("Hola a todos");
this.add(jLabel1);
}
public void setText(String text) {
jLabel1.setText(text);
}
public Gestor getGestor(){
return this.gestor;
}
}
import javax.swing.JTextField;
import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JPanel;
public class Ventana1 extends JPanel implements Gestionable {
private JTextField jTextField1;
private Gestor gestor;
JButton boton = new JButton("Presiona aqui");
public Ventana1(Gestor gestor) {
this.gestor = gestor;
iniciarInterfaz();
}
private void iniciarInterfaz() {
GestorTabs gesorTabs = new GestorTabs(this);
jTextField1 = new javax.swing.JTextField();
jTextField1.setText("escribe algo y oprime enter");
jTextField1.setPreferredSize(new Dimension(200, 25));
jTextField1.addActionListener(gesorTabs);
boton.addActionListener(gesorTabs);
boton.setName("boton enviar");
this.add(jTextField1);
this.add(boton);
}
public JTextField getCajaTexto(){
return this.jTextField1;
}
public Gestor getGestor(){
return this.gestor;
}
}
public interface Gestionable {
public Gestor getGestor();
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
class GestorTabs implements ActionListener{
Gestionable ventana;
public GestorTabs(Gestionable panel){
this.ventana = panel;
}
public void actionPerformed(ActionEvent e){
if(ventana instanceof Ventana1){
Ventana1 ven1 = (Ventana1)ventana;
this.ejecutarVentana1(ven1, ven1.getCajaTexto().getText());
}
}
/**
*
* @param ven
* @param textoMostrar
*/
public void ejecutarVentana1(Ventana1 ven, String textoMostrar){
Gestor ges = this.ventana.getGestor();
Ventana2 vent2 = (Ventana2)ges.getPanel("ventana 2");
vent2.setText(textoMostrar);
}
}
import java.awt.Component;
import java.awt.Container;
import javax.swing.JPanel;
public class Gestor {
Container container ;
public Gestor(Container conta){
this.container = conta;
}
/**
* Devuelve el panel especificado por nombre
* @param name
* @return
*/
public JPanel getPanel(String name){
Component []componentes = this.container.getComponents();
JPanel panel;
for(Component conp : this.container.getComponents()){
panel = (JPanel)conp;
if(name.equals(panel.getName())){
return panel;
}
}
return null;
}
}
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
public class Principal extends JFrame {
public static void main(String[] args) {
Principal prin = new Principal();
JTabbedPane panel = new JTabbedPane();
Gestor gestor = new Gestor(panel);
Ventana1 vent = new Ventana1(gestor);
Ventana2 vent2 = new Ventana2(gestor);
vent.setName("ventana 1");
vent2.setName("ventana 2");
panel.addTab("Ventana 1" ,vent);
panel.addTab("Ventana 2",vent2);
panel.setBounds(200, 5000, 6000 ,7000);
panel.setVisible(true);
prin.getContentPane().add(panel);
prin.setVisible(true);
prin.setBounds(500, 200, 500 ,500);
prin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}