Topic: 请问大虾门为什么没有button呀 |
Print this page |
1.请问大虾门为什么没有button呀 | Copy to clipboard |
Posted by: wangyabing Posted on: 2005-12-26 11:06 原代码: /** * AWT Sample application * * @author * @version 1.00 05/12/26 */ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; public class Wang { public static void main(String[] args) { // Create application frame. WangFrame frame = new WangFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.show(); // Show frame frame.setVisible(true); } } class WangFrame extends JFrame { public WangFrame () {setTitle("BorderExample"); setSize(WIDTH, HEIGHT); //Use pack() method //JButton jButton9 = new JButton(); // jButton9.addMouseListener(new MouseAdapter() //单击jButton9时,出现history_1窗口 // public void mouseReleased(MouseEvent e) { history_1.setVisible(true);} //(JPanel) getContentPane().add( jButton9 ) JPanel textPanel = new JPanel(); //增加相应的文本框 for (int i = 0; i <3; i++ ) { JTextField addText = new JTextField("wang" + i, 10); textPanel.add(addText); } contentPane.add(textPanel); buttonPanel = new JPanel(); //增加相应的按钮 for (int i = 0; i < 3; i++ ) { JButton addButton = new JButton("add" + i); buttonPanel.add(addButton); } group = new ButtonGroup(); //添加按钮和事件监视器 //低斜面边界 addRadioButton("Lowered bevel", BorderFactory.createLoweredBevelBorder()); //凸斜面边界 addRadioButton("Raised bevel", BorderFactory.createRaisedBevelBorder()); //蚀刻边界 addRadioButton("Etched", BorderFactory.createEtchedBorder()); //直线边界 addRadioButton("Line", BorderFactory.createLineBorder(Color.blue)); //不光滑边界 addRadioButton("Matte", BorderFactory.createMatteBorder(5, 5, 5, 5, Color.yellow)); //空边界 addRadioButton("Empty", BorderFactory.createEmptyBorder()); //初始化带标题的空边界 Border border = BorderFactory.createEmptyBorder(); Border titled = BorderFactory.createTitledBorder(border, "Border types"); //给面板设置给定的边界 buttonPanel.setBorder(titled); Container contentPane = getContentPane(); contentPane.add(buttonPanel); } public void addRadioButton(String buttonName, final Border b) { JRadioButton button = new JRadioButton(buttonName); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { Border titled = BorderFactory.createTitledBorder (b, "Border types"); buttonPanel.setBorder(titled); //重新显示 validate(); } }); group.add(button); buttonPanel.add(button); } public static final int WIDTH = 500; public static final int HEIGHT = 200; private JPanel buttonPanel; private ButtonGroup group; } 在执行后没有出现button |
2.Re:请问大虾门为什么没有button呀 [Re: wangyabing] | Copy to clipboard |
Posted by: why Posted on: 2006-01-01 20:13 contentPane.add(textPanel); ===> getContentPane().add(textPanel); the textPanel is covered by the buttonPanel, use something like: // contentPane.add(textPanel); ... Container contentPane = getContentPane(); contentPane.add("North", textPanel); contentPane.add("South", buttonPanel); |
3.Re:请问大虾门为什么没有button呀 [Re: wangyabing] | Copy to clipboard |
Posted by: wangyabing Posted on: 2006-01-01 21:47 谢谢問題兒童 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |