Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Graphics2D;
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author Lab18
- */
- public class Paint extends javax.swing.JFrame {
- int x;
- int y;
- private java.awt.Graphics rysuj;
- /**
- * Creates new form Paint
- */
- public Paint() {
- initComponents();
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- linia = new javax.swing.JButton();
- mazak = new javax.swing.JButton();
- kółko = new javax.swing.JButton();
- prostokąt = new javax.swing.JButton();
- kolor = new javax.swing.JButton();
- clear = new javax.swing.JButton();
- jPanel1 = new javax.swing.JPanel();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- linia.setText("linia");
- linia.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- liniaMouseClicked(evt);
- }
- public void mousePressed(java.awt.event.MouseEvent evt) {
- liniaMousePressed(evt);
- }
- });
- linia.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- liniaActionPerformed(evt);
- }
- });
- mazak.setText("mazak");
- kółko.setText("kółko");
- kółko.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mousePressed(java.awt.event.MouseEvent evt) {
- kółkoMousePressed(evt);
- }
- });
- prostokąt.setText("prostokąt");
- prostokąt.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mousePressed(java.awt.event.MouseEvent evt) {
- prostokątMousePressed(evt);
- }
- });
- kolor.setText("kolor");
- clear.setText("clear");
- jPanel1.setBackground(new java.awt.Color(255, 255, 255));
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 625, Short.MAX_VALUE)
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 320, Short.MAX_VALUE)
- );
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addGap(14, 14, 14)
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(prostokąt, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(linia, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(mazak, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(kółko, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(kolor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(clear, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGap(101, 101, 101))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(52, 52, 52)
- .addComponent(linia)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(mazak)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(kółko)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(prostokąt)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(kolor)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(clear)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap(33, Short.MAX_VALUE)
- .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(164, 164, 164))
- );
- pack();
- }// </editor-fold>
- private void liniaActionPerformed(java.awt.event.ActionEvent evt) {
- }
- private void liniaMouseClicked(java.awt.event.MouseEvent evt) {
- }
- private void liniaMousePressed(java.awt.event.MouseEvent evt) {
- rysuj = (java.awt.Graphics)jPanel1.getGraphics();
- rysuj.drawLine(evt.getX(), evt.getY(), 100, 100);
- }
- private void kółkoMousePressed(java.awt.event.MouseEvent evt) {
- rysuj = (java.awt.Graphics)jPanel1.getGraphics();
- rysuj.drawOval(evt.getX(), evt.getY(), 100, 100);
- }
- private void prostokątMousePressed(java.awt.event.MouseEvent evt) {
- rysuj = (java.awt.Graphics)jPanel1.getGraphics();
- rysuj.drawRect(evt.getX(), evt.getY(), 100, 100);
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(Paint.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(Paint.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(Paint.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(Paint.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new Paint().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton clear;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JButton kolor;
- private javax.swing.JButton kółko;
- private javax.swing.JButton linia;
- private javax.swing.JButton mazak;
- private javax.swing.JButton prostokąt;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement