Uploaded by Haseeb Ur Rehman

Assignment 6( MPL, Haseeb ur rehman,17-arid1320)

advertisement
University Institute of Information Technology
_____________________________________________________________________________________
Subject Title:
Modern Programming Language(MPL)
Assignment # 6
Submitted By:
Haseeb ur rehman 17-Arid-1320
Submitted To:
Sir Bilal Bashir
Submittion Date:
18-May-2020
________________________________________________________________
University Institute of Information Technology Rawalpindi
/*
* To change this license header, choose License Headers in
Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package assignment.pkg6;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
/**
*
* @author Haseeb ur Rehman
*/
public class Assgn_no_6 {
private Random d = new Random();
public Assgn_no_6 () {
JFrame frame = new JFrame();
JPanel panel = new JPanel();
panel.add(createButton());
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 300);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
private JButton createButton() {
final JButton button = new JButton("Button");
button.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
int a = d.nextInt(200);
int b = d.nextInt(200);
button.setLocation(a, b);
}
});
return button;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new Assgn_no_6();
}
});
}
}
Download