首页 新闻 会员 周边 捐助

关于JavaSE 布局管理器的一些疑问

0
悬赏园豆:20 [已关闭问题] 关闭于 2012-09-21 08:46
 1 package test;
 2 
 3 import javax.swing.ButtonGroup;
 4 import javax.swing.JButton;
 5 import javax.swing.JFrame;
 6 import javax.swing.JPanel;
 7 
 8 import java.awt.Color;
 9 import java.awt.Dimension;
10 import java.awt.FlowLayout;
11 import java.awt.GridLayout;
12 import java.awt.LayoutManager;
13 import java.awt.Toolkit;
14 
15 public class TicketPanel extends JPanel {
16     /**
17      * @ClassName: NodeEntityCollection
18      * @Description: 线路选择面板
19      * @author YangWei
20      * @date 2012-9-16 下午13:00:00
21      * 
22      */
23     private static final long serialVersionUID = 1L;
24 
25     public final static Dimension ScreenSize = Toolkit.getDefaultToolkit()
26             .getScreenSize();
27 
28     private static int ticketWeight = ScreenSize.width / 4;
29 
30     private static int ticketHeight = ScreenSize.height;
31 
32     private JButton oneYuan;
33 
34     private JButton twoYuan;
35 
36     private JButton threeYuan;
37 
38     private JButton fourYuan;
39 
40     private JButton fiveYuan;
41 
42     private JButton sixYuan;
43 
44     private JButton sevenYuan;
45 
46     private JButton more;
47 
48     private JButton Englis_Chiness;
49 
50     private JButton Recharge;
51 
52     private JButton cancel;
53 
54     public TicketPanel() {
55 
56         setLayout(null);
57         setBounds(3 * ScreenSize.width / 4, 0, ticketWeight, ticketHeight);
58         init();
59         add(Englis_Chiness);
60         setVisible(true);
61     }
62 
63     public void init() {
64         oneYuan = new JButton("1元");
65         twoYuan = new JButton("2元");
66         threeYuan = new JButton("3元");
67         fourYuan = new JButton("4元");
68         fiveYuan = new JButton("5元");
69         sixYuan = new JButton("6元");
70         sevenYuan = new JButton("7元");
71         more = new JButton("更多");
72         Englis_Chiness = new JButton("English");
73         Englis_Chiness.setBounds(3 * ticketWeight + 50, 50, 50, 50);
74         Recharge = new JButton("充值");
75         cancel = new JButton("交易取消");
76     }
77 
78     public static void main(String[] args) {
79         JFrame f = new JFrame();
80         f.setTitle("test");
81         f.setBounds(0, 0, ScreenSize.width, ScreenSize.height);
82         f.setLayout(null);
83         f.setVisible(true);
84         f.add(new TicketPanel());
85         f.repaint();
86     }
87 }

代码如上:
 为什么这样"Englis_Chiness"这个Button在添加后不能显示呢?是布局的原因吗?还是Buttton在添加后被覆盖了呢?

问题补充:

怎么没有人响应呢??

Crazy_Yang的主页 Crazy_Yang | 初学一级 | 园豆:167
提问于:2012-09-20 12:25
< >
分享
所有回答(1)
0

这是应为当把JPanel加到JFrame上去之后,JPanel的左上角的坐标变成了0

Crazy_Yang | 园豆:167 (初学一级) | 2012-09-21 08:46
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册