码迷,mamicode.com
首页 > 其他好文 > 详细

15.1

时间:2016-06-23 23:40:53      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

技术分享
 1 import java.awt.Color;
 2 import java.awt.Graphics;
 3 
 4 import javax.swing.JFrame;
 5 import javax.swing.JPanel;
 6 
 7 public class Test_15 extends JFrame{
 8 
 9     public  Test_15(){
10         add(new JP());
11     }
12     public static void main(String[] args) {
13         // TODO Auto-generated method stub
14         Test_15 t = new Test_15();
15         t.setTitle("test");
16         t.setSize(200,200);
17         t.setLocationRelativeTo(null);
18         t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
19         t.setVisible(true);
20     }
21 
22 }
23 
24 class JP extends JPanel{
25     protected void paintComponent(Graphics g){
26         super.paintComponent(g);
27         
28         int width = getWidth();
29         int height = getHeight();    
30         g.setColor(Color.BLUE);
31         g.drawLine(0, height/3, width, height/3);
32         g.drawLine(0, 2*height/3, width, 2*height/3);
33         g.setColor(Color.RED);
34         g.drawLine(width/3,0, width/3,height);
35         g.drawLine(2*width/3,0, 2*width/3,height);
36     }
37 }
Test_15

 

15.1

标签:

原文地址:http://www.cnblogs.com/wanjiang/p/5612357.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!