Java лекц№3

1,269 views

Published on

Published in: Technology, Art & Photos
  • Be the first to comment

  • Be the first to like this

Java лекц№3

  1. 1. Лекц №3 график горимд дүрс зурах, дүрслэх.<br />Д. Энхжаргал<br />
  2. 2. Хялбар дүрсүүдийг зурах<br />g2.setColor(new Color(255,0,0));<br />Зурах өнгийг өөрчлөх<br />g2.fillRect(10,10,200,50);<br />10, 10 координатаас эхлэн 200 өргөнтэй 50 өндөртэй тэгш өнцөгтийг дүүргэж будах<br />g2.drawString("Hello World", 10, 10);<br />Hello World үгийг 10, 10 координатаас зурах<br />
  3. 3. Canvas –д шулуун шугам зурах<br />...<br />public class MyCanvas extends Canvas<br />{<br /> ...<br /> public void paint(Graphics graphics)<br /> {<br />graphics.drawLine(10, 20, 300, 310);<br /> }<br /> ...<br />}<br />
  4. 4. Тэгш өнцөгтийг Canvas-т зурах<br />...<br />public class MyCanvas extends Canvas<br />{<br /> ...<br /> public void paint(Graphics graphics)<br /> {<br />graphics.drawRect(10, 10, 100, 100);<br /> }<br /> ...<br />}<br />
  5. 5. Өнгө өөрчлөх<br />public void paint(Graphics graphics)<br /> {<br />graphics.setColor(Color.red);<br />graphics.drawRect(10, 10, 100, 100);<br /> }<br />Доорх өнгүүдээс сонгоно:<br />Color.red<br />Color.blue<br />Color.green<br />Color.yellow<br />Color.pink<br />Color.black<br />Color.white<br />
  6. 6. Тойрог зурах<br />public void paint(Graphics graphics)<br /> {<br />graphics.setColor(Color.white);<br />graphics.fillOval(10, 10, 100, 100);<br />graphics.setColor(Color.blue);<br />graphics.drawOval(10, 10, 100, 100);<br /> }<br />
  7. 7. Дугуй булант тэгш өнцөгт зурах<br />public void paint(Graphics graphics)<br /> {<br />graphics.setColor(Color.pink);<br />graphics.fillRoundRect(10, 10, 100, 100, 5, 5);<br />graphics.setColor(Color.red);<br />graphics.drawRoundRect(10, 10, 100, 100, 5, 5);<br /> }<br />
  8. 8. График програмын жишээ<br />public class MyPanelextends JPanel{<br /> public void paintComponent(Graphics g){<br />super.paintComponent(g); <br />// erases background<br /> Graphics2D g2 = (Graphics2D)g; //cast for java2<br /> // my graphics:<br /> g2.setColor(new Color(255,0,0));<br /> g2.fillRect(10,10,200,50);<br /> g2.setColor(new Color(0,0,0));<br /> g2.drawString("Hello World", 10, 10);<br /> }<br />}<br />
  9. 9. Даалгавар<br />Smile зурах програм бич<br />

×