Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. import javax.swing.*;  
  2.  
  3. import java.awt.*;  
  4.  
  5. public class DrawTriangle extends JPanel  
  6. {  
  7.  
  8.    
  9.    
  10. public void paint(Graphics g)  
  11. {  
  12.  super.paint(g);  
  13.  
  14.  //All triangle corner x coordinate  
  15.  int[]x={0,150,300};  
  16.  
  17.  //All triangle corner y coordinate  
  18.  int[]y={200,0,200};  
  19.  
  20.  //Set color base on RGB  
  21.  //You can get RGB value for your color at "Color picker" at above  
  22.  //R=255  
  23.  //G=192  
  24.  //B=0  
  25.  //So after this all you draw will use this color  
  26.  g.setColor(new Color(255,192,0));  
  27.  
  28.  //Draw triangle in JPanel  
  29.  g.fillPolygon(x,y,3);  
  30.  
  31.  //Set color base on RGB  
  32.  //You can get RGB value for your color at "Color picker" at above  
  33.  //R=1  
  34.  //G=1  
  35.  //B=1  
  36.  //So after this all you draw will use this color  
  37.  g.setColor(new Color(1,1,1));  
  38.  
  39.  //Set font that will use when draw String  
  40.  g.setFont(new Font("Arial",Font.BOLD,14));  
  41.  
  42.  //Draw String in JPanel  
  43.  g.drawString("(0,200)",10,200);  
  44.  g.drawString("(150,0)",150,20);  
  45.  g.drawString("(300,200)",290,200);  
  46. }  
  47.  
  48. public static void main(String[]args)  
  49. {  
  50.  DrawTriangle dt=new DrawTriangle();  
  51. }  
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement