
problemas con botones :)
Publicado por hymuura (10 intervenciones) el 01/11/2013 18:07:23
Hola gente espero que esten bien. Me surgio una duda, hay algo que no me funciona xD estoy haciendo un pequeño menu con botones y labels y tengo un problemita con los eventos aca esta el codigo:
public class MenuConSwing extends JFrame implements ActionListener{
private JLabel label1;
private JButton button1, button2;
private int showMenu=0;
public MenuConSwing(){
setTitle("Facturatronic");
setLayout(null);
label1=new JLabel("Bienvenido a Facturatronic");
label1.setBounds(70, 0, 300, 100);
add(label1);
button1=new JButton("Factura");
button1.setBounds(50, 100, 100, 50);
add(button1);
button1.addActionListener(this);
button2=new JButton("Orden");
button2.setBounds(150, 100, 100, 50);
add(button2);
button2.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource()==button1) {
this.showMenu=1;
}
if (e.getSource()==button2) {
this.showMenu=2;
}
}
public int getShowMenu(){
return this.showMenu;
}
}
// tengo 1 label con un titulo y 2 botones uno que dice factura y otro orden (dentro de un jframe)
-------------------------------------------------------------------------------------------------------------
public static void main(String[] args) {
int showMenu1;
MenuConSwing menu1=new MenuConSwing();
menu1.setBounds(0,0,300,200);
menu1.setResizable(false);
menu1.setVisible(true);
menu1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
showMenu1=menu1.getShowMenu();
if (showMenu1==1){
System.out.println("hola");
menu1.setVisible(false);
}
if (showMenu1==2){
System.out.println("chau");
menu1.setVisible(false);
}
}
-----------------------------------------------------------------------------------------------------------
bueno lo que quise hacer es que:
1) Al presionar el boton factura me guarde el valor 1 dentro de una variable y en el main preguntar ese valor y que haga tal cosa
2)Al presionar el boton orden me guarde el valor 2 dentro de una variable y en el main preguntar ese valor y que haga tal cosa
mi problema es que: al presionar los botones no pasa nada xD alguien sabe que me esta pasando :)? estoy aprendiendo a manejar eventos :)
public class MenuConSwing extends JFrame implements ActionListener{
private JLabel label1;
private JButton button1, button2;
private int showMenu=0;
public MenuConSwing(){
setTitle("Facturatronic");
setLayout(null);
label1=new JLabel("Bienvenido a Facturatronic");
label1.setBounds(70, 0, 300, 100);
add(label1);
button1=new JButton("Factura");
button1.setBounds(50, 100, 100, 50);
add(button1);
button1.addActionListener(this);
button2=new JButton("Orden");
button2.setBounds(150, 100, 100, 50);
add(button2);
button2.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource()==button1) {
this.showMenu=1;
}
if (e.getSource()==button2) {
this.showMenu=2;
}
}
public int getShowMenu(){
return this.showMenu;
}
}
// tengo 1 label con un titulo y 2 botones uno que dice factura y otro orden (dentro de un jframe)
-------------------------------------------------------------------------------------------------------------
public static void main(String[] args) {
int showMenu1;
MenuConSwing menu1=new MenuConSwing();
menu1.setBounds(0,0,300,200);
menu1.setResizable(false);
menu1.setVisible(true);
menu1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
showMenu1=menu1.getShowMenu();
if (showMenu1==1){
System.out.println("hola");
menu1.setVisible(false);
}
if (showMenu1==2){
System.out.println("chau");
menu1.setVisible(false);
}
}
-----------------------------------------------------------------------------------------------------------
bueno lo que quise hacer es que:
1) Al presionar el boton factura me guarde el valor 1 dentro de una variable y en el main preguntar ese valor y que haga tal cosa
2)Al presionar el boton orden me guarde el valor 2 dentro de una variable y en el main preguntar ese valor y que haga tal cosa
mi problema es que: al presionar los botones no pasa nada xD alguien sabe que me esta pasando :)? estoy aprendiendo a manejar eventos :)
Valora esta pregunta


0