1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| import java.awt.*;
import javax.swing.*;
import com.sun.org.apache.xerces.internal.impl.RevalidationHandler;
import java.awt.event.*;
public class BABEL extends JFrame implements ActionListener{
private JPanel pan1= new JPanel();
private JButton buton1=new JButton("1");
private JButton buton2=new JButton("2");
private JButton buton3=new JButton("");
public BABEL(){
int xTemp ;
int yTemp;
this.setResizable(false);
this.setSize(240, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
pan1.setBackground(Color.BLACK);
pan1.setLayout(new GridLayout(3, 3,5,5));
pan1.setPreferredSize(new Dimension (240,190));
pan1.setLayout(new GridLayout(2,2 ,5,5));
pan1.add(buton2);
pan1.add(buton1);
pan1.add(buton3);
buton1.addActionListener(this);
buton2.addActionListener(this);
buton3.addActionListener(this);
this.add(pan1);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource() == buton1) { int xTemp = buton1.getX();
int yTemp =buton1.getY();
buton1.setLocation(buton2.getX(), buton2.getY());
buton2.setLocation(xTemp , yTemp);
pan1.revalidate();
}
}
} |
Partager