0% found this document useful (0 votes)
33 views

TP 3

This document contains code for two Java classes that create internal frames. The InternalFrameEx3_tp3 class creates a frame with buttons to display messages and text selection. The InternalFrameEx4_tp3 class creates a frame with a label that changes color on mouse events and displays messages for mouse clicks. Both classes implement interfaces to handle button and mouse click events.

Uploaded by

Iram Kasan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

TP 3

This document contains code for two Java classes that create internal frames. The InternalFrameEx3_tp3 class creates a frame with buttons to display messages and text selection. The InternalFrameEx4_tp3 class creates a frame with a label that changes color on mouse events and displays messages for mouse clicks. Both classes implement interfaces to handle button and mouse click events.

Uploaded by

Iram Kasan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 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