Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.02 KB | None | 0 0
  1. import java.awt.Graphics2D;
  2.  
  3. /*
  4. * To change this template, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7.  
  8. /**
  9. *
  10. * @author Lab18
  11. */
  12. public class Paint extends javax.swing.JFrame {
  13. int x;
  14. int y;
  15. private java.awt.Graphics rysuj;
  16.  
  17. /**
  18. * Creates new form Paint
  19. */
  20. public Paint() {
  21. initComponents();
  22. }
  23.  
  24. /**
  25. * This method is called from within the constructor to initialize the form.
  26. * WARNING: Do NOT modify this code. The content of this method is always
  27. * regenerated by the Form Editor.
  28. */
  29. @SuppressWarnings("unchecked")
  30. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  31. private void initComponents() {
  32.  
  33. linia = new javax.swing.JButton();
  34. mazak = new javax.swing.JButton();
  35. kółko = new javax.swing.JButton();
  36. prostokąt = new javax.swing.JButton();
  37. kolor = new javax.swing.JButton();
  38. clear = new javax.swing.JButton();
  39. jPanel1 = new javax.swing.JPanel();
  40.  
  41. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  42.  
  43. linia.setText("linia");
  44. linia.addMouseListener(new java.awt.event.MouseAdapter() {
  45. public void mouseClicked(java.awt.event.MouseEvent evt) {
  46. liniaMouseClicked(evt);
  47. }
  48. public void mousePressed(java.awt.event.MouseEvent evt) {
  49. liniaMousePressed(evt);
  50. }
  51. });
  52. linia.addActionListener(new java.awt.event.ActionListener() {
  53. public void actionPerformed(java.awt.event.ActionEvent evt) {
  54. liniaActionPerformed(evt);
  55. }
  56. });
  57.  
  58. mazak.setText("mazak");
  59.  
  60. kółko.setText("kółko");
  61. kółko.addMouseListener(new java.awt.event.MouseAdapter() {
  62. public void mousePressed(java.awt.event.MouseEvent evt) {
  63. kółkoMousePressed(evt);
  64. }
  65. });
  66.  
  67. prostokąt.setText("prostokąt");
  68. prostokąt.addMouseListener(new java.awt.event.MouseAdapter() {
  69. public void mousePressed(java.awt.event.MouseEvent evt) {
  70. prostokątMousePressed(evt);
  71. }
  72. });
  73.  
  74. kolor.setText("kolor");
  75.  
  76. clear.setText("clear");
  77.  
  78. jPanel1.setBackground(new java.awt.Color(255, 255, 255));
  79.  
  80. javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  81. jPanel1.setLayout(jPanel1Layout);
  82. jPanel1Layout.setHorizontalGroup(
  83. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  84. .addGap(0, 625, Short.MAX_VALUE)
  85. );
  86. jPanel1Layout.setVerticalGroup(
  87. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  88. .addGap(0, 320, Short.MAX_VALUE)
  89. );
  90.  
  91. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  92. getContentPane().setLayout(layout);
  93. layout.setHorizontalGroup(
  94. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  95. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  96. .addGap(14, 14, 14)
  97. .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  98. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  99. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  100. .addComponent(prostokąt, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  101. .addComponent(linia, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  102. .addComponent(mazak, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  103. .addComponent(kółko, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  104. .addComponent(kolor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  105. .addComponent(clear, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  106. .addGap(101, 101, 101))
  107. );
  108. layout.setVerticalGroup(
  109. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  110. .addGroup(layout.createSequentialGroup()
  111. .addGap(52, 52, 52)
  112. .addComponent(linia)
  113. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  114. .addComponent(mazak)
  115. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  116. .addComponent(kółko)
  117. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  118. .addComponent(prostokąt)
  119. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  120. .addComponent(kolor)
  121. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  122. .addComponent(clear)
  123. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  124. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  125. .addContainerGap(33, Short.MAX_VALUE)
  126. .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  127. .addGap(164, 164, 164))
  128. );
  129.  
  130. pack();
  131. }// </editor-fold>
  132.  
  133. private void liniaActionPerformed(java.awt.event.ActionEvent evt) {
  134.  
  135.  
  136. }
  137.  
  138. private void liniaMouseClicked(java.awt.event.MouseEvent evt) {
  139.  
  140. }
  141.  
  142. private void liniaMousePressed(java.awt.event.MouseEvent evt) {
  143. rysuj = (java.awt.Graphics)jPanel1.getGraphics();
  144. rysuj.drawLine(evt.getX(), evt.getY(), 100, 100);
  145. }
  146.  
  147. private void kółkoMousePressed(java.awt.event.MouseEvent evt) {
  148. rysuj = (java.awt.Graphics)jPanel1.getGraphics();
  149. rysuj.drawOval(evt.getX(), evt.getY(), 100, 100);
  150. }
  151.  
  152. private void prostokątMousePressed(java.awt.event.MouseEvent evt) {
  153. rysuj = (java.awt.Graphics)jPanel1.getGraphics();
  154. rysuj.drawRect(evt.getX(), evt.getY(), 100, 100);
  155. }
  156.  
  157. /**
  158. * @param args the command line arguments
  159. */
  160. public static void main(String args[]) {
  161. /* Set the Nimbus look and feel */
  162. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  163. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  164. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  165. */
  166. try {
  167. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  168. if ("Nimbus".equals(info.getName())) {
  169. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  170. break;
  171. }
  172. }
  173. } catch (ClassNotFoundException ex) {
  174. java.util.logging.Logger.getLogger(Paint.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  175. } catch (InstantiationException ex) {
  176. java.util.logging.Logger.getLogger(Paint.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  177. } catch (IllegalAccessException ex) {
  178. java.util.logging.Logger.getLogger(Paint.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  179. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  180. java.util.logging.Logger.getLogger(Paint.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  181. }
  182. //</editor-fold>
  183.  
  184. /* Create and display the form */
  185. java.awt.EventQueue.invokeLater(new Runnable() {
  186. public void run() {
  187. new Paint().setVisible(true);
  188. }
  189. });
  190. }
  191. // Variables declaration - do not modify
  192. private javax.swing.JButton clear;
  193. private javax.swing.JPanel jPanel1;
  194. private javax.swing.JButton kolor;
  195. private javax.swing.JButton kółko;
  196. private javax.swing.JButton linia;
  197. private javax.swing.JButton mazak;
  198. private javax.swing.JButton prostokąt;
  199. // End of variables declaration
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement