1 //* Example of Stroke in JAVA *
2 // by Luciano da Silva Ribas
3 // license under GNU General Public License
4 
5 import java.awt.*;
6 import java.awt.event.*;
7 import java.math.*;
8 
9 public class Paint extends Frame implements WindowListener, MouseListener,MouseMotionListener, ActionListener {
10 	public static Canvas c;
11 	public static Graphics g;
12 	public static int xp;
13 	public static int yp;
14 	public Color cor = Color.black;
15 	public Stroke MyStroke;
16 
17 	public static int figura = 1;
18 	public static int rect_lx = 50;
19 	public static int rect_ly = 50;
20 	public static int circ_s = 100;
21 
main(String args[])22 	public static void main(String args[]){
23 		Paint i = new Paint("Paint");
24 	}
25 
Paint(String t)26 	public Paint(String t){
27 		super(t);
28 		this.setSize(500,500);
29 		this.setLocation(100,100);
30 		this.setVisible(true);
31 
32 		MyStroke = new Stroke();
33 
34 		MenuBar mbar = new MenuBar();
35 		Menu menuAbout = new Menu("About");
36 		MenuItem miAbout = new MenuItem("About..");
37 		miAbout.addActionListener(this);
38       mbar.add(menuAbout);
39       menuAbout.add(miAbout);
40 		this.setMenuBar(mbar);
41 
42 		c = new Canvas();
43 		this.add(c);
44 
45 		c.addMouseListener(this);
46 		c.addMouseMotionListener(this);
47 
48 		this.addWindowListener(this);
49 		this.show();
50 
51       System.out.println("\nLASD/CEFETPR\nTMN Project - Telecommunications Management Network\n\nAuthor: Luciano da Silva Ribas  ribas@lasd.cefetpr.br\n");
52 		System.out.println("Strokes actived.");
53 		System.out.println("\t1  2  3\n\t4  5  6\n\t7  8  9\n");
54 		System.out.println("to change color:");
55 		System.out.println("\t456 - Black");
56 		System.out.println("\t654 - Blue");
57 		System.out.println("\t258 - Yellow");
58 		System.out.println("\t852 - Red\n");
59     	System.out.println("to change draw:");
60 		System.out.println("\t78963 - Oval");
61 		System.out.println("\t14789 - Rectangle\n");
62   	   System.out.println("to change size:");
63 		System.out.println("\t357 - Zoom-in");
64 		System.out.println("\t753 - Zoom-out\n");
65 
66 		System.out.println("detected:");
67 
68 		Draw();
69 	}
70 
71 
Draw()72 	public void Draw() {
73 
74 if( figura==1) {
75 			g=c.getGraphics();
76 			g.setColor(Color.white);
77 			g.fillRect(0,0,500,500);
78 			g.setColor(cor);
79 			g.fillOval(200,200,circ_s,circ_s);
80 			}
81 
82 	if( figura==2) {
83 			g=c.getGraphics();
84 			g.setColor(Color.white);
85 			g.fillRect(0,0,500,500);
86 			g.setColor(cor);
87 			g.fillRect(200-rect_lx,200-rect_ly,200+rect_lx,200+rect_ly);
88 			}
89 	}
90 
actionPerformed( ActionEvent a)91 	public void actionPerformed( ActionEvent a){
92 		String comand=a.getActionCommand();
93 		if(comand.equals("About.."))
94       System.out.println("\nLASD/CEFETPR\nTMN Project - Telecommunications Management Network\n\nAuthor: Luciano da Silva Ribas  ribas@lasd.cefetpr.br\n");
95 	}
96 
mousePressed(MouseEvent m)97 	public void mousePressed(MouseEvent m){
98 		xp = m.getX();
99 		yp = m.getY();
100 		g=c.getGraphics();
101 		g.setColor(cor);
102 		g.drawLine(xp,yp,xp,yp);
103 	}
104 
mouseReleased(MouseEvent m)105 	public void mouseReleased(MouseEvent m){
106 		String Result;
107 		Result = MyStroke.stroke_trans();
108 		System.out.print("----> ["+Result+"] .. ");
109 
110 		if (Result.equals("456")) {
111 		  cor = Color.black;
112 		  System.out.println("color black.");
113 		} else
114 		if (Result.equals("654")) {
115 		  cor = Color.blue;
116 		  System.out.println("color blue.");
117 		} else
118 		if (Result.equals("258")) {
119 		  cor = Color.yellow;
120 		  System.out.println("color yellow.");
121 		} else
122 		if (Result.equals("852")) {
123 		  cor = Color.red;
124 		  System.out.println("color red.");
125 		} else
126 		if (Result.equals("78963")) {
127 		  figura = 1;
128 		  System.out.println("draw circle.");
129 		} else
130 		if (Result.equals("14789")) {
131 		  figura = 2;
132 		  System.out.println("draw rectangle.");
133 		} else
134 		if (Result.equals("357")) {
135 		  rect_lx *= 2;
136 		  rect_ly *= 2;
137 		  circ_s *= 2;
138 		  System.out.println("ZOOM IN.");
139 		} else
140 		if (Result.equals("753")) {
141 		  rect_lx = (int) rect_lx/2;
142 		  rect_ly = (int) rect_ly/2;
143 		  circ_s = (int) circ_s/2;
144 		  System.out.println("ZOOM OUT.");
145 		} else {
146 		System.out.println("stroke not recognizable.");}
147 
148 		Draw();
149 	}
150 
mouseEntered(MouseEvent m)151 	public void mouseEntered(MouseEvent m){}
mouseExited(MouseEvent m)152 	public void mouseExited(MouseEvent m){}
mouseClicked(MouseEvent m)153 	public void mouseClicked(MouseEvent m){}
154 
mouseDragged(MouseEvent m)155 	public void mouseDragged(MouseEvent m){
156 		int x=m.getX();
157 		int y=m.getY();
158 		g=c.getGraphics();
159 		g.setColor(Color.black);
160 		g.drawLine(x,y,xp,yp);
161 		xp=x;
162 		yp=y;
163 		MyStroke.stroke_record( x, y );
164 	}
165 
mouseMoved(MouseEvent m)166 	public void mouseMoved(MouseEvent m){}
167 
windowClosing(WindowEvent e)168 	public void windowClosing (WindowEvent e){
169 		System.exit(0);}
windowOpened(WindowEvent e)170 	public void windowOpened (WindowEvent e){}
windowIconified(WindowEvent e)171 	public void windowIconified (WindowEvent e){}
windowDeiconified(WindowEvent e)172 	public void windowDeiconified (WindowEvent e){}
windowClosed(WindowEvent e)173  	public void windowClosed (WindowEvent e){}
windowActivated(WindowEvent e)174  	public void windowActivated (WindowEvent e){}
windowDeactivated(WindowEvent e)175 	public void windowDeactivated (WindowEvent e){}
176 }
177 
178