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

15.2

时间:2016-06-23 23:56:09      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

技术分享
 1 import java.awt.Color;
 2 import java.awt.Graphics;
 3 import java.awt.GridLayout;
 4 
 5 import javax.swing.JButton;
 6 import javax.swing.JFrame;
 7 import javax.swing.JPanel;
 8 
 9 public class Test_15 extends JFrame{
10     public Test_15(){
11         setLayout(new GridLayout(1,2,5,5));
12         add(new OvalButton("OK"));
13         add(new OvalButton("CANCEL"));
14     }
15     
16     
17     public static void main(String[] args) {
18         // TODO Auto-generated method stub
19         Test_15 t = new Test_15();
20         t.setTitle("test");
21         t.setSize(400,100);
22         t.setLocationRelativeTo(null);
23         t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
24         t.setVisible(true);
25     }
26 
27 }
28 
29 class OvalButton extends JButton{
30     public String str;
31     public OvalButton(String str){
32         this.str = str;
33     }
34     protected void paintComponent(Graphics g){
35         super.paintComponent(g);
36         
37         int width = getWidth();
38         int height = getHeight();
39         g.drawString(str, width/2, height/2);
40         g.drawOval((int)(0.1*width), (int)(0.1*height), (int)(0.8*width), (int)(0.8*height));
41     }
42 }
Test_15.java

 

15.2

标签:

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

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