SHARE
TWEET

Untitled

a guest Dec 8th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. package dip107;
  8.  
  9. import java.awt.Graphics;
  10.  
  11. /**
  12.  *
  13.  * @author krist
  14.  */
  15. public class NewJFrame extends javax.swing.JFrame {
  16. public void NewJFrame() {
  17. Graphics g=jPanel1.getGraphics();
  18. int w=jPanel1.getWidth();
  19. int h=jPanel1.getHeight();
  20. int xc=w/2;
  21. int yc=h/2;
  22. g.drawLine(0,0,w,h);
  23. g.drawLine(0,yc,w,yc);
  24. g.drawLine(xc,0,xc,h);
  25. g.drawLine(0,h,w,0);
  26. int R=Integer.parseInt(jTextField1.getText());
  27. int xk=0;
  28. int yk=R;
  29. int Pk=1-R;
  30. while(xk<=yk)
  31. {
  32. if (Pk<0)    
  33. {
  34. xk ++;
  35. Pk=Pk+2*xk+1;
  36. }
  37. else
  38. {
  39. xk++;
  40. yk--;
  41. Pk=Pk+2*xk+1-2*yk;
  42.      
  43. }
  44. }
  45. g.drawRect(xk+xc,yk+yc,1,1);
  46. g.drawRect(-yk+xc,xk+yc,1,1);
  47. g.drawRect(-xk+xc,-yk+yc,1,1);
  48. g.drawRect(yk+xc,-xk+yc,1,1);
  49. g.drawRect(-yk+xc,-xk+yc,1,1);
  50. g.drawRect(-xk+xc,yk+yc,1,1);
  51. g.drawRect(yk+xc,xk+yc,1,1);
  52. g.drawRect(xk+xc,-yk+yc,1,1);
  53. }
  54. public NewJFrame() {
  55.         initComponents();
  56.        
  57.     }
  58.     /** This method is called from within the constructor to
  59.      * initialize the form.
  60.      * WARNING: Do NOT modify this code. The content of this method is
  61.      * always regenerated by the Form Editor.
  62.      */
  63.     @SuppressWarnings("unchecked")
  64.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  65.     private void initComponents() {
  66.  
  67.         jPanel1 = new javax.swing.JPanel();
  68.         jButton1 = new javax.swing.JButton();
  69.         jLabel1 = new javax.swing.JLabel();
  70.         jTextField1 = new javax.swing.JTextField();
  71.  
  72.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  73.  
  74.         jPanel1.setBackground(new java.awt.Color(255, 255, 255));
  75.  
  76.         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  77.         jPanel1.setLayout(jPanel1Layout);
  78.         jPanel1Layout.setHorizontalGroup(
  79.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  80.             .addGap(0, 350, Short.MAX_VALUE)
  81.         );
  82.         jPanel1Layout.setVerticalGroup(
  83.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  84.             .addGap(0, 260, Short.MAX_VALUE)
  85.         );
  86.  
  87.         jButton1.setText("Aiziet!");
  88.  
  89.         jLabel1.setText("R=");
  90.  
  91.         jTextField1.setText("100");
  92.         jTextField1.addActionListener(new java.awt.event.ActionListener() {
  93.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  94.                 jTextField1ActionPerformed(evt);
  95.             }
  96.         });
  97.  
  98.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  99.         getContentPane().setLayout(layout);
  100.         layout.setHorizontalGroup(
  101.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  102.             .addGroup(layout.createSequentialGroup()
  103.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  104.                     .addGroup(layout.createSequentialGroup()
  105.                         .addGap(21, 21, 21)
  106.                         .addComponent(jLabel1)
  107.                         .addGap(159, 159, 159)
  108.                         .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  109.                         .addGap(18, 18, 18)
  110.                         .addComponent(jButton1))
  111.                     .addGroup(layout.createSequentialGroup()
  112.                         .addContainerGap()
  113.                         .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
  114.                 .addContainerGap(40, Short.MAX_VALUE))
  115.         );
  116.         layout.setVerticalGroup(
  117.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  118.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  119.                 .addContainerGap()
  120.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  121.                     .addComponent(jButton1)
  122.                     .addComponent(jLabel1)
  123.                     .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  124.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  125.                 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  126.         );
  127.  
  128.         pack();
  129.     }// </editor-fold>                        
  130.  
  131.     private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {                                            
  132.         // TODO add your handling code here:
  133.        
  134.         Draw_circle();
  135.     }                                          
  136.  
  137.     /**
  138.      * @param args the command line arguments
  139.      */
  140.     public static void main(String args[]) {
  141.         /* Set the Nimbus look and feel */
  142.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  143.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  144.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  145.          */
  146.         try {
  147.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  148.                 if ("Nimbus".equals(info.getName())) {
  149.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  150.                     break;
  151.                 }
  152.             }
  153.         } catch (ClassNotFoundException ex) {
  154.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  155.         } catch (InstantiationException ex) {
  156.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  157.         } catch (IllegalAccessException ex) {
  158.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  159.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  160.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  161.         }
  162.         //</editor-fold>
  163.  
  164.         /* Create and display the form */
  165.         java.awt.EventQueue.invokeLater(new Runnable() {
  166.             public void run() {
  167.                 new NewJFrame().setVisible(true);
  168.             }
  169.         });
  170.     }
  171.  
  172.     // Variables declaration - do not modify                    
  173.     private javax.swing.JButton jButton1;
  174.     private javax.swing.JLabel jLabel1;
  175.     private javax.swing.JPanel jPanel1;
  176.     private javax.swing.JTextField jTextField1;
  177.     // End of variables declaration                  
  178.  
  179.     private void Draw_circle() {
  180.         throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  181.     }
  182.  
  183. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top