Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1.  
  2. package g1;
  3. //import com.sun.pisces.Surface;
  4. import java.awt.Graphics;
  5. import java.awt.Graphics2D;
  6. import java.awt.EventQueue;
  7. import javax.swing.JPanel;
  8. import javax.swing.JFrame;
  9.  
  10. class Surface extends JPanel{
  11.     private void drawLine1(Graphics g){
  12.         Graphics2D g2d = (Graphics2D)g.create();
  13.         g2d.drawLine(100, 100, 500, 100);
  14.        
  15.     }
  16.     @Override
  17.     public void paintComponent(Graphics g){
  18.         super.paintComponent(g);
  19.         drawLine1(g);
  20.     }
  21. }
  22.  
  23. public class G1 extends JFrame{
  24.  
  25.     public G1(){
  26.         initUI();
  27.     }
  28.     private void initUI(){
  29.         add (new Surface());
  30.         setTitle("testline1");
  31.         setSize(480, 640);
  32.         setLocationRelativeTo(null);
  33.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  34.     }
  35.    
  36.     public static void main(String[] args) {
  37.         EventQueue.invokeLater(new Runnable() {
  38.             @Override
  39.             public void run() {
  40.                 //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  41.                 G1 gl = new G1();
  42.                 gl.setVisible(true);
  43.             }
  44.         });
  45.     }
  46.    
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement