TP 3

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

import java.awt.

FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

public class InternalFrameEx3_tp3 extends JInternalFrame implements ActionListener{


private JButton btna,btns;
private JTextField txt;
public InternalFrameEx3_tp3() {
// TODO Auto-generated constructor stub
this.setTitle("ex3");
this.setBounds(30, 30, 400, 300);
this.setClosable(true);
this.setResizable(true);
this.setIconifiable(true);
this.setLayout(new FlowLayout());

btna=new JButton("afficher");
btna.addActionListener(this);

btns=new JButton("afficher sélection");


btns.addActionListener(this);

txt=new JTextField(10);
txt.addActionListener(this);

this.add(btna);
this.add(btns);
this.add(txt);

this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==btna) {
JOptionPane.showMessageDialog(this, "Appui sur le bouton
Afficher");
}
if(e.getSource()==btns) {
JOptionPane.showMessageDialog(this, txt.getSelectedText());
}

}
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

public class InternalFrameEx4_tp3 extends JInternalFrame implements MouseListener{


private JLabel lbl;
public InternalFrameEx4_tp3() {
// TODO Auto-generated constructor stub
this.setTitle("ex4");
this.setBounds(40, 40, 400, 300);
this.setClosable(true);
this.setResizable(true);
this.setIconifiable(true);
this.setLayout(new FlowLayout());

lbl=new JLabel();
lbl.setPreferredSize(new Dimension(200 ,50));
lbl.setBackground(Color.red);
lbl.setOpaque(true);

lbl.addMouseListener(this);

this.addMouseListener(this);

this.add(lbl);

this.setVisible(true);
}
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
if(e.getButton()==MouseEvent.BUTTON1) {
JOptionPane.showMessageDialog(this, "boutton gauche "+e.getX()
+":"+e.getY());
}
if(e.getButton()==MouseEvent.BUTTON2) {
JOptionPane.showMessageDialog(this, "boutton centre "+e.getX()
+":"+e.getY());
}
if(e.getButton()==MouseEvent.BUTTON3) {
JOptionPane.showMessageDialog(this, "boutton droite "+e.getX()
+":"+e.getY());
}

@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==lbl) {
lbl.setBackground(Color.blue);
}

@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==lbl) {
lbl.setBackground(Color.green);
}

@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
System.out.println("action appui souris "+e.getX()+":"+e.getY());

@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
System.out.println("action relâcher souris "+e.getX()+":"+e.getY());

You might also like