import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class pla2 extends JFrame implements ActionListener
{
private JPanel x=new JPanel();
private JButton b1=new JButton("1");
private JButton b2=new JButton("2");
private JButton b3=new JButton("3");
private JButton b4=new JButton("4");
private JButton b5=new JButton("5");
private int factor;
public pla2(){
super("factor");
getContentPane().add(x);
setSize(300,300);
x.add(b1); b1.addActionListener((ActionListener) this);
x.add(b2); b2.addActionListener((ActionListener) this);
x.add(b3); b3.addActionListener((ActionListener) this);
x.add(b4); b4.addActionListener((ActionListener) this);
x.add(b5); b5.addActionListener((ActionListener) this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent ev){
if(ev.getSource()==b1){factor=1;}
if(ev.getSource()==b2){factor=2;}
if(ev.getSource()==b3){factor=3;}
if(ev.getSource()==b4){factor=4;}
if(ev.getSource()==b5){factor=5;}
}
public int choix(){return factor;}
}
class final_class {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int factor;
pla2 p2=new pla2();
p2.setVisible(true);
factor=p2.choix(); System.out.println("fac "+factor);
}
}
This post has been edited by killer_beast: 31 May 2008 - 07:44 AM

New Topic/Question
Reply




MultiQuote





|