Advertisement
Guest User

test

a guest
Apr 26th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.67 KB | None | 0 0
  1. package hw11;
  2. import java.awt.*;
  3. import javax.swing.*;
  4. import java.awt.event.*;
  5. import java.util.Random;
  6. import javax.swing.JFrame;
  7. import javax.swing.JPanel;
  8.  
  9. class MyPainter extends JPanel implements ActionListener, MouseListener {
  10. JButton b1, b2, b3, b4, b5, b6,
  11. b7, b8, b9, b10, b11, b12,
  12. b13, b14, b15, b16, b17, b18;
  13.  
  14. String s1, s2, s3, s4, s5, s6,
  15. s7, s8, s9, s10, s11, s12,
  16. s13, s14, s15, s16, s17, s18;
  17.  
  18. boolean k = false;
  19.  
  20. MyPainter() {
  21. //setBackground(Color.GRAY);
  22.  
  23. setLayout(null);
  24.  
  25. addMouseListener(this);
  26. s1 = "h";
  27.  
  28.  
  29. b1 = new JButton();
  30. b1.setBounds(16, 48, 48, 48);
  31. b1.setFocusable(true);
  32. add(b1);
  33. b1.addActionListener(this);
  34.  
  35.  
  36.  
  37. }
  38.  
  39. public void actionPerformed(ActionEvent e) {
  40. Graphics g = getGraphics();
  41. if(e.getSource() == b1) {
  42. g.drawString(s1, 40, 72);
  43. }
  44.  
  45. // if (e.getSource() == bRed)
  46. // drawColor = Color.RED;
  47. // else if (e.getSource() == bBlue)
  48. // drawColor = Color.BLUE;
  49. // else if (e.getSource() == bLine)
  50. // drawShape = 'l';
  51. // else if (e.getSource() == bCircle)
  52. // drawShape = 'c';
  53.  
  54. }
  55.  
  56. public void mousePressed(MouseEvent e) {
  57.  
  58.  
  59. }
  60.  
  61. public void mouseReleased(MouseEvent e) {
  62.  
  63. }
  64.  
  65. public void mouseClicked(MouseEvent e) {
  66.  
  67. }
  68.  
  69. public void mouseEntered(MouseEvent e) {
  70.  
  71. }
  72.  
  73. public void mouseExited(MouseEvent e) {
  74.  
  75. }
  76.  
  77. }
  78.  
  79. public class Hw11 {
  80. public static void main(String[] args) {
  81. JFrame myWin = new JFrame("My Painter");
  82.  
  83. MyPainter mC = new MyPainter();
  84.  
  85. myWin.add(mC);
  86. myWin.setSize(800, 600);
  87. myWin.setLocation(100, 50);
  88. myWin.setVisible(true);
  89. myWin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  90. }
  91. }
  92. //
  93. //class Game extends JFrame implements ActionListener, MouseListener, MouseMotionListener {
  94. // JButton b1, b2, b3, b4, b5, b6,
  95. // b7, b8, b9, b10, b11, b12,
  96. // b13, b14, b15, b16, b17, b18;
  97. //
  98. // String s1, s2, s3, s4, s5, s6,
  99. // s7, s8, s9, s10, s11, s12,
  100. // s13, s14, s15, s16, s17, s18;
  101. //
  102. //
  103. //
  104. // Game() {
  105. //// setLayout(null);
  106. //// addMouseListener(this);
  107. //// addMouseMotionListener(this);
  108. ////
  109. //// b1 = new JButton();
  110. //// b1.setBounds(0, 48, 48, 48);
  111. //// b1.setFocusable(false);
  112. //// add(b1);
  113. //// b1.addActionListener(this);
  114. ////
  115. // }
  116. //
  117. // public void actionPerformed(ActionEvent e) {
  118. //// if (e.getSource() == bRed)
  119. //// drawColor = Color.RED;
  120. //// else if (e.getSource() == bBlue)
  121. //// drawColor = Color.BLUE;
  122. //// else if (e.getSource() == bLine)
  123. //// drawShape = 'l';
  124. //// else if (e.getSource() == bCircle)
  125. //// drawShape = 'c';
  126. //
  127. // }
  128. //
  129. // void Create(int c) {
  130. // s1 = ""+(char)c;
  131. // c--;
  132. // if(c < 97)
  133. // c = c+'r'-'a'+1;
  134. // s2 = ""+(char)c;
  135. // c--;
  136. // if(c < 97)
  137. // c = c+'r'-'a'+1;
  138. // s3 = ""+(char)c;
  139. // c--;
  140. // if(c < 97)
  141. // c = c+'r'-'a'+1;
  142. // s4 = ""+(char)c;
  143. // c--;
  144. // if(c < 97)
  145. // c = c+'r'-'a'+1;
  146. // s5 = ""+(char)c;
  147. // c--;
  148. // if(c < 97)
  149. // c = c+'r'-'a'+1;
  150. // s6 = ""+(char)c;
  151. // c--;
  152. // if(c < 97)
  153. // c = c+'r'-'a'+1;
  154. // s7 = ""+(char)c;
  155. // c--;
  156. // if(c < 97)
  157. // c = c+'r'-'a'+1;
  158. // s8 = ""+(char)c;
  159. // c--;
  160. // if(c < 97)
  161. // c = c+'r'-'a'+1;
  162. // s9 = ""+(char)c;
  163. // c--;
  164. // if(c < 97)
  165. // c = c+'r'-'a'+1;
  166. // s10 = ""+(char)c;
  167. // c--;
  168. // if(c < 97)
  169. // c = c+'r'-'a'+1;
  170. // s11 = ""+(char)c;
  171. // c--;
  172. // if(c < 97)
  173. // c = c+'r'-'a'+1;
  174. // s12 = ""+(char)c;
  175. // c--;
  176. // if(c < 97)
  177. // c = c+'r'-'a'+1;
  178. // s13 = ""+(char)c;
  179. // c--;
  180. // if(c < 97)
  181. // c = c+'r'-'a'+1;
  182. // s14 = ""+(char)c;
  183. // c--;
  184. // if(c < 97)
  185. // c = c+'r'-'a'+1;
  186. // s15 = ""+(char)c;
  187. // c--;
  188. // if(c < 97)
  189. // c = c+'r'-'a'+1;
  190. // s16 = ""+(char)c;
  191. // c--;
  192. // if(c < 97)
  193. // c = c+'r'-'a'+1;
  194. // s17 = ""+(char)c;
  195. // c--;
  196. // if(c < 97)
  197. // c = c+'r'-'a'+1;
  198. // s18 = ""+(char)c;
  199. // c--;
  200. // }
  201. //
  202. //
  203. //
  204. //
  205. // public void mousePressed(MouseEvent e) {
  206. //
  207. // }
  208. //
  209. // public void mouseReleased(MouseEvent e) {
  210. //
  211. // }
  212. //
  213. // public void mouseClicked(MouseEvent e) {
  214. //
  215. // }
  216. //
  217. // public void mouseEntered(MouseEvent e) {
  218. //
  219. // }
  220. //
  221. // public void mouseExited(MouseEvent e) {
  222. //
  223. // }
  224. //
  225. // public void mouseMoved(MouseEvent e) {
  226. //
  227. // }
  228. //
  229. // public void mouseDragged(MouseEvent e) {
  230. //
  231. // }
  232. //
  233. //}
  234. //
  235. //
  236. //public class Hw11 extends JPanel {
  237. //
  238. //
  239. // public void paint(Graphics g) {
  240. //
  241. //
  242. // }
  243. //
  244. // public static void main(String[] args) {
  245. //// JFrame frame = new JFrame();
  246. //// frame.getContentPane().add(new Hw11());
  247. ////
  248. //// frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  249. //// frame.setSize(500,500);
  250. //// frame.setVisible(true);
  251. ////
  252. //// Random rnd = new Random();
  253. //// int c = ('r'-rnd.nextInt(19));
  254. ////
  255. //// Game gm = new Game();
  256. //// gm.Create(c);
  257. ////
  258. // JFrame myWin = new JFrame("My Painter");
  259. //
  260. // Game mC = new Game();
  261. //
  262. // myWin.add(mC);
  263. // myWin.setSize(800, 600);
  264. // myWin.setLocation(100, 50);
  265. // myWin.setVisible(true);
  266. // myWin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  267. // Random rnd = new Random();
  268. // int c = ('r'-rnd.nextInt(19));
  269. //
  270. // Game gm = new Game();
  271. // gm.Create(c);
  272. //
  273. //
  274. //s1 = ""+(char)c;
  275. // c--;
  276. // if(c < 97)
  277. // c = c+'r'-'a'+1;
  278. // s2 = ""+(char)c;
  279. // c--;
  280. // if(c < 97)
  281. // c = c+'r'-'a'+1;
  282. // s3 = ""+(char)c;
  283. // c--;
  284. // if(c < 97)
  285. // c = c+'r'-'a'+1;
  286. // s4 = ""+(char)c;
  287. // c--;
  288. // if(c < 97)
  289. // c = c+'r'-'a'+1;
  290. // s5 = ""+(char)c;
  291. // c--;
  292. // if(c < 97)
  293. // c = c+'r'-'a'+1;
  294. // s6 = ""+(char)c;
  295. // c--;
  296. // if(c < 97)
  297. // c = c+'r'-'a'+1;
  298. // s7 = ""+(char)c;
  299. // c--;
  300. // if(c < 97)
  301. // c = c+'r'-'a'+1;
  302. // s8 = ""+(char)c;
  303. // c--;
  304. // if(c < 97)
  305. // c = c+'r'-'a'+1;
  306. // s9 = ""+(char)c;
  307. // c--;
  308. // if(c < 97)
  309. // c = c+'r'-'a'+1;
  310. // s10 = ""+(char)c;
  311. // c--;
  312. // if(c < 97)
  313. // c = c+'r'-'a'+1;
  314. // s11 = ""+(char)c;
  315. // c--;
  316. // if(c < 97)
  317. // c = c+'r'-'a'+1;
  318. // s12 = ""+(char)c;
  319. // c--;
  320. // if(c < 97)
  321. // c = c+'r'-'a'+1;
  322. // s13 = ""+(char)c;
  323. // c--;
  324. // if(c < 97)
  325. // c = c+'r'-'a'+1;
  326. // s14 = ""+(char)c;
  327. // c--;
  328. // if(c < 97)
  329. // c = c+'r'-'a'+1;
  330. // s15 = ""+(char)c;
  331. // c--;
  332. // if(c < 97)
  333. // c = c+'r'-'a'+1;
  334. // s16 = ""+(char)c;
  335. // c--;
  336. // if(c < 97)
  337. // c = c+'r'-'a'+1;
  338. // s17 = ""+(char)c;
  339. // c--;
  340. // if(c < 97)
  341. // c = c+'r'-'a'+1;
  342. // s18 = ""+(char)c;
  343. // c--;
  344. //
  345. //
  346. // System.out.println(s1);
  347. // System.out.println(s2);
  348. // System.out.println(s3);
  349. // System.out.println(s4);
  350. // System.out.println(s5);
  351. // System.out.println(s6);
  352. // System.out.println(s7);
  353. // System.out.println(s8);
  354. // System.out.println(s9);
  355. // System.out.println(s10);
  356. // System.out.println(s11);
  357. // System.out.println(s12);
  358. // System.out.println(s13);
  359. // System.out.println(s14);
  360. // System.out.println(s15);
  361. // System.out.println(s16);
  362. // System.out.println(s17);
  363. // System.out.println(s18);
  364. //
  365. // int c = ('r'-rnd.nextInt(19));
  366. // if(c < 'a' - 0)
  367. // c = 'a' + c + 1;
  368. //
  369. // System.out.println((char)c);
  370. //
  371. // System.out.println();
  372. //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement