skip to main
|
skip to sidebar
It's Crazzy 4 You
Tuesday 29 October 2013
Java Code for Dinamicaly drawing some thing - Rough
package com.ssga.invapp.col.test.e544990; import java.awt.Container; import java.awt.Cursor; import java.awt.FlowLayout; import java.awt.Point; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JFrame; import javax.swing.JTextArea; import javax.swing.JTextField; public class MyTest25 extends JFrame { private static final long serialVersionUID = -2903548059824985612L; private Point startLocation; private Point endLocation; private JTextField txtLocation; private JTextArea txtArea; public MyTest25(String windowName) { super(windowName); this.setBounds(10, 10, 500, 500); txtLocation = new JTextField(); txtLocation.setColumns(20); Container pane = this.getContentPane(); pane.setLayout(new FlowLayout()); pane.add(txtLocation); txtArea = new JTextArea(); pane.add(txtArea); } public static void main(String[] args) { MyTest25 test25 = new MyTest25("Test Window"); test25.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); } }); MyMouseAdapter mouse = new MyMouseAdapter(test25); test25.addMouseListener(mouse); test25.setVisible(true); } public void setStartLocation(Point locationOnScreen) { this.startLocation = new Point(locationOnScreen.x - getX(), locationOnScreen.y - getY()); this.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); } public void setEndLocation(Point locationOnScreen) { this.endLocation = new Point(locationOnScreen.x - getX(), locationOnScreen.y - getY()); if (startLocation.x != endLocation.x && startLocation.y != endLocation.y) { this.txtLocation.setText("(" + startLocation.x + "," + startLocation.y + ") to (" + endLocation.x + "," + endLocation.y + ")"); txtArea.setLocation(startLocation); txtArea.setSize(endLocation.x - startLocation.x, endLocation.y - startLocation.y); this.setCursor(Cursor.getDefaultCursor()); } } } class MyMouseAdapter extends MouseAdapter { private MyTest25 t25; public MyMouseAdapter(MyTest25 t25) { this.t25 = t25; } @Override public void mousePressed(MouseEvent e) { t25.setStartLocation(e.getLocationOnScreen()); } @Override public void mouseReleased(MouseEvent e) { t25.setEndLocation(e.getLocationOnScreen()); } }
Newer Posts
Older Posts
Home
Subscribe to:
Posts (Atom)
Followers
Blog Archive
▼
2013
(1)
▼
October
(1)
Java Code for Dinamicaly drawing some thing - Rough
►
2010
(3)
►
February
(3)
►
2009
(6)
►
October
(3)
►
September
(1)
►
August
(2)
About Me
manuspanicker
View my complete profile