Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java GUI 设计  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 请问大虾门为什么没有button呀
wangyabing





发贴: 18
积分: 0
于 2005-12-26 11:06 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
原代码:
/**
* 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




话题树型展开
人气 标题 作者 字数 发贴时间
3599 请问大虾门为什么没有button呀 wangyabing 2847 2005-12-26 11:06
2495 Re:请问大虾门为什么没有button呀 why 293 2006-01-01 20:13
2814 Re:请问大虾门为什么没有button呀 wangyabing 6 2006-01-01 21:47

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2018 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号
客服电话 0592-8750026    客服信箱 714923@qq.com    客服QQ 714923