Best Projects

Bug Trackingsystem,Books online shopping,college management system,HR management system,Internet banking,Online chat room ,Online exam,Telephone billing system,Banking application,ATM database,airways reservation system,virtual network computing ,calculator,SMTP(simple mail transfer protocol)

Magnifier (VERY NICE)JAR

Description: Magnifier lens that provides a way to enlarge items on the screen.

//Magnifierwindow
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;

public class MagnifierWindow extends JFrame{
private Container container = getContentPane();
private JPopupMenu popupMenu = new JPopupMenu();
private JMenuItem menuRefresh = new JMenuItem("Refresh");
private JMenuItem menuHide = new JMenuItem("Hide");
private JMenu menuSize = new JMenu("Size");
private JMenuItem menu100Pixels = new JMenuItem("100 Pixels");
private JMenuItem menu200Pixels = new JMenuItem("200 Pixels");
private JMenu menuHelp = new JMenu("Help");
private JMenuItem menuHow = new JMenuItem("How to use");
private JMenuItem menuSite = new JMenuItem("Visit web site");
private JMenuItem menuAbout = new JMenuItem("About");
private JMenuItem menuExit = new JMenuItem("Exit");

private TimeUpdate timeUpdate = new TimeUpdate();
private int timeUpdateDelay = 10;
private int onScreenMoveDidectionUp = 1;
private int onScreenMoveDidectionDown = -1;
private int onScreenMoveDidectionX = onScreenMoveDidectionUp;
private int onScreenMoveDidectionY = onScreenMoveDidectionUp;

private int setCoordinateX;
private int setCoordinateY;
private int absoluteCoordinateX;
private int absoluteCoordinateY;
private int relativeCoordinateXWhenMousePressed;
private int relativeCoordinateYWhenMousePressed;
private boolean mousePressedNow;
private boolean magnifierStopped;

private ConfigData configData = new ConfigData();

private int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
private int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
private int magnifierSize = 100;

private MagnifierPanel magnifierPanel = new MagnifierPanel(magnifierSize);
private Image magnifierIcon;

private int updateScreenDelay = 500;

public MagnifierWindow(String windowTitle){
super(windowTitle);
magnifierIcon = new ImageIcon(MagnifierIcon.magnifierIcon).getImage();
setIconImage(magnifierIcon);
setUndecorated(true);

container.add(magnifierPanel);
addMouseListener(new MouseFunctions());
addMouseMotionListener(new MouseMotionFunctions());
timeUpdate.start();
menuRefresh.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
updateScreen();
}
}
);
menuHide.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
setState(JFrame.ICONIFIED);
}
}
);
menu100Pixels.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
magnifierSize = 100;
updateSize(magnifierSize);
}
}
);
menu200Pixels.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
magnifierSize = 200;
updateSize(magnifierSize);
}
}
);
menuHow.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane jOptionPane = new JOptionPane();
JTextArea jTextArea = new JTextArea();
jTextArea.setText("1.Single click on left mouse button stops magnifier movement.\n" +
"2.Double click on left mouse button starts magnifier movement.\n" +
"3.Single click on right mouse button stops magnifier movement and shows menu.\n" +
"4.Move magnifier by click on left mouse button on it and drag to desired place.\n" +
"5.Refresh option in the menu is needed to update last screen status.\n" +
"6.Hide option in the menu is needed to minimize magnifier");
jOptionPane.showMessageDialog(null,
jTextArea,
"How to use magnifier",
JOptionPane.INFORMATION_MESSAGE);
}
}
);
menuSite.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane jOptionPane = new JOptionPane();
JTextField jTextField = new JTextField();
jTextField.setText("http://softcollection.sytes.net/javaprog");
jOptionPane.showMessageDialog(null,
jTextField,
"Please visit web site!",
JOptionPane.INFORMATION_MESSAGE);
}
}
);
menuAbout.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null,"Magnifier v1.14","About",JOptionPane.INFORMATION_MESSAGE);
}
}
);
menuExit.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
}
);
popupMenu.add(menuRefresh);
popupMenu.add(menuHide);
popupMenu.add(menuSize);
menuSize.add(menu100Pixels);
menuSize.add(menu200Pixels);
popupMenu.add(menuHelp);
menuHelp.add(menuHow);
menuHelp.add(menuSite);
menuHelp.add(menuAbout);
popupMenu.add(menuExit);

updateSize(magnifierSize);
openFile();
show();
}

public void updateSize(int magnifierSize){
magnifierPanel.setMagnifierSize(magnifierSize);
setSize(magnifierSize,magnifierSize);
validate();
}

public void updateScreen(){
hide();
try{Thread.sleep(updateScreenDelay);} catch(InterruptedException e){}
magnifierPanel.getScreen();
show();
}

private class TimeUpdate extends Thread{
public void run(){
while(true){
if (magnifierStopped == false){
setCoordinateX += onScreenMoveDidectionX;
setCoordinateY += onScreenMoveDidectionY;
if (setCoordinateX < 0) onScreenMoveDidectionX = onScreenMoveDidectionUp;
if (setCoordinateY < 0) onScreenMoveDidectionY = onScreenMoveDidectionUp;
if (setCoordinateX > (screenWidth-magnifierSize)) onScreenMoveDidectionX = onScreenMoveDidectionDown;
if (setCoordinateY > (screenHeight-magnifierSize)) onScreenMoveDidectionY = onScreenMoveDidectionDown;
magnifierPanel.setMagnifierLocation(setCoordinateX,setCoordinateY);
setLocation(setCoordinateX,setCoordinateY);
}
try{Thread.sleep(timeUpdateDelay);} catch(InterruptedException e){}
}
}
}


private class MouseFunctions extends MouseAdapter{
public void mousePressed(MouseEvent e){
if (e.getClickCount()==1){
mousePressedNow = true;
relativeCoordinateXWhenMousePressed=e.getX();
relativeCoordinateYWhenMousePressed=e.getY();
magnifierStopped = true;
}
if (e.getButton()==MouseEvent.BUTTON1&&e.getClickCount()==2){
magnifierStopped = false;
}
}
public void mouseReleased(MouseEvent e){
mousePressedNow = false;
saveFile();
if (e.isPopupTrigger()){
popupMenu.show(e.getComponent(),e.getX(),e.getY());
}
}
}

private class MouseMotionFunctions extends MouseMotionAdapter{
public void mouseDragged(MouseEvent e){
if (mousePressedNow == true){
absoluteCoordinateX = MagnifierWindow.this.getLocationOnScreen().x + e.getX();
absoluteCoordinateY = MagnifierWindow.this.getLocationOnScreen().y + e.getY();
setCoordinateX = absoluteCoordinateX-relativeCoordinateXWhenMousePressed;
setCoordinateY = absoluteCoordinateY-relativeCoordinateYWhenMousePressed;
magnifierPanel.setMagnifierLocation(setCoordinateX,setCoordinateY);
setLocation(setCoordinateX,setCoordinateY);
}
}
}

public void saveFile(){
ObjectOutputStream out;
configData.magnifierXCoordinate = getLocation().x;
configData.magnifierYCoordinate = getLocation().y;
configData.magnifierSizeInPixels = magnifierSize;
try{
out = new ObjectOutputStream(new FileOutputStream("Magnifier.cfg"));
out.writeObject(configData);
out.flush();
out.close();
}
catch(IOException e){}
}

public void openFile(){
ObjectInputStream in;
try{
in = new ObjectInputStream(new FileInputStream("Magnifier.cfg"));
try{
configData = (ConfigData)in.readObject();
setCoordinateX = configData.magnifierXCoordinate;
setCoordinateY = configData.magnifierYCoordinate;
magnifierSize = configData.magnifierSizeInPixels;
updateSize(magnifierSize);
}
catch(ClassNotFoundException e){}
catch(IOException e){}
in.close();
}
catch(IOException e){}
}
}

class ConfigData implements Serializable{
public int magnifierXCoordinate;
public int magnifierYCoordinate;
public int magnifierSizeInPixels;
}






//magnifierPanel
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.geom.*;

public class MagnifierPanel extends JPanel{
private Image screenImage;
private int magnifierSize;
private int locationX;
private int locationY;
private Area circle1;
private Area circle2;
private Area circle3;
private Area circle4;
private Area circle5;
private Area rectangle1;
private Color brightGlassColor;
private Color darkGlassColor;
private Color lightInGlassColor;
private Robot robot;

public MagnifierPanel(int magnifierSize){
try{robot = new Robot();} catch(AWTException e){}
getScreen();
setMagnifierSize(magnifierSize);
}

public void setMagnifierLocation(int locationX,int locationY){
this.locationX = locationX;
this.locationY = locationY;
updateMagnifierPicture();
}

public void setImage(Image screenImage){
this.screenImage = screenImage;
updateMagnifierPicture();
}

public void getScreen(){
screenImage = robot.createScreenCapture(new Rectangle(0,0,Toolkit.getDefaultToolkit().getScreenSize().width,Toolkit.getDefaultToolkit().getScreenSize().height));
}

public void setMagnifierSize(int magnifierSize){
this.magnifierSize = magnifierSize;
circle1 = new Area(new Ellipse2D.Double(0,0,magnifierSize,magnifierSize));
circle2 = new Area(new Ellipse2D.Double((magnifierSize/5),(magnifierSize/5),(magnifierSize/10*11),(magnifierSize/10*11)));
circle3 = new Area(new Ellipse2D.Double(0,0,magnifierSize,magnifierSize));
circle4 = new Area(new Ellipse2D.Double((magnifierSize/5),(magnifierSize/5),(magnifierSize/10*11),(magnifierSize/10*11)));
circle5 = new Area(new Ellipse2D.Double(0,0,magnifierSize,magnifierSize));
rectangle1 = new Area(new Rectangle2D.Double(0,0,magnifierSize,magnifierSize));
rectangle1.subtract(circle5);
circle1.subtract(circle2);
circle3.intersect(circle4);
brightGlassColor = new Color(140,140,140,50);
darkGlassColor = new Color(100,100,100,50);
lightInGlassColor = new Color(255,255,255,100);
setPreferredSize(new Dimension(magnifierSize,magnifierSize));
if (getParent() != null) getParent().repaint();
updateMagnifierPicture();
}

public void updateMagnifierPicture(){
if (getParent() != null) getParent().repaint();
else repaint();
}

public void paintComponent(Graphics g){
super.paintComponent((Graphics2D)g);
drawScreenRectangle((Graphics2D)g);
}
private void drawScreenRectangle(Graphics2D g){
g.setClip(rectangle1);
g.drawImage(screenImage,
0,
0,
magnifierSize,
magnifierSize,
locationX,
locationY,
locationX+magnifierSize,
locationY+magnifierSize,
this);
g.setClip(circle5);
g.drawImage(screenImage,
0,
0,
magnifierSize,
magnifierSize,
locationX+(magnifierSize/4),
locationY+(magnifierSize/4),
locationX+(magnifierSize/4*3),
locationY+(magnifierSize/4*3),
this);
g.setColor(darkGlassColor);
g.fill(circle1);
g.setColor(brightGlassColor);
g.fill(circle3);
g.setColor(lightInGlassColor);
g.fillOval((magnifierSize/5),(magnifierSize/5),(magnifierSize/10),(magnifierSize/10));
}
}




//magnifiericon
public class MagnifierIcon{
public static byte magnifierIcon[]={
71,73,70,56,57,97,16,0,16,0,-111,0,0,0,0,0,-1,-1,-1,
-25,-25,-25,-1,-1,-1,33,-7,4,1,0,0,3,0,44,0,0,0,0,16,
0,16,0,0,2,43,-100,45,-87,-57,-93,-65,24,-100,-30,80,-118,82,-104,-95,
7,71,121,-30,-58,-115,94,105,118,80,42,-82,-84,-86,-68,30,40,-56,31,109,
91,-11,-37,-20,105,115,48,53,10,0,59
};
}



//magnifier
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Magnifier{
public static void main(String arg[]){
MagnifierWindow magnifierWindow = new MagnifierWindow("Magnifier");
}
}

No comments: